Skip to the lesson
FixTheRobot Explore Robotics / Robot Foundations / Module 7 / Lesson 2

Robot Foundations · Module 7: Knowing Where You Are

Why Drift Grows

Every step adds a tiny error, and nothing ever takes one away. A heading error is the worst kind, because it misdirects everything that follows.

  • Lesson 2 of 4
  • Beginner
  • No code
  • About 10 minutes

On paper, odometry is exact. On a floor it is wrong by a little on every step, and the wrongness has nowhere to go. It piles up. The robot is never told "you have drifted"; it simply goes on believing its last estimate, and the estimate slides further from the truth the longer the robot runs. This lesson separates the different ways odometry goes wrong, shows the numbers, and explains why one of them is far more damaging than the others.

What you will be able to do

  • Name the main sources of odometry error.
  • Explain why errors in distance and errors in heading behave differently.
  • Read how the position error grows with distance driven.
  • Explain why odometry alone can never be trusted for long.

The idea

Where the errors come from

  • Wheel slip. The wheel turns and the robot goes less far (lesson Commands Are Not Motion). The encoder counts the turn, not the movement.
  • Wrong dimensions. A wheel radius or wheel base in the program that is a little off from the real one. Tyres wear and squash.
  • Encoder noise. A wheel that really rolled 1.00 m may be measured as 0.97 m or 1.04 m, differently each time.
  • The floor. Bumps, a cable, a change from tile to carpet.

Whatever the source, the effect on one step is small. The trouble is that odometry adds each step to the last: the error of the new pose is the old error plus the error of this step. Nothing in the update ever subtracts error.

Two kinds of error

What matters is whether the error is the same on both wheels or different between them.

  • The same on both wheels (both slip 10%, say). Both distances are too big by the same share. The average, ds, is too big by that share, and the difference, dθ, is too big by that share of nothing: still zero. The robot thinks it went further than it did, in the right direction. The position error is a fixed share of the distance driven.
  • Different between the wheels (one encoder reads 2% high). The difference between the two distances is now wrong, so dθ is wrong on every step. The estimated heading drifts steadily away from the true heading, and because every later step is placed along the wrong heading, the position error grows much faster.
The typical position error and heading error of odometry after three distances, for four kinds of error, simulated over 200 runs each (the cases with no random part give the same result every time)
Case (straight drive at 0.5 m/s)After 5 mAfter 10 mAfter 20 m
Random encoder noise, 4% on every step0.19 m, 4°0.54 m, 5°1.51 m, 8°
Both wheels slip 10%0.5 m, 0°1 m, 0°2 m, 0°
One encoder over-reads by 2%0.84 m, 19°3.3 m, 38°12.73 m, 76°
The wheels slip by different amounts (10% and 8%)0.92 m, 19°3.31 m, 38°12.42 m, 76°

Look at the rows one at a time.

  • Both wheels slipping 10%: the position error is exactly 10% of the distance (0.5, 1, 2 m), and the heading error is 0°. It grows in proportion to the distance, no faster.
  • One encoder 2% high: after 5 m the heading is already 19° wrong. By 20 m it is 76° wrong, and the position error is 12.7 m: the estimate has gone round a corner while the robot went straight. Doubling the distance more than doubles the error each time (0.84, 3.3, 12.7 m).
  • Random noise (4%): because it changes sign from step to step it partly cancels, and the error is small to begin with (0.19 m at 5 m). It still grows faster than the distance: 1.5 m at 20 m.
Odometry position error against distance for three kinds of errorA plot of position error against distance driven, up to 20 metres. A green straight line, for both wheels slipping 10 percent, rises steadily to 2 metres. A blue curve, for random encoder noise, rises slowly then faster to about 1.5 metres. An orange curve, for one encoder reading 2 percent high, curves upward steeply, reaching about 12.7 metres at 20 metres.0510152002468101214distance driven (m)position error of the estimate (m) one encoder +2% both slip 10% noise 4%
The same three cases as a picture. The orange curve is a heading error that grows steadily: its damage keeps accelerating.

Why heading is the worst

Suppose the heading error grows steadily as the robot drives, reaching θ by the end of a straight drive of length D. For the first part of the drive the error is tiny and for the last part it is nearly θ, so the average heading error is about half of θ, and the sideways error of the estimate is about:

The sideways error is about the distance driven multiplied by half the final heading error, in radians.

sideways error ≈ D × θ ÷ 2

This holds for small angles. It is why a heading error that grows with distance gives a position error that grows with distance squared.

Check it against the table. After 5 m the heading error is 19.1°, which is 0.33 rad, so the rule gives 5 × 0.33 ÷ 2 = 0.83 m, against 0.84 m in the simulation. At larger angles the small-angle rule fails, and the real curve bends over, but the lesson holds: heading drives drift.

An error that is the same on both wheels costs a fixed share of the distance. An error that differs between the wheels turns the estimate, and a turned estimate keeps going the wrong way.

