Help with choosing the correct settings for Mahony or Madgwick AHRS filters

I'm using the Adafruit Mahony / Madgwick AHRS filters to get quaternions (Euler angles to better understand output), using a calibrated BMX160 sensor. I'm polling the sensor at 100Hz.

I've read through the documentation and scoured the web, but couldn't find an explanation (at least not one without heavy mathematics) for how to select the beta and gain values for Madgwick, or the proportional and integral gain for Mahony respectively.

Only one forum post which suggested that (beta*sampleFreq)~=50 to 60 for madgwick.

I'm sorry if this is coming across as lazy, I really tried, but couldn't figure out a solution on my own. I'm slowly revising my maths, but don't think I'll ever get to the point of fully understanding the filters :frowning:

The gain is the Kp term in a PID controller, so you tune it as you would any PID controller (missing the I and D terms).

If Kp is too low, the filter will respond slowly to changes in sensor orientation. If too high, the filter output will oscillate.

For a technical explanation and comparison of various AHRS filters, see this excellent discussion: OlliW's Bastelseiten » IMU Data Fusing: Complementary, Kalman, and Mahony Filter

1 Like

Thanks for responding again, @jremington

I'll have a go at the link you forwarded, but from an initial look the maths is above my paygrade for now. So until I get to grips with it I suppose I'll have to just experiment, if there's no rule of thumb I can follow, e.g. for 100Hz data rate, X beta sort of relationship.

The experimental approach is fine. The serial plotter can be used to display angles, but print at the highest possible Baud rate, and not too often, or the loop time will become very slow, and the filter integration step will fail.

1 Like

Thank you very much for the advice!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.