# What is corrrect the way to find roll, pitch, yaw?

I have an MPU9250. I have calculated accelerometer, gyroscope, magnetometer. But I want to know how to caclulate roll yaw pitch. I have searched on Google. I found many answer

``````roll  =  (atan2(-Accel_Y, Accel_Z)*180.0)/M_PI;
pitch =  (atan2(Accel_X sqrt(Accel_Y*Accel_Y + Accel_Y*Accel_Y))*180.0)/M_PI;
``````
``````   accelerationX = (signed int)(((signed int)rawData_X) * 3.9);
accelerationY = (signed int)(((signed int)rawData_Y) * 3.9);
accelerationZ = (signed int)(((signed int)rawData_Z) * 3.9);
pitch = 180 * atan (accelerationX/sqrt(accelerationY*accelerationY + accelerationZ*accelerationZ))/M_PI;
roll = 180 * atan (accelerationY/sqrt(accelerationX*accelerationX + accelerationZ*accelerationZ))/M_PI;
yaw = 180 * atan (accelerationZ/sqrt(accelerationX*accelerationX + accelerationZ*accelerationZ))/M_PI;
``````
``````  Accroll = atan2( accy / (accy^2 + accz^2) )
Accpitch = atan2( accx / (accx^2 + accz^2) )
``````
`````` Accroll = atan2(accy, accz)
Accpitch = atan2( -accx, sqrt(accy^2 + accz^2) )
``````

What is the correct way to find roll yaw pitch?

• The accelerometer is noisy and the gyro drifts and only the magnetometer knows the direction. The correct way is a filter that uses all sensors combined, sometimes called: sensor fusion. For example the ahrs filter. See the mpu-9250 and ahrs at sparkfun: learn.sparkfun.com/tutorials/mpu-9250-hookup-guide
– Jot
Jun 9 '18 at 17:03
• Before everyone makes this problem complicated, the first thing to figure out is if the device is moving and/or changing orientation. If it is not, the problem is a lot simpler and many of the things being suggested are unnecessary. Jun 10 '18 at 5:02

For a stationary accelerometer sensing the acceleration of gravity, I see "dead zones" when the Pitch, Yaw or Roll axes are parallel or close to parallel to the gravity vector.

Likely this is why accelerometers are used in conjunction with gyroscopes.

Refer to this NXP (aka Motorola, Freescale & Qualcomm) document for an in depth discussion regarding the necessary math. Note the section regarding "Regions of Instability".

Also, refer to this class and this class from rutgers.edu which work students through a project using an Arduino and an accelerometer in the 1st class then adds a gyroscope in the 2nd class to improve the response.