You cannot fix this by making the robot more careful. Every real robot has some difference between its wheels. The drift can only be made slower, by calibrating the wheels well, and removed, by looking at something outside the robot. That is the next lesson.

Words to know

Drift
The error of an estimate that keeps growing because each step builds on the last. On Pip: its odometry drifts a little further every second it runs.
Systematic error
An error that is the same every time, such as a tyre that is 2% too big. On Pip: the encoder that reads 2% high.
Random error (noise)
An error that differs from step to step and partly cancels. On Pip: the 4% noise per step.
Heading drift
The growing error in the estimated direction. On Pip: 76° after 20 m in the 2% example.
Calibration
Measuring the robot's real wheel radius and wheel base and correcting the numbers in the program. On Pip: driving a measured 5 m and adjusting the wheel radius until the count agrees.
Accumulate
To add up. Odometry accumulates the error of every step. On Pip: what makes small errors big.

A worked example: how far off after a long straight drive?

Pip drives straight for 20 m at 0.5 m/s. Its right encoder over-reads by 2%. The wheel base is 0.3 m.

  1. The error on each step. The right wheel measures 2% more than it rolled. Over a distance D the difference between the two measured distances is 0.02 × D.
  2. Heading error. dθ = difference ÷ wheel base, so after 20 m the estimate's heading is wrong by 0.02 × 20 ÷ 0.3 = 1.33 rad, which is 76°. (The simulation agrees: 76°.)
  3. The estimate has turned. The robot has really driven in a straight line. The odometry has it going round a long left curve.
  4. Position error. After 20 m the estimate is 12.7 m from the truth: the estimate believes the robot is round the corner, and the robot is still on the straight.

The same drive with both wheels slipping 10%. The heading error is zero, and the estimate is on the right line, but ahead of the robot by 10% of 20 m = 2 m. That is far less damaging than the 12.7 m of the first case, though it is the same size of error per step. Where an error comes from matters much more than how large it looks.

Try it yourself

Walk across a room with your eyes closed, counting your steps as if they were encoder ticks, and stop when you think you are at the other wall. (a) How far from the wall are you? (b) Now do it again, but shuffle your left foot a little shorter than the right. What happens to the path, and why is that worse than taking every step 10% short?

What to expect

(a) Probably within half a metre of the wall, if the room is 5 m across: a small distance error. (b) With one foot shorter you walk in an arc and end up well to the side, and the further you go the further you end up from where you intended. Taking all steps 10% short only leaves you short of the wall, in the right direction. The difference between the two sides is the difference that does the damage.

Common mistakes

"A 2% error is small, so the drift will be small."

Two percent in the difference between wheels is a heading error of 3.8° per metre for a robot this size: 76° after 20 m. Small errors per step become large errors through accumulation.

"Random noise is the main problem."

Noise partly cancels. Steady differences between the wheels do not, and they dominate on long drives.

"If I average the encoder readings the drift goes away."

Averaging reduces noise but not bias (lesson 4.4), and the dominant drift is a bias between the wheels. Calibration can reduce it, and only an outside observation can remove what remains.

Remember this

  1. Odometry adds each step to the last, and nothing in it removes error: drift grows.
  2. An error equal on both wheels costs a fixed share of the distance driven.
  3. A difference between the wheels turns the estimate, and sideways error grows like D × θ ÷ 2, so much faster than the distance.
  4. Odometry cannot be trusted for long. Calibration slows drift and an outside observation removes it.

Check yourself

Three questions. Write an answer in your own words, then reveal the explanation. Nothing you type leaves your browser.

Question 1

Both wheels of a robot slip by 5%. After driving 40 m in a straight line, how far is the odometry estimate from the true position, and in which direction?

Explanation

5% of 40 m is 2 m. Because both wheels slip equally, the heading estimate is right, so the estimate is 2 m ahead of the robot along its line of travel (the odometry believes the robot went further than it did).

Question 2

The left encoder of a robot reads 1% low and the right is perfect. Is the estimated heading drifting to the left or the right, and why?

Explanation

To the left. The left wheel is measured as having rolled less, so the right wheel appears to roll further than the left, and the difference between them is read as a left turn. The heading estimate drifts left even while the robot drives straight.

Question 3

A heading error that grows to 0.2 rad over a 10 m straight drive gives roughly what sideways position error?

Explanation

sideways error ≈ D × θ ÷ 2 = 10 × 0.2 ÷ 2 = 1.0 m. A heading error of only about 11° has put the estimate a metre to the side after 10 m.

What’s next

Odometry is smooth, always available and slowly wrong. To stop the drift the robot needs something that is not built from its own past: an observation of the world.

Next lesson

Landmarks: Correcting with Something You Recognise

Use one measurement to a landmark at a known place to correct a drifting position.

The lab of this module (after lesson 4)

Where Am I?

Write odometry in Python, watch it drift with wheel slip and noise, and correct it with a landmark. About 35–45 minutes.

Where this goes on the site

Nothing below is needed to continue this course. These pages take the topic of this module further, and most assume more mathematics or Python than this course does.