rpicopter / ArduinoMotionSensorExample

MPU6050/MPU6500/MPU9150/MPU9250 over I2c for Arduino
117 stars 43 forks source link

Rotation convention used in MPU sources #12

Open yerzhik opened 8 years ago

yerzhik commented 8 years ago

My task is to compare two sensors results one is xsense another is MPU 9150. I read about the quaternions to euler conversion: wikipedia formula

What I see from the source code of MPU is:

 *x = atan2( 2.f * ( q->x * q->w + q->y * q->z ), 1.f - 2.f * ( sqz + sqw ) );
 *y = asin( 2.f * test );
 *z = atan2( 2.f * ( q->x * q->y - q->z * q->w ), 1.f - 2.f * ( sqy + sqz ) );

As you see its different. I tried to analyze the matrices of rotations with different conventions (xyz, zyx etc) but none fits this kind of formulas.

Due to unknown convention I can't compare them. So I decided to use the quaternions from MPU instead. And then Using matlab to convert them into euler angles. Euler angles (yaw pitch roll) from MPU and euler angles got from MATLAB after conversion MPU quaternions to euler angles are completely different and makes no sense. MPU euler angles are OK. Showing good results but mpu quaternions to euler angles done in Matlab are completely wrong (matlab uses zyx convention but I think it doesn't matter which convention to use as I'm getting it from quaternions).

So the question is: is it possible that mpu is using it's own kind of quaternions and rotation matrix convention for euler angles or am I missing something? Could you help with that please?