Title: **MPU6050 Calibration **

Post by:**Hitesh_KHD** on **Nov 30, 2017, 07:56 pm**

Post by:

Hello People!

I am completely new to this world of IOT, I am working on my very first project where I have used an MPU6050 Powered with Arduino uno to detect change in motion of an object and also the angle of change in orientation

I have Couple of questions regarding the same

1 : The angle that Gyro sensor gives when MPU6050 is rotated, is with respect to what?

2: What basically are offsets and how do I determine offset for my MPU6050

P:s I know this might seem silly Questions, But as I said earlier, I don't have much knowledge regarding this stuff!

I am completely new to this world of IOT, I am working on my very first project where I have used an MPU6050 Powered with Arduino uno to detect change in motion of an object and also the angle of change in orientation

I have Couple of questions regarding the same

1 : The angle that Gyro sensor gives when MPU6050 is rotated, is with respect to what?

2: What basically are offsets and how do I determine offset for my MPU6050

P:s I know this might seem silly Questions, But as I said earlier, I don't have much knowledge regarding this stuff!

Title: **Re: MPU6050 Calibration **

Post by:**MrMark** on **Nov 30, 2017, 08:59 pm**

Post by:

1) The gyro sensor measures angular rate around each Cartesian axis.

2) Without more context, I'm not clear as to which offset you are referring.

Have you looked at the Datasheet and register descriptions (https://www.invensense.com/products/motion-tracking/6-axis/mpu-6050/) for the device (bottom of linked page)?

2) Without more context, I'm not clear as to which offset you are referring.

Have you looked at the Datasheet and register descriptions (https://www.invensense.com/products/motion-tracking/6-axis/mpu-6050/) for the device (bottom of linked page)?

Title: **Re: MPU6050 Calibration **

Post by:**jremington** on **Nov 30, 2017, 09:23 pm**

Post by:

Do not cross post. It wastes everyone's time, including yours. (https://forum.arduino.cc/index.php?topic=514498.msg3506264#msg3506264)

Title: **Re: MPU6050 Calibration **

Post by:**Hitesh_KHD** on **Dec 01, 2017, 06:49 am**

Post by:

I'm sorry, I wanted to delete the duplicate pose but wasn't successful!

Title: **Re: MPU6050 Calibration **

Post by:**MartinL** on **Dec 02, 2017, 10:16 am**

Post by:

Hi Hitesh_KHD,

A good place to start understanding the MPU6050 is here: http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-a-chip/ (http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-a-chip/).

This article describes how use a simple complementary filter to fuse the gyroscope and accelerometer data to obtain Euler angles for pitch and roll.

The gyroscope measures rotational speed in say degrees/s or radians/s, this can be integrated to obtain the angle again in degrees or radians, however like you mention it has no reference point and additionally, like all gyroscopes, drifts to a greater or lesser extent over time.

To provide a reference point we use the accelerometer to measure gravity. Using some trigonometry we can convert these raw acceleration values to pitch and roll angle with respect to the horizontal, however the accelerometer is noisy and any acceleration other than rotation can distort the measurements.

To solve this we can fuse the integrated gyroscope and accelerometer pitch and roll angles using a complementary filter. The complementary filter takes around 99.9% of the gyroscope angle mesurements and adds this to around just 0.1% of the accelerometer. Calculating this each time around the Arduino's loop() function the complementary filter has the magical effect of providing stable angle measurements that are tied to the horizontal reference. In addition the angles are more or less acceleration invariant and compensate for the gyroscope's drift.

To calibrate the gyroscope just take the mean average of a couple of hundred raw gyro readings at start-up and subtract from the raw values taken during operation.

To calibrate the accelerometer, place it on level-ground then again take the average raw values and again subtract from the raw values during operation. It's also possible to store the accelerometer values in EEPROM to save you having to calibrate each time you start-up.

There's also the issue of yaw compensation that the article above doesn't discuss. This involves transferring any small movements in yaw rotation from pitch to roll angle or vice-versa. This is covered by Joop Brokking in his quadcopter video on Youtube: https://www.youtube.com/watch?v=j-kE0AMEWy4 (https://www.youtube.com/watch?v=j-kE0AMEWy4).

Another option is to just get the angle values using the MPU6050's in-built DMP (Digital Motion Processor). Jeff Rowberg's I2Cdev library for the MPU6050 has example code for this.

If however you require full 3D orientation then you'll also need a 3-axis magnetometer, as the accelerometer is unable to measure yaw rotation. You'll also need more complex mathematics such as Quaternions or DCM (Direction Cosine Matrix). For this reference Kris Winer's Github code: https://github.com/kriswiner (https://github.com/kriswiner).

A good place to start understanding the MPU6050 is here: http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-a-chip/ (http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-a-chip/).

This article describes how use a simple complementary filter to fuse the gyroscope and accelerometer data to obtain Euler angles for pitch and roll.

The gyroscope measures rotational speed in say degrees/s or radians/s, this can be integrated to obtain the angle again in degrees or radians, however like you mention it has no reference point and additionally, like all gyroscopes, drifts to a greater or lesser extent over time.

To provide a reference point we use the accelerometer to measure gravity. Using some trigonometry we can convert these raw acceleration values to pitch and roll angle with respect to the horizontal, however the accelerometer is noisy and any acceleration other than rotation can distort the measurements.

To solve this we can fuse the integrated gyroscope and accelerometer pitch and roll angles using a complementary filter. The complementary filter takes around 99.9% of the gyroscope angle mesurements and adds this to around just 0.1% of the accelerometer. Calculating this each time around the Arduino's loop() function the complementary filter has the magical effect of providing stable angle measurements that are tied to the horizontal reference. In addition the angles are more or less acceleration invariant and compensate for the gyroscope's drift.

To calibrate the gyroscope just take the mean average of a couple of hundred raw gyro readings at start-up and subtract from the raw values taken during operation.

To calibrate the accelerometer, place it on level-ground then again take the average raw values and again subtract from the raw values during operation. It's also possible to store the accelerometer values in EEPROM to save you having to calibrate each time you start-up.

There's also the issue of yaw compensation that the article above doesn't discuss. This involves transferring any small movements in yaw rotation from pitch to roll angle or vice-versa. This is covered by Joop Brokking in his quadcopter video on Youtube: https://www.youtube.com/watch?v=j-kE0AMEWy4 (https://www.youtube.com/watch?v=j-kE0AMEWy4).

Another option is to just get the angle values using the MPU6050's in-built DMP (Digital Motion Processor). Jeff Rowberg's I2Cdev library for the MPU6050 has example code for this.

If however you require full 3D orientation then you'll also need a 3-axis magnetometer, as the accelerometer is unable to measure yaw rotation. You'll also need more complex mathematics such as Quaternions or DCM (Direction Cosine Matrix). For this reference Kris Winer's Github code: https://github.com/kriswiner (https://github.com/kriswiner).

Title: **Re: MPU6050 Calibration **

Post by:**aster94** on **Dec 03, 2017, 01:21 pm**

Post by:

Getting the mpu family to work isn t straigh forward but then you will have good results

I simplified the quaternion filters, see here if you need them: https://www.hackster.io/vincenzo-g/sensor-fusion-algorithms-made-simple-6c55f6

I simplified the quaternion filters, see here if you need them: https://www.hackster.io/vincenzo-g/sensor-fusion-algorithms-made-simple-6c55f6