Calculation of roll, pitch and yaw angles

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Calculation of roll, pitch and yaw angles

21,994 Views
shrijan00
Contributor I

I have an IMU FXOS8700CQR1 which has an accelerometer and magnetometer. I'm trying to calculate roll, pitch from the accelerometer and yaw from the magnetometer.

roll = atan2(-accelerometer[1],accelerometer[2]);

pitch = atan2(accelerometer[0],sqrt(accelerometer[1]*accelerometer[1]+(accelerometer[2]*accelerometer[2])));

magx = magnetometer[0]*cos(pitch)+magnetometer[1]*sin(roll)*sin(pitch) + magnetometer[2]*sin(pitch)*cos(roll);

magy = -magnetometer[1]*cos(roll) + magnetometer[2]*sin(roll);

yaw =  atan2(-magy,magx)*180/M_PI; 

I'm getting incorrect yaw data but I'm not sure about the equations which I found on the internet. Does anybody have any idea in this regard?

Thanks!

Labels (2)
0 Kudos
Reply
3 Replies

19,790 Views
reyes
NXP TechSupport
NXP TechSupport

Hi,

Equation 22 of the application note AN4248 may help you for this task: https://cache.freescale.com/files/sensors/doc/app_note/AN4248.pdf

 

However, if your system need the yaw, pitch and roll calculations, I would recommend you to use the FXAS21002 gyroscope sensor instead: https://www.nxp.com/docs/en/data-sheet/FXAS21002.pdf

Regards,

Jose

0 Kudos
Reply

18,850 Views
JimmyXelectroN
Contributor I

Um, how would you go about calculating the yaw angle with only a gyroscope. I have an MPU6050 6-axis accelerometer and gyroscope and I have been unsuccessfully trying to calculate yaw angle.

0 Kudos
Reply

7,378 Views
Hari123pass123
Contributor I
I have an mpu6050 which has an accelerometer and gyroscop . I'm trying to calculate roll, pitch from the accelerometer and yaw from the sensor I'm getting incorrect yaw data please help to me
0 Kudos
Reply