Trust Your Sensors
A robot wanders around. Its position sensor is jittery and its wheel counter slowly drifts. A Kalman filter blends them into a better guess.
The blue dots are a noisy sensor. The orange robot trusts only its wheels and drifts away. My green guess uses both. The ring shows how unsure I am!
Where is the robot?
true robotnoisy sensorwheels onlyKalman guess + 2σ ring
Challenges
Beat the noise: with sensor noise 15 or more, get the Kalman error under half the raw sensor error.
Watch the wheels drift: wait until the orange guess is 60 pixels from the truth.
Into the tunnel: switch it on and watch the ring grow to twice its size while the sensor is dark.
Break it: tune the filter so badly that it is no better than the raw sensor.
What just happened?
- The sensor is right on average but jumps around. The wheel counter is smooth but slowly drifts away.
- A Kalman filter predicts where the robot should be, then corrects the prediction with each measurement.
- It weighs them by how much it trusts each: a noisy sensor gets less weight, a good prediction gets more.
- The ring is its uncertainty. It grows while predicting blind (in the tunnel) and shrinks when a measurement arrives.
- Tune it wrong and it lags behind turns (too trusting of its model) or just copies the noise (too trusting of the sensor).
For grown-ups: what's really going on
A Kalman filter for a constant-velocity model, one 2-state filter (position, velocity) per axis. Each step: predict x ← F x, P ← F P Fᵀ + Q, then update with K = P Hᵀ (H P Hᵀ + R)⁻¹, x ← x + K (z − H x), P ← (I − K H) P.
R= sensor noise variance (here the true sensor standard deviation).Q= process noise from a random-acceleration model, scaled by the slider.- The ring is a 2σ ellipse from the position variance (we show axis-aligned, since x and y are filtered separately).
- Dead reckoning (odometry) integrates a biased, noisy velocity, so error grows without bound. A position fix bounds it.
- Too small Q: the filter believes its straight-line model and lags. Too large Q: it follows the noisy measurements. The best value matches how much the robot really swerves.
- The real robot here is not exactly constant-velocity (random swerves, pulled to the middle), so the filter is useful but not optimal, like in real life. Real robots usually also fuse the wheel speed, with an Extended or Unscented Kalman filter for non-linear motion.
Further reading: Thrun, Burgard, Fox, Probabilistic Robotics, ch. 3 · Roger Labbe, Kalman and Bayesian Filters in Python.