Madgwick/Mahony AHRS code for AltIMU-9 and -10 sensors

Since I have some extra time on my hands these days, I implemented the popular Madgwick/Mahony AHRS fusion filters for the AltIMU-10 v3. The present version uses the Mahony algorithm, which makes the most sense to me. (Aside: the Kalman filter is provably the “best”, but only in terms of a specific system model, which is assumed to be accurate. Other fusion filter proposals do not require a specific system model.)

The Mahony filter is quite fast (about 180 updates/second on a 16 MHz Arduino Pro Mini), responsive and perfectly stable when the sensor is not moving, so I’m very pleased with the performance. Both quaternion and Tait-Bryan (one type of Euler) orientation angles can be output. Minor modifications will be needed to work with other AltIMU versions, due to sensor differences.

Sensor calibration is all-important!

Most fusion filter implementations suffer from poor sensor calibration, which is absolutely essential for best performance. In many cases, the magnetometer data can be so far out of calibration that the filter results are completely meaningless. So, I’ve written simple Arduino code to collect data for calibrating both the accelerometer and the magnetometer in one go, and point readers to procedures that make the best possible use of the calibration data.

The Github link is GitHub - jremington/AltIMU-AHRS: Arduino Madgwick/Mahoney AHRS filters for the Pololu AltIMU9 and 10 series of 9 and 10DOF sensors. Includes code for sensor calibration.

The calibration procedure involves full 3D ellipsoid fitting, resulting in a 9+3 parameter matrix and offset that can correct for severe environmental effects on sensor performance. I described that procedure in some detail, in this post on correcting the Balboa magnetometer:

See also this tutorial and general overview:

Keep in mind that the sensor should be calibrated in its final installation.

For those interested in AHRS fusion filter theory, Olli W’s page hosts a really excellent discussion and comparison of the various popular algorithms. It includes links to the original papers.
http://www.olliw.eu/2013/imu-data-fusing/

1 Like

Hi, Jim.

Thanks for sharing your software! I hope to try it out soon and I also hope it will be useful to others looking to implement an AHRS.

Kevin