9 years ago.

How to calculate Yaw, Pitch, Roll from Axcel, Gyto and Magnet

Hi, I'm trying to work with MPU9150 with a nucleo f401 board on Mbed online IDE.

I can read accelerometer (x,y,z), gyroscope (x,y,z) and magetometer (x,y,z) but I don't understand how to calculate Yaw (really important to me), Pitch and Roll.

May you help me?

Thank you

Question relating to:

A quick implementation of Quaternion and Vector classes for use with my MPU9150 library MPU9150, Quaternion, vector

1 Answer

9 years ago.

You need a suitable algorithm to merge the 9 degrees of measurement into Euler angles - something like https://developer.mbed.org/users/aberk/code/IMUfilter/ which uses Sebastian Madgwick's algorithm. I've had it working well (other than me getting a roll angle of +/-180 because I'd turned the IMU upside down) at a 50 Hz refresh rate.

A few things to consider:

1. You do need to calibrate the magnetometer - just min/max rather than ellipsoid calibration seems to work well enough 2. Unless you like waiting hours for a decent fix, it's worth setting the beta variable (if you're using Madgwick) to a high number to start with (I've used 3.0f) to trust the magnetometer data to start with and thus get a quick fix, and then turning it right down to increase the sensitivity thereafter (I've used 0.15 IIRC) 3. The yaw angle is measured relative to magnetic north. If, like me, you're interested in the difference between direction of travel and heading angle, don't forget to deal with declination.