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

ConfigurationSensorsCan Estimate
6-DOFAccel + GyroRoll, pitch (yaw drifts)
9-DOFAccel + Gyro + MagRoll, pitch, yaw (with mag calibration)

Most flight controllers use 6-DOF + GPS for yaw, since magnetometers are unreliable near motors.

Sensor Noise

Noise TypeSourceEffectMitigation
White noiseRandom fluctuationsJittery readingsAveraging, low-pass filter
BiasManufacturing offsetConstant errorCalibration (measure at rest, subtract)
Bias driftTemperature, agingSlowly changing offsetSensor Fusion, recalibration
Scale factor errorSensitivity variationReadings 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

ChipDOFGyro RangeAccel RangeInterfaceNotes
MPU-60506±2000°/s±16gI2C/SPIClassic, cheap, discontinued
ICM-209489±2000°/s±16gI2C/SPIMPU-9250 successor
BMI2706±2000°/s±16gSPILow power, used in fitness
BNO0559±2000°/s±16gI2CBuilt-in sensor fusion (quaternion output)
LSM6DSO6±2000°/s±16gI2C/SPIST, machine learning core

Other Robot Sensors

SensorTechnologyRangeRateBest For
UltrasonicTime-of-flight (sound)2cm – 4m10-40 HzShort-range obstacle avoidance
2D LiDARTime-of-flight (laser)0.1 – 30m5-40 HzIndoor mapping, SLAM
3D LiDARScanning laser1 – 200m10-20 HzAutonomous vehicles
Depth cameraIR structured light / ToF0.3 – 10m30-90 HzIndoor navigation, manipulation
GPSSatellite triangulationGlobal1-10 HzOutdoor position (±2m)
RTK GPSDifferential GPSGlobal10 HzOutdoor position (±2cm)
BarometerAir pressureRelative altitude25-100 HzDrone altitude hold
Optical flowCamera motion trackingGround texture30-100 HzVelocity 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).