IMU and Sensors
An IMU (Inertial Measurement Unit) combines accelerometers, gyroscopes, and often magnetometers to measure motion. Combined with other sensors (GPS, LiDAR, cameras, barometers), these form the sensory system of any mobile robot.
Why It Matters
Sensors are how robots perceive the world. Every control loop, every SLAM system, every navigation stack starts with sensor data. Understanding sensor characteristics — noise, drift, bandwidth, failure modes — determines whether your robot works reliably or crashes into walls.
IMU Components
Accelerometer (3-axis)
Measures linear acceleration including gravity. At rest, it reads [0, 0, 9.81] m/s² (pointing up).
Principle: a proof mass on a spring. Acceleration displaces the mass; capacitive or piezoresistive sensing measures displacement.
Getting tilt from gravity:
import numpy as np
def accel_to_tilt(ax, ay, az):
roll = np.arctan2(ay, az)
pitch = np.arctan2(-ax, np.sqrt(ay**2 + az**2))
return roll, pitch
# Only valid when not accelerating (e.g., hovering drone, stationary)Limitation: can’t distinguish tilt from linear acceleration. During movement, readings include both gravity and motion — need Sensor Fusion to separate them.
Gyroscope (3-axis)
Measures angular velocity (°/s or rad/s). Integrate to get angle change:
angle += gyro_rate × dt
Principle: MEMS vibrating structure — Coriolis effect deflects vibration proportional to rotation rate.
Limitation: integration accumulates bias error → drift. A 0.01°/s bias drifts 36°/hour. This is why gyro alone can’t maintain orientation long-term.
Magnetometer (3-axis)
Measures Earth’s magnetic field vector → heading/yaw. Points toward magnetic north.
Limitation: heavily distorted by nearby ferromagnetic materials (steel, magnets, motors). Requires hard-iron and soft-iron calibration before use. Motors running nearby corrupt readings — often unusable on drones during flight.
6-DOF vs 9-DOF
| Configuration | Sensors | Can Estimate |
|---|---|---|
| 6-DOF | Accel + Gyro | Roll, pitch (yaw drifts) |
| 9-DOF | Accel + Gyro + Mag | Roll, pitch, yaw (with mag calibration) |
Most flight controllers use 6-DOF + GPS for yaw, since magnetometers are unreliable near motors.
Sensor Noise
| Noise Type | Source | Effect | Mitigation |
|---|---|---|---|
| White noise | Random fluctuations | Jittery readings | Averaging, low-pass filter |
| Bias | Manufacturing offset | Constant error | Calibration (measure at rest, subtract) |
| Bias drift | Temperature, aging | Slowly changing offset | Sensor Fusion, recalibration |
| Scale factor error | Sensitivity variation | Readings off by % | Factory or self-calibration |
Characterizing Noise: Allan Variance
The Allan variance plot shows noise characteristics vs averaging time:
log(Allan deviation)
│
│ ╲ white noise (slope -1/2)
│ ╲
│ ──── bias instability (flat region)
│ ╱
│ ╱ random walk (slope +1/2)
└─────────────→ log(averaging time)
The minimum of the Allan deviation curve gives the bias instability — the best achievable stability. Datasheets report this in °/hr for gyros.
Common IMU ICs
| Chip | DOF | Gyro Range | Accel Range | Interface | Notes |
|---|---|---|---|---|---|
| MPU-6050 | 6 | ±2000°/s | ±16g | I2C/SPI | Classic, cheap, discontinued |
| ICM-20948 | 9 | ±2000°/s | ±16g | I2C/SPI | MPU-9250 successor |
| BMI270 | 6 | ±2000°/s | ±16g | SPI | Low power, used in fitness |
| BNO055 | 9 | ±2000°/s | ±16g | I2C | Built-in sensor fusion (quaternion output) |
| LSM6DSO | 6 | ±2000°/s | ±16g | I2C/SPI | ST, machine learning core |
Other Robot Sensors
| Sensor | Technology | Range | Rate | Best For |
|---|---|---|---|---|
| Ultrasonic | Time-of-flight (sound) | 2cm – 4m | 10-40 Hz | Short-range obstacle avoidance |
| 2D LiDAR | Time-of-flight (laser) | 0.1 – 30m | 5-40 Hz | Indoor mapping, SLAM |
| 3D LiDAR | Scanning laser | 1 – 200m | 10-20 Hz | Autonomous vehicles |
| Depth camera | IR structured light / ToF | 0.3 – 10m | 30-90 Hz | Indoor navigation, manipulation |
| GPS | Satellite triangulation | Global | 1-10 Hz | Outdoor position (±2m) |
| RTK GPS | Differential GPS | Global | 10 Hz | Outdoor position (±2cm) |
| Barometer | Air pressure | Relative altitude | 25-100 Hz | Drone altitude hold |
| Optical flow | Camera motion tracking | Ground texture | 30-100 Hz | Velocity estimation (drones) |
Calibration
Accelerometer: place IMU in 6 orientations (each axis up and down), record gravity vector, fit to sphere to find offset and scale.
Gyroscope: record data at rest for 60+ seconds. Average = bias offset. Subtract from all future readings.
Magnetometer: rotate in all orientations, fit to ellipsoid (hard-iron = offset, soft-iron = scale/rotation).
Related
- Sensor Fusion — combining IMU data with complementary/Kalman filter
- Kalman Filter — optimal estimation from noisy sensor data
- ADC and DAC — how analog sensor signals are digitized
- UART SPI I2C — digital interfaces to sensor ICs
- SLAM — sensors feed into mapping and localization
- Drone Flight Dynamics — IMU is the primary attitude sensor