EN
SensorsIntermediateIMUaccelerometergyroscopemagnetometercomplementary filterKalmansensor fusion

IMU and sensor fusion

In 30 secondsThe accelerometer knows where down is but gets confused when moving; the gyroscope is smooth but drifts. A complementary filter trusts the gyroscope in the short term and the accelerometer in the long term.

Also available in: Català · Castellano

The two sensors

  • Accelerometer: measures acceleration, including gravity. At rest, gravity shows where “down” is and gives the tilt. When moving, it gets confused.
  • Gyroscope: measures turning speed. Integrating it gives the angle, smooth and fast, but a small bias builds up: drift.

Fusion: complementary filter

angle = α · (angle + gyro · dt) + (1 − α) · accel_angle, with α typically 0.98.

Gyroscope in the short term, accelerometer in the long term. Robots use more advanced variants (the Kalman filter).

It’s the same pattern as in SLAM: one sensor that drifts and another that doesn’t drift but is noisy. Combining them corrects the error. It shows up all over robotics.

Magnetometer

A compass: heading ≈ atan2(my, mx) with the sensor level. Hard iron shifts the circle of readings; soft iron distorts it. Calibration re-centres it.

In the demo

Press the shake: the accelerometer is fooled. Raise the gyroscope bias: the integrated angle drifts away. The fused signal stays close to the real one.

Interactive demo

Related concepts