- Words first: u[n] = the move the encoder reports at step n. x̂[n] = our estimate of the position after step n. P = how unsure we are (the variance of that estimate). Q = the variance one noisy move adds each step.
- Dead reckoning: start at a known spot and keep adding the measured moves: x̂[n] = x̂[n−1] + u[n].
- Each step adds a fresh error, and the errors accumulate instead of cancelling.
- The variance P grows by Q every step, so P = n·Q and σ grows like √n.
- With no position sensor, nothing ever shrinks P. The estimate drifts.
Walking with your eyes closed
Stand at your front door, close your eyes and walk to the kitchen by counting steps. The first few steps go fine. But each step is a bit longer or shorter than you think. After twenty steps you bump into a wall that "should not be there". You did nothing wrong. The small errors just added up.
A robot with only a wheel encoder has the same problem.
The encoder and dead reckoning
An encoder is a sensor on the wheel that counts how far it turns. u[n] is the move the encoder reports for step n, in metres: the true move plus some noise.
Dead reckoning means: start at a known position, then keep adding the measured moves.
The hat on x̂ means "our estimate of x", not the true value. The [n] is the step number. We add u[n], the move the encoder reports, because the true move is unknown. A quick example: the robot starts at 2 m and the encoder reports moves of 0.6, 0.4 and 0.5 m.
Why the errors pile up
Each encoder reading u[n] is the true move plus noise. Call the noise's standard deviation σ_enc, so its variance is Q = σ_enc² per step. We will call Q the process noise (noise in the motion itself): the uncertainty we add every time the robot moves without looking.
The estimate's own uncertainty is its variance P. Each step adds an independent error, and variances of independent errors add (lesson 1):
For example, with σ_enc = 0.5 m we get Q = 0.25:
Notice the square root. Four times as many steps only doubles σ. That is the good news. The bad news: σ never stops growing. There is no step that makes P smaller, because the robot never checks where it actually is.
Drift
So the estimate drifts: it wanders off the true path and stays off. Here is a robot whose speed changes a little, with σ_enc = 0.5 m (Q = 0.25). The picture shows steps 0 to 29. The lab below runs all 79 steps, so its band ends wider.
The band is ±2σ, and σ = √P. At step 29, P = 29 · 0.25 = 7.25, so σ ≈ 2.69 m and the band is about ±5.4 m. The error you actually get depends on luck. Run the same robot four times, with four different sets of encoder noise:
A bigger example: five steps, one by one
A robot starts at exactly 0 m (P = 0) and really moves 1.0 m every step. Its encoder has σ_enc = 0.2 m, so Q = 0.04. The encoder reports 1.2, 0.9, 1.3, 1.1 and 0.8 m.
Each reading is only 0.1 to 0.3 m off, but the error of the estimate is the sum of all of them so far. It never resets. A real robot runs thousands of steps, and the sum keeps growing.
Where this shows up
Your phone does dead reckoning in a tunnel, using its step counter and compass (a sensor that tells which way is north) until GPS comes back. Submarines navigate this way under water. Warehouse robots count wheel turns between floor markers. In every case the fix is the same: every so often, look at a position sensor.
Reading the lab code
In the code, v is the true move per step and u is what the encoder reports. Python counts from 0, so u[0] holds the move for step 1, u[1] the move for step 2, and so on. The same goes for v. As in lesson 1, dashed(...) draws a dashed line (the truth). New here: line(...) draws a solid line. band= gives σ at each step, and the picture shades ±2σ around the line. Hint for the exercise: the final σ is √79 · enc_std.
Next: a sensor that measures the position itself, the GPS. It never drifts, but it has a problem of its own.
Examples
Example 1 · How fast the band grows
The encoder noise is σ_enc = 0.5 m per step, so Q = 0.5² = 0.25. The start is known exactly (P = 0).
Show solutionHide solution
25 times as many steps, only 5 times the σ. But 10 m either way is already useless for a robot in a corridor.
Example 2 · One estimate, step by step
A robot starts at exactly 10 m (P = 0). Here the encoder reports speed, not distance, so each move is u = speed · Δt, where Δt ("delta t") is the time between steps: Δt = 0.5 s. The speeds are 2.1, 1.9 and 2.0 m/s over three steps. Each step adds Q = 0.04 m².
Show solutionHide solution
The estimate is a clean number. The variance tells you not to trust it too much.
Example 3 · Even a good encoder drifts
A careful encoder has σ_enc = 0.02 m per step, so Q = 0.0004. A delivery robot runs 10,000 steps down long aisles.
Show solutionHide solution
A sensor 25 times better than one with σ_enc = 0.5 m still loses the robot over a long enough run. Better hardware slows the drift. It never stops it.
Example 4
An encoder has σ_enc = 0.3 m per step. The start is known exactly. Find P, σ and the ±2σ band after 25 steps.
Show solutionHide solution
Q = 0.3² = 0.09. After 25 steps, P = 25 · 0.09 = 2.25.
σ = √2.25 = 1.5 m, so the ±2σ band is ±3 m.
Example 5
A robot starts at 5 m with P = 1. The encoder reports moves of 1.2, 0.8, 1.0 and 1.0 m over four steps, with Q = 0.5 per step. Find the estimate and its variance after four steps.
Show solutionHide solution
Position: 5 + 1.2 + 0.8 + 1.0 + 1.0 = 9.0 m.
Variance: the starting P = 1 carries over, plus 4 · 0.5 = 2, so P = 3 (σ ≈ 1.73 m). Dead reckoning never forgets its starting doubt. It only adds to it.

Questions and comments
Stuck on something, or found a mistake? Ask here and I'll answer. You sign in with GitHub.