Inertial measurement unit sensor fusion

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
Post Reply
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Inertial measurement unit sensor fusion

Post by pythoncoder » Sun May 24, 2015 11:12 am

I have made a first pass at porting some C# code for Madgwick sensor fusion to MicroPython on the Pyboard and would appreciate any comments. See
https://github.com/micropython-IMU/micr ... fusion.git
It is intended to be device agnostic with regard to IMU's - testing was done with an MPU-9150. Performance is 1.6mS for a filter update.

As I point out in the readme I'm unfamiliar with aircraft conventions and terminology regarding coordinate systems: any information which might improve the document would be welcome.
Last edited by pythoncoder on Sun Jun 14, 2015 6:55 am, edited 1 time in total.
Peter Hinch
Index to my micropython libraries.

hansel
Posts: 13
Joined: Wed Feb 11, 2015 7:34 pm
Location: Rotterdam, NL
Contact:

Re: Inertial measurement unit sensor fusion

Post by hansel » Mon May 25, 2015 3:55 pm

Hello Pythoncoder,

Great work! What you did was on my long term todo list... :-)

I ran your class in a 'quick and dirty' way on my Pyboard with a sensor board called GY-88 which has a MPU6050 and a HMC5883. I ran the update function without calibrating first and I get meaningful stable values. I have some issues with my sensors (probably a wrong orientation / sign somewhere) but the results so far are great never the less!

I'm using a very primitive home baked driver at the moment. I call update with 30 Hz, I'll have to configure the sensors (I2C registers) for faster measurements. I don't have much time at the moment but intend to play some more with this in the near future...

Edit: the yaw takes a long time to settle: more than 10 sec to settle withing 2 deg after a 30 deg rotation
Thanks, Hans.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Inertial measurement unit sensor fusion

Post by pythoncoder » Tue May 26, 2015 6:25 am

I'm glad you're finding it useful :)
I'm using a very primitive home baked driver at the moment.
I assume you're aware there's a driver for the MPU-9150 here https://github.com/micropython-IMU/micr ... pu9150.git. It should work with the 6050 with only trivial changes - removing the magnetometer correction code from the class constructor may be all that's required.

Regarding response time I get similar results. There is a parameter Beta which can be adjusted to trade off accuracy against response time which you could adjust. Fusion algorithms, from a simple complementary filter to a full-blown Kalman one, aim to produce an approximate result quickly, with accuracy improving with time. This is because of the characteristics of the three types of sensor. Gyros produce the fastest response but suffer from drift. In moving vehicles accelerometers have good long term accuracy but short term response is heavily affected by inertial effects as the vehicle velocity changes. Magnetometers can be slow to respond. So, given the process, I think it's inevitable that there will be a lag before a given level of accuracy is achieved.
Last edited by pythoncoder on Sun Jun 14, 2015 6:54 am, edited 1 time in total.
Peter Hinch
Index to my micropython libraries.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Inertial measurement unit sensor fusion

Post by pythoncoder » Thu Jun 04, 2015 5:52 am

I advise anyone using this, in particular the magnetometer calibration method, to grab an update. There was a nasty bug in there which could crash the pyboard. :oops:
Peter Hinch
Index to my micropython libraries.

Post Reply