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

Robot Foundations · Module 7: Knowing Where You Are

Dead Reckoning: Position from Counting Wheel Turns

Start from a pose you know, add up how far each wheel rolled, and you always have a pose. No map, no outside help.

  • Lesson 1 of 4
  • Beginner
  • No code
  • About 8 minutes

Sailors crossing an ocean before satellites had no landmarks to look at. They knew where they had left, how fast they had sailed and in which direction, and for how long. From that they marked the ship's position on the chart, and moved the mark a little further every hour. They called it dead reckoning, short for "deduced reckoning". A robot does the same thing with its wheels. This lesson turns the formulas you already know into the update rule that runs on every step.

What you will be able to do

  • Write the odometry update from the distance each wheel rolled.
  • Explain why the update uses the middle heading of the step.
  • Carry a pose forward through several steps by hand.
  • State what dead reckoning needs and what it cannot do.

The idea

In the lesson Sensors That Look Inward: Encoders and Inertial Sensors two encoders gave the distance each wheel rolled during one step, dL and dR. In the lesson How a Two-Wheeled Robot Drives the average of the two gave the forward distance, and the difference over the wheel base gave the turn. Odometry puts them together and applies them to the pose, once per step.

Forward distance in the step, and the angle turned in the step.

ds = (dR + dL) ÷ 2
dθ = (dR − dL) ÷ L

L is the wheel base, 0.3 m for Pip.

The new pose: move ds along the middle heading of the step, and turn by dθ.

x = x + ds × cos(θ + dθ ÷ 2)
y = y + ds × sin(θ + dθ ÷ 2)
θ = θ + dθ

Each line replaces the old value of x, y and θ by the new one. Repeat on every step.

These are the same three lines as the motion model of the lesson Speed, Time and Small Steps, with two differences. The speeds v and ω are replaced by what the encoders measured, and the heading used for moving is the heading half way through the turn.

Why the middle heading?

While the robot moves ds it is also turning by dθ. Its heading goes from θ to θ + dθ, and it is pointing in each direction in between. The average direction, a good one to use for the whole step, is the middle: θ + dθ ÷ 2. Using the heading from the start of the step would send the whole step in a direction the robot only pointed in at the beginning. For small turns the difference is tiny. For a large turn in one step it is not.

One large step (d<sub>L</sub> = 0.1 m, d<sub>R</sub> = 0.5 m, a turn of 76°) placed three ways, from a pose of (0, 0, 0°)
Way of placing the new poseNew xNew yOff from the exact answer by
Exact (the true arc)0.2190.1720
Middle heading (the update above)0.2360.1862.2 cm
Heading from the start of the step0.3019 cm

The middle-heading rule is about 9 times closer to the truth on a step this violent. That is why lab 5 asks for it, and why every robot uses it.

The pose after each of 6 steps of odometryA floor grid. Pip starts at x = 0.5, y = 0.5 facing right. Over six steps of odometry its pose is marked after each step: first straight, then curving left for two steps, straight again, then curving right for two steps, ending facing right again about 1 metre above where it started.0123450123x (m)y (m) startafter 6 steps
The poses computed by hand in the table below, joined by a line. The first step is straight, steps 2 and 3 turn left, step 4 is straight, steps 5 and 6 turn right.

Dead reckoning: new pose = old pose + what the wheels say they did. The estimate is only ever the last estimate plus one small step.

What it needs, and what it gives

  • A known start. The first pose has to be given. Odometry measures change, not position: it has no way of finding out where it started.
  • The robot's dimensions. The wheel radius (to turn encoder ticks into distance) and the wheel base L. A wrong value is a wrong answer on every step.
  • Nothing from the outside. No map, no sensor looking at the world. It works in the dark, in fog and in an empty corridor.

With perfect encoders and wheels that never slip, odometry is exact apart from the small error of using a straight line for each step. That is the first demonstration in lab 5. The next lesson is about why real robots do not get that.

Words to know

Dead reckoning
Working out a position from a known start by adding up the moves made since. On Pip: what its odometry does between sightings of anything known.
Odometry
Dead reckoning for wheeled robots: estimating the pose from wheel rotation. On Pip: the update_pose function of lab 5.
Estimate
The pose the robot believes it has. It is not the same as the true pose. On Pip: the pose the odometry holds.
Step
One pass of the update, for the distance each wheel rolled since the last one. On Pip: 0.05 s long for Pip's loop.
Middle heading
The heading half way through the turn of a step, θ + dθ ÷ 2, used to place the step. On Pip: it uses it in every step.
Wheel base (L)
The distance between the drive wheels. On Pip: 0.3 m.

