I'm using the MPU9250, it measures acceleration, magnetometer, gyro, etc. Complementary filter tutorial for this is here, however this tutorial does not have a magnetometer and I do, thus I thought I could eliminate the gyro drift. Seen here:

serial monitor showing drift

I've found this post already in which other users state that a magnetometer is required. However, they do not go into much detail (and because it is such an old post I didn't want to bump it).

My other complementary filters are calculated as such:

float angle_x = alpha*gyro_angle_x + (1.0 - alpha)*accel_angle_x;

float angle_y = alpha * gyro_angle_y + (1.0 - alpha) * accel_angle_y;

angle z = yaw

I have my local inclination angle which I have been previously told I need and I also have my magnetometer value.

My question is; How do I combine all my values into an equation for the complementary filter?

  • $\begingroup$ robotics.stackexchange.com/a/19166/23148 please see this post :) sparkfun as far as i know has their own arduino implementation of the Madgwick filter so you dont have to use the adafruit library...assuming you’re using an arduino $\endgroup$ Aug 13, 2019 at 16:40
  • $\begingroup$ @morbo can I use that filter along with my already implemented complementary filter? $\endgroup$ Aug 13, 2019 at 16:41
  • $\begingroup$ It would replace your comp filter entirely. $\endgroup$ Aug 13, 2019 at 16:42
  • $\begingroup$ I have seen that the Madgwick filter has better accuracy however I’ve also seen it’s harder to implement. I have a custom arduino sketch so that’s why everything is hard coded. $\endgroup$ Aug 13, 2019 at 16:43
  • $\begingroup$ Its very easy to implement if you use any of the libraries from sparkfun or adafruit :) $\endgroup$ Aug 13, 2019 at 16:44


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.