AnsweredAssumed Answered

Calculation of roll, pitch and yaw angles

Question asked by Shrijan Kumar on Oct 25, 2019
Latest reply on Oct 28, 2019 by Jose Alberto Reyes Morales

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!

Outcomes