Strange coefficient in offset formulae (mpu6050 calibration)

Hello there everyone, I got stuck with the following equation during the calibration IMU sensor, mpu6050
So there is the following library that needs for calibration the sensor: DIYino/MPU6050_calibration.ino at master · Protonerd/DIYino (github.com)

Code where I got stuck

bool calibration(){
ax_offset=-mean_ax/accel_offset_divisor;
ay_offset=-mean_ay/accel_offset_divisor;
//az_offset=-mean_az/accel_offset_divisor;
az_offset=(16384-mean_az)/8;

gx_offset=-mean_gx/gyro_offset_divisor;
gy_offset=-mean_gy/gyro_offset_divisor;
gz_offset=-mean_gz/gyro_offset_divisor;

so what does accel_offset_divisor mean ? Why does for acceleration it equal 8, but for gyro it equal 4 ?

when you have such questions, best is to go to the documentation .

Here is my naive understanding

if you look at this document "MPU Hardware Offset Registers Application Note Revision: 1.0"

you'll see (page 5) that the Gyro register offset (the bias) is measured in the +-1000dps sensitivity range

and (page 7) that the accelerometer offset is expressed for +-8G

they also mention that the acceleration offset is only on 15 bits, the 16th bit (LSb) should not be touched


Now In the code you listed for calibration, they set them at the highest sensitivity level of 250deg/s and 2g

          // set the fll scale range of the gyro- and accelerometer respectively
        accelgyro.setFullScaleGyroRange(0); //0: 250deg/s | 1: 500deg/s | 2: 1000deg/s | 3: 2000deg/s
        accelgyro.setFullScaleAccelRange(0); //0: 2g | 1: 4g | 2: 8g | 3: 16g

So since the offset values obtained are not in the expected range, they need to be adjusted.

from 1000dps to 250dps you go /4
from 8g to 2g you go /4 but the LSb is not part of the offset (it's stored on bit 1 to 15) so you need to get rid of that one too, so an extra shift right which is the same thing as dividing by 2 ➜ /4/2 <==> /8

So that's my guess :slight_smile:

Thank you! Frankly speaking, I didn't know about this doc :laughing:
So if got right for my settings (+- 2000 deg/s I need to value * 2) and (+- 16g I need to (value >> 1) * 2 ), right ?

The offset You obtained with the script as it is (max sensitivity and divide by 4 and 8) are what you want to use in your real code irrespective of the future settings you choose.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.