MPU6050 Jeff Rowberg Libraries - Help with Code Interpretation

Hi All–

I am trying to figure out the ins and outs of the MPU6050 sensor. Particularly, I am trying to understand the equations that are being used in Jeff Rowberg’s libraries to calculate Euler angles. I’m afraid my C++ skills haven’t gotten to the point to understand some of the pointers. Can someone help me with how to interpret the “phi” calculation in the MPU6050_6Axis_MotionApps20.h library:

uint8_t MPU6050::dmpGetEuler(float data, Quaternion q) {
data[0] = atan2(2
q → x
q → y - 2q → wq → z, 2q → wq → w + 2q → xq → x - 1); // psi
data[1] = -asin(2q → xq → z + 2q → wq → y); // theta
data[2] = atan2(2q → yq → z - 2q → wq → x, 2q → wq → w + 2q → zq → z - 1); // phi
return 0;

I attached all relevant libraries…

MPU_lib.ino (15.5 KB)

MPU6050.h (41.5 KB)

MPU6050_6Axis_MotionApps20.h (39.8 KB)

I2Cdev.h (11.8 KB)

uint8_t MPU6050::dmpGetEuler(float *data, Quaternion *q) {
    data[0] = atan2(2*x*y -2*w*z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);   // psi
    data[1] = -asin(2*q -> x*q -> z + 2*q -> w*q -> y);                              // theta
    data[2] = atan2(2*q -> y*q -> z - 2*q -> w*q -> x, 2*q -> w*q -> w + 2*q -> z*q -> z - 1);   // phi
    return 0;
}

q is a pointer to a Quaternion structure which has elements x, y, z, and w. It's a way of representing a spacial orientation that does not have the same discontinuities as Euler Angles (Roll, Pitch, and Yaw?). For example when pitch is 90 degrees (pointed straight up) Yaw and Roll are the same axis. Similarly a Roll of 90 degrees makes the Pitch and Yaw axis the same.

atan2() does the arctangent() of an angle given two sides of a triangle instead of the angle. That avoids problems with division by zero at 90 degrees.

The rest is basic trig.