Knowing where you are
Counting your own steps drifts. GPS jumps around. Combine them and you get something better than either. This is localisation.
In 60 seconds
Knowing where you are
Counting your own steps drifts. GPS jumps around. Combine them and you get something better than either. This is localisation.
Dead reckoning: counting your own movement
# A robot thinks each wheel turn moves it 1.00 m.
# In truth the wheel is slightly worn and moves 0.98 m per turn.
believed_per_turn = 1.00
real_per_turn = 0.98
for turns in [10, 100, 1000, 5000]:
believed = turns * believed_per_turn
real = turns * real_per_turn
print(f"after {turns:5d} turns: believes {believed:7.1f} m, really {real:7.1f} m, "
f"error {believed - real:6.1f} m")GPS: noisy but does not drift
| Dead reckoning | GPS | |
|---|---|---|
| Short-term | Smooth and precise | Jumpy, a few metres of noise |
| Long-term | Error keeps growing (drift) | Error stays about the same |
| Indoors, tunnels | Still works | Often fails |
| Update speed | Very fast | A few times a second |
Combining them: predict, then correct
- 1
Start
An estimate of position, and a number for how unsure you are (the variance). - 2
Predict
Add the movement from the wheels or IMU. Uncertainty grows a little. - 3
Measure
A GPS reading arrives, with its own uncertainty. - 4
Correct
Take a weighted average: trust the less uncertain one more. Uncertainty shrinks. - 5
Repeat
Every step. Drift can never build up, and GPS noise is smoothed out.
Watch and read more
Lab
A fuse() function that combines dead reckoning and GPS, beating both on made-up data.
The problem
This runs in your browser. A robot drives along a straight road. Its wheel reading is 5% too high (drift), and its GPS has about 3 m of noise. All numbers are made up.
- Finish
fuse(estimate, est_var, measurement, meas_var). Use the weightk = est_var / (est_var + meas_var). The new estimate moveskof the way towards the measurement. The new variance is(1 - k) × est_var. - Run it and compare the three errors. Look at the plot.
- Change
GPS_VARto 100 (you trust GPS much less). What happens to the fused line? Write two sentences.
Practice lab
Edit the code and run it. Python runs in your browser — nothing is sent to our server.
No output. Add print(...) to see values.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1The wheel reading is biased (5% too high), but the filter assumes only random error. Why does fusion still work well?Reveal
GPS keeps pulling the estimate back, so the bias cannot build up without limit. The fused estimate ends up a small, steady distance ahead of the truth instead of drifting further and further away. A better filter could also estimate the bias itself, by adding it to the things it tracks, and then correct the wheel readings.
Q2What would happen to the fused estimate if GPS were lost for 30 seconds?Reveal
During the outage, only the predict step runs. The estimate follows dead reckoning and drifts, and the variance grows each step. When GPS comes back, the large variance means the filter trusts the first new GPS reading a lot and jumps back towards it. Good systems also check that the returning reading is sensible before trusting it.
Questions people ask
Why is it called dead reckoning?
It is an old term from ship navigation, where sailors worked out their position from speed, heading and time. The exact origin of the name is not certain. The idea is the same in robots today.
How accurate can satellite navigation get?
An ordinary phone or drone receiver is often a few metres off in open sky, and worse in cities. Special setups that use correction signals from a nearby base station can reach centimetre-level accuracy. These are used in surveying and precision farming. Check current equipment before promising a number.
Does the Kalman filter need GPS?
No. It combines any prediction with any measurement: wheel counts with a camera, IMU with a barometer, and so on. GPS is just the most common example.
What happens if the GPS reading is badly wrong?
A single wild reading can pull the estimate off. Good systems check each reading against the prediction and ignore ones that are far too different. This is called outlier rejection or gating.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.