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!
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
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.