convert mpu6050 euler angle (order xyz) from quaternion

199 views Asked by At

I use the dmp of the Mpu6050 chip to read quaternions and convert them to Euler Angle (zyx) very well. pitch and roll angles do not drift over long periods of time. But when I use the same quaternion to convert to Euler Angle (xyz), I find that the pitch,roll and yaw are all slowly drifting. Why is that?My quaternion converts Euler angles as follows

//quaternion to zyx:
 *pitch = asin(-2 * q1 * q3 + 2 * q0* q2)* 57.3;
 *roll  = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1)* 57.3;
 *yaw   = atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3) * 57.3;

//quaternion to xyz:
 *pitch = asin(2*(q1*q3 + q0*q2)) * 57.3f;
 *roll = atan2(-2*(q2*q3 - q0*q1), q0*q0 - q1*q1 - q2*2 + q3*q3) * 57.3f;
 *yaw = atan2(-2*(q1*q3 - q0*q1) , q0*q0 - q1*q1 - q2*q2 + q3*q3) * 57.3f;

I don't understand why using the same quaternion but calculating it differently causes all three angles to shift.Please somebody help explain. Thank you!

1

There are 1 answers

0
Ton van den Bogert On

I did not check your math, but I think I know why.

Your first set of angles is the true yaw-pitch-roll convention. Yaw is a rotation about the vertical axis of the world. Roll is a rotation about a forward pointing axis in the moving body. Pitch is a rotation about an axis that is perpendicular to the other two.

The MPU6050 is a 6-axis inertial measurement unit, it has a 3D accelerometer and a 3D rate gyro. Internally it has either a Kalman filter or a complementary filter (I did not look it up) to stabilize against integration drift. This makes use of the fact that any tilting of the sensor relative to gravity will generate a signal in the horizontal components of the accelerometer. So tilt (a combination of pitch and roll) is stabilized. Yaw is not stabilized because a change in heading will not tilt the sensor.

To stabilize Yaw, a 9-axis sensor is needed which also includes a magnetometer. The heading (yaw) is then stabilized with respect to the direction of the magnetic north pole.

Your second set of angles is not actually yaw-pitch-roll. It probably has the "yaw" axis fixed in the moving body, and the "roll" axis fixed in the world. As soon as the body is tilted, a change in heading (which is drifting) will appear in all three angles.