MPU6050 calibration

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Samuel97
Posts: 3
Joined: Fri Jan 04, 2019 7:03 pm

MPU6050 calibration

Post by Samuel97 » Fri Mar 29, 2019 4:39 pm

Hello,
I'm trying to use MPU6050 with pyBoard, I use this libs
https://github.com/micropython-IMU/micropython-mpu9x50
and
https://github.com/micropython-IMU/micropython-fusion

MPU6050 don't have magnetometro, so I use Fusion.update_nomag.
Pitch value and roll value are pretty stable, value of heading (Yaw) is constant 0.
For me is important value of heading so I copy calculation from Fusion.update and rewrite

self heading = 0
to
self.heading = self.declination + degrees(atan2(2.0 * (self.q[1] * self.q[2] + self.q[0] * self.q[3]),
self.q[0] * self.q[0] + self.q[1] * self.q[1] - self.q[2] * self.q[2] - self.q[3] * self.q[3]))

The value of heading is good but after while it start integrating some mistake. And value continuously change after 5 minutes almost up to 180°, without rotating mpu6050.
I guess that it is some static mistake from gyro, is there any way how to calibrate it?

Really thank for help

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

Re: MPU6050 calibration

Post by pythoncoder » Sat Mar 30, 2019 9:26 am

Heading information comes from the magnetometer. In the case of the MPU6050 driver we deliberately set heading to zero because there is no way to deduce absolute heading without a magnetometer.

Trying to infer a relative heading value by integrating the gyro output twill inevitably cause any error to accumulate. A true inertial measurement as used on spacecraft requires equipment with much higher precision than an MPU6050. Out of curiosity I experimented with this myself and concluded it was a lost cause. This did not come as a surprise.

You could try adding in ad hoc calibration values prior to integration but I don't hold out any hope for long term stability: any gyro offsets are liable to vary with changes in temperature, supply voltage or the phase of the moon ;)
Peter Hinch
Index to my micropython libraries.

Post Reply