MPU-6050 Yaw Drift and how to combat

I’m using the MPU-6050 in DMP mode to fuse the gyro and accelerometer data into a single quaternion value representing the orienation of the sensor.  No matter how well calibrated the device is , there will always be some yaw drift. Gravity provides a partial frame of reference so the sensor know which way is down and can accuranty determine pitch and roll.  But yaw has no fixed reference point and tends to drift.

There are multiple ways to combat yaw drift.  A  magnetometer (compass) can be used but that comes with it’s own calibration issues, which is they route Occulus Rift have taken. The newer MPU-9150 chip combines a magnetometer with the existing sensors and there are plenty of alogrithms out there in the wild which will fuse all three sets of data together to provide drift free output.

Another option is to measure the drift over a number of minutes and see how it behaves. This is what I did;

Image

The graph shows yaw output over time. At two points I moved the sensor around to detemine if the yaw value returned to where it should be and also to see if drift rate was effected.  You can see that firstly the yaw value generated by DMP returned to it’s original value (allowing for drift) after movement and also that the rate of drift is constant.

This allows a simple ‘yaw drift compensation’ approach to be implemented in code. If the average yaw drift rate is 0.12 units every  second then simply accumulate this as a growing offset which you apply to the DMP yaw value.  In my code I update the drift offset every second.

float driftComp = 0.00; // more +ve number makes drift more -ve
.
.
.
void loop()
{
.


if (now > lastUpdate) {
     lastUpdate = now+ 1000;
     driftOffset += driftComp;
}
etc...

It’s simple and work suprisingly well.

Rob J

 

 

 

 

 

 

 

 

 

 

Advertisements

8 thoughts on “MPU-6050 Yaw Drift and how to combat

  1. Can you go into detail on how you made the graph of the drift? How exactly did you monitor the drift?

    Maybe you can list your entire code? I’m completely new to this and this seems like a really cool project but it’s hard to follow bits and pieces, for me any way.

    • I find the 9150 breakout boards much harder to come by and they’re twice the price. I wanted a bargain bucket solution 🙂
      I find that with drift compensation yaw drift is no longer an issue in-game.

  2. Good point:) And guess we don’t need that level of precision anyway. Have ordered one of each from ebay, will try with the 6050 first. And then see how easy it is to implement the 9150 just to amuse myself:)

  3. Will do. Looks from the data sheet that the 9150 can be used as a 6050 and then I will see if I can get my head around the magnetometer part. But should be able to reset the yaw drift based on that. Sounds easy so properly not!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s