IMU and sensor fusion
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
Lidar and SLAM
Counting wheel turns accumulates error (drift). A lidar measures distances in many directions at once; SLAM builds the map and locates itself in it by aligning each scan, which corrects the drift.
Load cell
Strain gauges glued to a piece of metal change their resistance slightly when it bends. A Wheatstone bridge gives a few millivolts, an ADC turns them into counts and calibration converts those to grams.