An inertial measurement unit, the accelerometer plus gyroscope chip in every robot, tells you how the robot is moving right now, but integrating those measurements into position and orientation accumulates error without bound: the dreaded IMU drift. A robot that trusts its IMU alone thinks it has wandered meters after standing still for a minute. The Extended Kalman Filter fuses the IMU with absolute references, wheel odometry, GPS, visual landmarks, or magnetometers, producing an estimate better than any single sensor. It is the standard solution because it handles the nonlinearity of real robot motion while remaining computationally practical.

Why IMUs Drift
An IMU measures acceleration and angular velocity, not position or orientation. Getting position requires integrating acceleration twice and orientation once, and integration accumulates every tiny sensor error. Gyroscopes have bias, a small constant offset, that integrates into a steadily growing orientation error; a fraction of a degree per second of uncorrected bias becomes tens of degrees within a minute. Accelerometers have bias and noise too, and worse, they cannot distinguish tilt from acceleration: a small orientation error misattributes a component of gravity as horizontal acceleration, which double-integrates into position error that grows quadratically with time. Consumer-grade IMUs drift visibly within seconds; even good ones are useless alone beyond short intervals. The IMU is an excellent short-term sensor and a terrible long-term one, which is exactly the gap sensor fusion fills.
What the EKF Actually Does
The Kalman filter maintains two things: an estimate of the state (position, orientation, velocity, sensor biases) and an estimate of how uncertain that estimate is (the covariance). Each cycle has two steps. The predict step uses the IMU measurements and a motion model to project the state forward in time, growing the uncertainty to reflect that prediction is imperfect. The update step takes an absolute measurement, a GPS fix, a wheel odometry reading, a visual landmark observation, and corrects the estimate, shrinking the uncertainty. The filter weights the correction by the relative uncertainties: it trusts the prediction more when sensors are noisy and the measurement more when the prediction has drifted. The "Extended" part handles nonlinearity: robot orientation lives in a nonlinear space, so the EKF linearizes the motion and measurement models around the current estimate each cycle, which works well as long as the estimate stays reasonably close to truth.
Choosing the Fusion Sources
The IMU provides the high-rate prediction; the absolute sources provide the drift correction, and the choice of sources defines the system's capability. Wheel odometry corrects position drift on ground robots but inherits its own errors from wheel slip. Magnetometers correct yaw drift but are corrupted by nearby metal and motors, a serious issue on robots built from steel and full of electromagnetic noise. GPS corrects absolute position outdoors but is unavailable indoors and noisy at the meter scale. Visual odometry or fiducial markers correct drift beautifully where cameras work but fail in darkness or featureless environments. The art is pairing sources whose failure modes do not overlap: IMU plus wheel odometry plus occasional absolute fixes covers most ground-robot cases. Each source needs a measurement model telling the filter what the sensor observes and a noise characterization telling it how much to trust the observation; wrong noise values make the filter overconfident in bad data or dismissive of good data.
Bias Estimation: The Quiet Superpower
One of the EKF's most valuable outputs is not position at all but the estimated sensor biases. By including gyro and accelerometer biases in the state vector, the filter continuously learns the IMU's offsets from the disagreement between prediction and absolute measurements. A robot that sits still while GPS says it is stationary learns its gyro bias within seconds; a robot driving straight while wheel odometry disagrees with the IMU's heading learns the yaw bias. This online calibration means the system improves as it runs and adapts to temperature-induced bias drift, which is significant in real IMUs. The practical implication: give the filter observability. Brief periods of known motion or stillness with good absolute measurements let the biases converge; a robot that only ever runs open-loop at speed gives the filter little to work with.
Tuning and Failure Modes
EKF tuning is mostly about the noise parameters: process noise (how much to distrust the motion model) and measurement noise per sensor. Start from the sensor datasheets' noise densities, then tune empirically: a filter that jumps nervously with each measurement trusts measurements too much; one that drifts despite good absolute data trusts them too little. Watch for the classic failure modes. Inconsistent linearization, when the estimate is far from truth, the linearization is wrong and the filter can diverge; robust implementations detect this and reinitialize. Delayed or out-of-sequence measurements need proper timestamp handling, or the update corrects the wrong state. And unmodeled errors, like a wheel diameter that changed with tire wear, bias every estimate silently; the filter is only as honest as its models. Log the filter's own uncertainty estimates: a covariance that stays small while the true error grows means the filter is confidently wrong, the most dangerous state.
The EKF turns a drifting IMU into a reliable pose estimate by pairing fast prediction with absolute correction, learning sensor biases along the way. Characterize your sensors honestly, choose fusion sources with complementary weaknesses, tune the noise parameters empirically, and watch the covariance. Drift becomes a managed quantity instead of a mission-ending one.
Related Guides
- Complementary Filter Tuning for Six-Axis IMU Drift: A six-axis IMU gives you a gyroscope and an accelerometer, and neither one tells the truth by itself. The gyroscope measures rotation rate
- Anti-Windup Reset Tuning in PID Loops: Integral windup is the PID loop's original sin: while the actuator is saturated, the integrator keeps accumulating error, building up a huge
- Feedforward Gain Tuning for High Acceleration Servos: Servo control loops react to error: the motor lags the command, the controller sees the lag, and it pushes harder. Feedforward skips the waiting: it
- Low-Pass Noise Filtering on Raw Gyroscope Inputs: A raw gyroscope signal looks nothing like the smooth rotation it represents. Zoom in and the trace is a thick band of jitter: vibration from motors