Atlas Robotics
IMUIntermediate

IMU calibration: eliminating systematic errors

Atlasbot · 18/8/2026 · 11 min read

IMU calibration: eliminating systematic errors
Calibrate IMU measurement and subtract bias when sensor is stationary

Given a fully stationary IMU on a table, the gyroscope should have reported angular velocity = 0 on all 3 axes — but the real-world always had a small deviation value, called bias (systematic error, offset). Without removing this bias, the robot will "think" that it is rotating even though it is at rest — resulting in odometry or biased balance data that accumulate over time (what exactly is the drift problem learned in Gyroscope?).

Key concepts

Low - cost IMUs (MEMS type such as MPU6050) mass - produced always have small errors between different chips — no chip gives an absolute zero value when fully stationary, even in the same model. Additionally, the bias varies slightly with ambient temperature, meaning that the morning calibration may be slightly different than the hot noon.

How it works

The simplest and most common method is to hold the IMU perfectly still for a few seconds at startup, read multiple samples in a row, average out — this average is the bias, minus each subsequent readout.

const int SAMPLES = 200;
float gyroZ_bias = 0;

void calibrateGyro() {
  long sum = 0;
  for (int i = 0; i < SAMPLES; i++) {
    int16_t gz = mpu.getRotationZ();
    sum += gz;
    delay(5);
  }
  gyroZ_bias = sum / (float)SAMPLES;   // offset value at rest
}

void loop() {
  int16_t raw = mpu.getRotationZ();
  float gyroZ_calibrated = raw - gyroZ_bias;   // subtract bias before use
}

A critical note: the robot must be fully stationary during the calibration of — if it is vibrated or moved slightly during sampling, the calculated bias will be wrong, causing subsequent data to deviate even more than without calibration.

For an accelerometer, the analog, but slightly more complicated method — requires placing the sensor in six different directions (up and down on each axis) to separate the bias from the true weight, rather than measuring it in one pose like a gyroscope.

Technical details

Formulas

The number of averaged samples directly affects the accuracy of the calculated bias — more samples reduce random noise in the estimation of the bias, according to the fundamental statistical law:

Bias_estimation_error ∝ Noise_standard_deviation / √(Sample_count)

Example: gyroscope noise standard deviation ~2 LSB, collecting 200 samples
Bias_estimation_error ≈ 2/√200 ≈ 0.14 LSB (fairly small, good enough)

Collecting 20 samples instead of 200:
Bias_estimation_error ≈ 2/√20 ≈ 0.45 LSB (~3 times less accurate)

→ More samples improve the estimate according to a square-root law (diminishing
returns) — 4 times as many samples only halves the error, rather than reducing it 4 times

Parameters

SensorsNumber of poses to takeCalibration complexity
Gyroscope1 (hold still in any direction)Low
Accelerometer6 (up/down axis each)Higher, we need to separate the bias from the gravity.

Practical applications

IMU calibration is a mandatory pre-preparation step for EKF in the real-world AMR architecture (learned in the IMU article in AMR) — bias uncalibrated which will cause even the best fusion algorithm to give systematic error results, as EKF only handles random noise, does not automatically detect and eliminate systematic errors (bias) if not calibrated prior to inclusion in the filter.

Practical example

import numpy as np

def hieu_chuan_gyro(mau_du_lieu):
    return np.mean(mau_du_lieu)

# Simulate 200 stationary gyro Z samples with random noise around true bias = 15
np.random.seed(42)
mau = np.random.normal(loc=15, scale=2, size=200)

bias_uoc_luong = hieu_chuan_gyro(mau)
print(f"Bias uoc luong: {bias_uoc_luong:.2f} (gia tri thuc: 15.0)")

# Apply bias to new data
gia_tri_moi_raw = 18
gia_tri_da_hieu_chuan = gia_tri_moi_raw - bias_uoc_luong
print(f"Gia tri sau hieu chuan: {gia_tri_da_hieu_chuan:.2f}")
Output:
Bias uoc luong: 14.87 (gia tri thuc: 15.0)
Gia tri sau hieu chuan: 3.13

The estimation Bias (14.87) is very close to the real value (15.0) thanks to averaging 200 samples — in the principle calculated in the Formula section, the estimation error getting smaller by the square root of the number of samples.

Common mistakes

  • Calibration when the robot is not fully stationary— as stated in the Operating Principles section, miscalibration bias causes subsequent data to deviate even more than without calibration.
  • Taking too few samples saves— boot time as calculated in the Formulary section, reducing the number of samples increases the bias estimation error according to the square root law, which needs a balance between boot time and accuracy.
  • Job gyroscope calibration alone neglects the— accelerometer which also has a bias to be calibrated (although more complicated, requiring 6 poses), neglecting which still systematically misaligns the inclination estimate (what is the accelerometer?).
  • Once-and-for-all calibration without re-update — bias varies slightly with temperature, with applications requiring high accuracy to re-calibrate periodically or at least every time the robot is started.

Conclusion

IMU calibration is a simple but easily overlooked initial step — where only a few lines of stationary-averaging code eliminate much of the systematic error, making gyroscope/accelerometer data far more reliable for subsequent steps such as odometry or balance. This is the last of the IMU — column the next Computer Vision/AI column to go into the higher processing layer: from raw camera frames to AI object recognition.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

IMU calibration: eliminating systematic errors — Atlas Robotics