Complimentary Filter or Kalman Filter Implementation For the GY521


I have recently been working with the GY521 IMU unit. It wasnt long after looking at the raw values of the accelerometer and gyroscope values that i realized that i would need some sort of filter to estimate the true value of the angle in the three axis. I came across two types of filters that are used for this application (Complimentary and Kalman).

I was hoping that if someone had done something similar on mesh devices could guide on the implementation of these filters :)?

How is this library related to the Kalman or complimentary filter? Unless i am missing something? :thinking:

I’m not sure if you should worried about any theoretical filters etc. Just try to port and add manually on Particle web IDEMPU6050.cpp and MPU6050_6Axis_MotionApps20.h then pick one of example and all should work for you. For sure there will be some minor changes needed as this is Arduino example but that shouldn’t be a “rocket science” :wink:

Its not rocket science but i am creating a model thrust vector control system (So it kinda is). I tried using some other techniques (Like averaging) but i still get drift. Filtering would allow me to fuse the data from the gyro and acc and hence provide better estimation. Or atleast thats what i think will happen :slight_smile:

My experience is only with 1D Simple Kalman filters - temperature from a low resolution thermal array sensor. Whether you implement the kalman filter on mesh (gen3) devices or gen2 doesn’t make much difference. The quoted use of the kalman filter is sensor fusion - where a car with GPS and IMU goes into a tunnel and loses the satellite signal. In this case the IMU input to the kalman filter allows a position to continue to be produced. Such 6D or 3D kalman filters are pretty complicated maths wise.

Hey @armor thanks for your response.

Yeah thats what i was planning to do, fuse the data from the Accelerometer and gyroscope, to give a better estimation. You’re right on the maths part, for Kalman filter its pretty complicated, but i have been working on my own and made some progress…

The complimentary filter is another option, that fuses IMU data and the maths is pretty easy to get your head wrapped around (Just a high and low pass filter) :slight_smile: .

Doesn’t the MPU-6050 have a built in fusion unit?

The MPU-6050 devices combine a 3-axis gyroscope and a 3-axis accelerometer on the same silicon die, together with an onboard Digital Motion Processor™ (DMP™), which processes complex 6-axis MotionFusion algorithms.

Got an online implementation of Kalman Filter to work. Seem to be getting pretty stable values now. Pretty stable now.