A worked example: six steps of odometry

Pip starts at the pose (0.5, 0.5, 0°) and its wheel base is 0.3 m. The encoders report, for each step, the distance rolled by each wheel. Work through the first two steps.

Step 1: dL = 0.6 m and dR = 0.6 m.

  1. ds = (0.6 + 0.6) ÷ 2 = 0.6 m. dθ = (0.6 − 0.6) ÷ 0.3 = 0: straight.
  2. x = 0.5 + 0.6 × cos 0° = 1.1. y = 0.5 + 0.6 × sin 0° = 0.5. θ stays 0°.

Step 2: dL = 0.54 m, dR = 0.66 m.

  1. ds = (0.66 + 0.54) ÷ 2 = 0.6 m. dθ = (0.66 − 0.54) ÷ 0.3 = 0.4 rad = 22.9°, a left turn because the right wheel rolled further.
  2. The middle heading is 0° + 11.5° = 11.5°.
  3. x = 1.1 + 0.6 × cos 11.5° = 1.69. y = 0.5 + 0.6 × sin 11.5° = 0.62. θ = 0° + 22.9° = 22.9°.

Carry on in the same way and the table below is the whole run.

The odometry of the six steps: wheel distances in, new pose out
StepdL (m)dR (m)ds (m)dθx (m)y (m)θ
10.60.60.60°1.10.50°
20.540.660.622.9°1.690.6222.9°
30.540.660.622.9°2.180.9645.8°
40.60.60.60°2.61.3945.8°
50.660.540.6-22.9°3.11.7322.9°
60.660.540.6-22.9°3.681.850°

The right wheel rolled further in steps 2 and 3, so the pose turned left. In steps 5 and 6 the left wheel rolled further, so it turned back right and ended facing 0° again. The total distance is 3.6 m, the net movement 3.46 m.

Try it yourself

Pip (L = 0.3 m) is at (0, 0, 0°). In one step the left wheel rolls 0.30 m and the right wheel 0.36 m. (a) What are ds and dθ in degrees? (b) What is the new pose, using the middle heading?

Answer

(a) ds = (0.36 + 0.30) ÷ 2 = 0.33 m. dθ = (0.36 − 0.30) ÷ 0.3 = 0.2 rad = 11.5°, a left turn. (b) The middle heading is 5.7°. x = 0.33 × cos 5.7° = 0.328. y = 0.33 × sin 5.7° = 0.033. θ = 11.5°. The pose is (0.328, 0.033, 11.5°).

Common mistakes

"Odometry measures position."

It measures the movement of the wheels and works the position out from a given start. Without a known start pose, or if the start was wrong, every pose after it is wrong by the same amount.

"Use the old heading to move, then turn: it is simpler."

It is, and it is wrong whenever the turn in a step is not tiny. The middle heading costs one extra line and removes most of the error.

"If the update is exact, the estimate is exact."

The update is exact for the wheel distances it is given. The wheel distances are what the encoders report, not what the robot did, and the next lesson is about the difference.

Remember this

  1. ds = (dR + dL) ÷ 2 and dθ = (dR − dL) ÷ L.
  2. The pose moves by ds along the middle heading θ + dθ ÷ 2, then the heading turns by dθ.
  3. Dead reckoning needs a known start and the robot's dimensions, and nothing from outside.
  4. With perfect encoders and no slip it is exact. Real robots do not have either.

Check yourself

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

Question 1

A robot with a wheel base of 0.4 m rolls its left wheel 0.50 m and its right wheel 0.50 m in one step from (1, 2, 90°). What is the new pose?

Explanation

ds = 0.50 m and dθ = 0, so it drives straight along its heading of 90°, which is along +y. The new pose is (1, 2.5, 90°).

Question 2

The left wheel rolls 0.2 m and the right wheel 0.5 m. Which way does the robot turn, and by roughly how many radians if the wheel base is 0.3 m?

Explanation

The right wheel rolled further, so it turns left. dθ = (0.5 − 0.2) ÷ 0.3 = 1.0 rad, about 57°.

Question 3

Why does the odometry update use the heading half way through the step?

Explanation

During a step the robot is turning, so it points in a range of directions between the start and end headings. The middle one is the best single direction to place the whole step. The start heading would be wrong by half the turn, and the error grows with the size of the step and the size of the turn.

What’s next

Dead reckoning is exact on paper. The next lesson shows what it does on a real floor, with wheels that slip and encoders that are not quite right.

Next lesson

Why Drift Grows

Explain why small errors in each step add up, and why an error in heading is worse than an error in distance.

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.