Atlas Robotics
LocalizationBasic

What is an IMU? Measuring acceleration and angular velocity to detect robot rotation and tilt

Atlasbot · 17/8/2026 · 11 min read

What is an IMU? Measuring acceleration and angular velocity to detect robot rotation and tilt
Three sensors inside one IMU: accelerometer, gyroscope, magnetometer

The Odometry article in Localization pointed out the weakness of the odometry wheel: if the wheel slips on the floor, the encoder still counts the full number of revolutions but the robot does not actually move like that — the encoder has no way to detect this on its own. IMU (Inertial Measurement Unit) solves that blind spot by directly measuring the movement of the robot body, not through the wheel.

Key concepts

  • Accelerometer (accelerometer) — measures linear acceleration in 3 axes, including gravitational acceleration — this is also how the IMU estimates static roll, pitch: when the robot is stationary, the measured acceleration vector is mainly gravity, the direction of which tells how much the robot is tilting
  • Gyroscope (gyroscope) — measures angular velocity (rad/s) around 3 axes — is the rate of change of Roll, Pitch, Yaw learned in the Rotation lesson
  • Magnetometer — measures the Earth's magnetic field, gives absolute direction — not all IMUs have it, and is susceptible to interference from nearby motors/metallic materials

MPU6050 sensors common in DIY robot projects only have accelerometer + gyroscope (6-axis IMU, "6-DOF"); adding a 9-axis ("9-DOF") magnetometer for absolute Yaw estimation.

How it works

Gyroscope directly measures whether the robot body is rotating quickly or slowly, regardless of whether the wheel is in good contact with the floor or not — if the robot is lifted and rotated by its arms, the gyroscope will still measure the true angular velocity correctly, while the wheel encoder is completely meaningless at this time.

In short: The encoder is reliable when the wheel has good contact with the floor, the IMU is reliable when it needs to know the robot body movement independent of whether the wheel slides or not. No source alone is good enough for every situation — this is the motivation for the next Sensor Fusion article.

Integrating angular velocity from a gyroscope over time into absolute rotation (θ = ∫ω dt), or double integrating acceleration into position (x = ∬a dt²) — both are dead reckoning and also drift over time. Double integrals (positions) flow much faster than single integrals (angles) — this is why IMU is mainly used to estimate rotation angle, and is rarely used directly to estimate absolute position.

Technical details

Formulas

The cumulative angular error from the gyroscope is directly proportional to bias (constant bias of the sensor, always different from zero even when completely stationary) multiplied by time:

θ_sai_so = bias × t

For example: cheap MEMS gyro has a bias of ~0.5°/s (uncorrected)
After 60 seconds of standing completely still (no real rotation):
θ_sai_so = 0.5°/s × 60s = 30° — the robot "thinks" it has rotated 30° even though it hasn't moved at all!

This is why bias calibration — measuring the average value at rest and then subtracting it from all subsequent measurements — is a required step before using a gyroscope for any integration.

Parameters

Reference parameters of cheap MEMS IMU popular in DIY robot project:

ParametersReference value (uncorrected)
Bias gyroscope~0.1 – 1°/s
Noise density gyroscopeSeveral hundredths of °/s/√Hz
Bias accelerometerA few dozen to a few hundred mg (1mg = 0.001g)

Practical applications

Combining the encoder and IMU allows detection of a situation that the encoder alone cannot detect: the robot is lifted off the ground (maintenance, accident, or someone intentionally lifting the robot) while the wheel is still spinning freely — the encoder will still report "moving" normally, but the IMU's accelerometer will measure an abnormal acceleration (almost free fall or strange oscillation) that does not match the reported wheel motion fox. Many AMR safety systems use the mismatch between these two sensor sources as an early warning signal — if two independent sources suddenly "conflict" with each other in motion, it is likely that there is an unusual problem that requires stopping the robot immediately to check, even if the exact cause is not determined.

Practical example

bias = 0.5  # do/s, chua hieu chinh
thoi_gian = [0, 10, 30, 60, 120]

for t in thoi_gian:
    sai_so_goc = bias * t
    print(f"Sau {t}s dung yen: goc uoc luong sai ~{sai_so_goc:.1f} do (that ra la 0)")
Output:
Sau 0s dung yen: goc uoc luong sai ~0.0 do (that ra la 0)
Sau 10s dung yen: goc uoc luong sai ~5.0 do (that ra la 0)
Sau 30s dung yen: goc uoc luong sai ~15.0 do (that ra la 0)
Sau 60s dung yen: goc uoc luong sai ~30.0 do (that ra la 0)
Sau 120s dung yen: goc uoc luong sai ~60.0 do (that ra la 0)

The robot was completely stationary, but the estimated angle "drifted" up to 60° after just 2 minutes — an extremely visual demonstration of why bias correction is required before trusting gyroscope data for any localization purposes.

Common mistakes

  • Skip the bias correction step — as shown above, this is the most common and serious error — always measure and subtract the stationary bias before using the gyro data for integration.
  • Bias changes with temperature without compensation — cheap MEMS sensors have bias that drifts with ambient temperature, calibrating once at startup is not enough if the robot operates for many hours with chip temperature changing significantly — higher quality IMUs have built-in temperature sensors for dynamic compensation.
  • Magnetometer is disturbed by nearby motors/wires — as mentioned in the Main Concepts section, digital compasses are very sensitive to magnetic field interference from nearby DC motors or high-current wires, causing the calculated absolute Yaw direction to deviate significantly if the IMU is installed too close to these noise sources.
  • Mistakenly, the gyroscope measures "angle" instead of "angular speed" — the gyroscope returns the angular velocity (rad/s or °/s) at a time, not the absolute rotation angle — must be integrated over time to get the angle, confusing these two concepts is a very common mistake for newbies.

Conclusion

The IMU correctly complements the blind spot of the odometry wheel - directly measuring the robot body's movement, regardless of whether the wheel sticks to the floor or not - but is also dead reckoning so it still drifts over time, especially sensitive to uncorrected bias. Combining both sources also allows detecting problems when they "conflict" with each other. The next article in the category is about Sensor Fusion — a technique that combines many different sensor sources (encoder, IMU) into a more reliable estimate than each individual source.

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.

What is an IMU? Measuring acceleration and angular velocity to detect robot rotation and tilt — Atlas Robotics