Skip to the lesson
FixTheRobot Explore Robotics / Robot Foundations / Module 6 / Lesson 3

Robot Foundations · Module 6: Building a Map

A Map Needs a Pose

A scan says where things are relative to the robot. To put them on the map, the robot must know where it was. If it is wrong, the map is wrong.

  • Lesson 3 of 3
  • Beginner
  • No code
  • About 9 minutes

Imagine drawing a floor plan of a room by walking round it with a tape measure, but with a blindfold on that makes you lose your sense of which way you are facing. Every measurement is good. You write them all down. The plan comes out as a smeared, doubled, bent copy of the room, because each measurement was recorded from the wrong place. A robot that builds a map from a drifting pose does exactly this. It is the central difficulty of mapping, and the reason the next module exists.

What you will be able to do

  • Explain why a scan can only be put on the map using the robot's pose.
  • Compute how far a wall is displaced by a small error in heading.
  • Describe what a map looks like when it was built from a wrong or drifting pose.
  • State the chicken-and-egg problem of mapping and localization.

The idea

Remember the two frames of the lesson Two Points of View: the Robot and the World. A scan arrives in the robot frame: "the wall is 3 m ahead". The map is in the world frame: "the wall is at x = 4.2, y = 1.0". The pose is the translation between them. Writing a beam into the map therefore takes two inputs: the reading and the pose, as in the lesson Occupancy Grids: Free, Occupied, Unknown.

When the pose the robot believes is correct, scans from many places line up: a wall seen from here and the same wall seen from there land on the same cells. When it is wrong, they do not.

How wrong does a small error make the map?

Take a heading error first. If the robot believes it faces θ but really faces θ + δ, every beam is written δ off. A point at distance d on the beam lands sideways by about:

The sideways displacement is about the distance to the wall multiplied by the heading error in radians.

displacement ≈ distance × heading error

The same rule as for the gap between laser beams. It grows with the distance, so far walls move most.

How far a wall is displaced for four heading errors at two distances
Heading errorWall at 2 m moves byWall at 4 m moves byCells of 0.5 m, at 4 m
1°3 cm7 cm0.1
3°10 cm21 cm0.4
5°17 cm35 cm0.7
10°35 cm70 cm1.4

A 5° error, about what the gyroscope of the lesson Sensors That Look Inward: Encoders and Inertial Sensors gathers in a minute (6°), moves a wall 4 m away by 0.35 m: most of a cell. A 10° error moves it 0.7 m, more than a whole cell. A position error is different: it moves everything by the same amount, whatever the distance. Both are common and both build up (lesson Commands Are Not Motion).

What a drifting pose does to a map

The error also grows: each step of odometry adds a little. Scans taken later are written with more error than scans taken earlier. The same wall, seen five times along a drive, is written in five slightly different places. The result is a wall that looks thick, doubled or bent.

A map built from true poses and from drifting posesTwo grid maps of the same room, six by four metres, built from five scans taken while driving along its middle. On the left, built from the true poses, the walls are clean and the box and pillar are single blocks. On the right, built from poses whose error grows with each scan, extra dark cells appear: the walls are doubled and the box and pillar are smeared.Built from the true posesBuilt from poses that drift
The same five scans, written twice. Left: from the true poses. Right: from believed poses that drift (about 9 cm and 3° more error at each scan). Orange and blue dots show where the robot stood.

Counting the cells: the clean map has 44 occupied cells. The drifted one has 49. Of those, 10 are ghost walls: cells that are not occupied in the real room. And 5 cells that really are occupied are missing: the wall was written next to them. A planner using the second map would avoid walls that are not there and drive at walls that are.

A map is only as good as the pose it was written from. Wrong poses make ghost walls and hide real ones.

The chicken and the egg

This looks like a trap. To build a good map the robot needs to know where it is. To know where it is, from a scan, it needs a good map to compare against.

  1. To map the room, I need to know where I am
  2. To know where I am, I need a map of the room

Neither can be done first, and the way out is to do both together, a little at a time, correcting each with the other. The robot builds a piece of map, uses it to correct its pose, uses the better pose to extend the map, and so on. This is called SLAM: Simultaneous Localization And Mapping. Full SLAM is the subject of the Localization and SLAM track on this site. The next module in this course teaches its first half: how a robot keeps track of where it is, and what to do when the count drifts.

In lab 4 you will see this directly: the "robot pose matters" stage gives the robot a wrong idea of where it is and shows the map smearing, then asks you to compare it with a map built from the true pose.

Words to know

Pose
Position and heading together: (x, y, θ). On Pip: what the scan is written from.
Ghost wall
A cell marked occupied on the map where nothing is in the real world. On Pip: 10 cells in the drifting map.
Smearing
Writing the same feature in slightly different places, so that it looks thick or doubled. On Pip: a wall seen five times from poses that drift.
Localization
Working out where the robot is. On Pip: module 7.
Mapping
Building the map from the readings and the pose. On Pip: this module.
SLAM
Simultaneous Localization And Mapping: building the map and finding the robot's place in it at the same time. On Pip: the full problem, covered on the Localization and SLAM track.

A worked example: one wall, one degree at a time

Pip believes it faces 0° but really faces 5° to the left. It sees a wall straight ahead of its true heading, 4 m away. Where does the map put the wall?

  1. The reading. 4 m, along the robot's forward direction.
  2. What the robot believes. It faces 0°, so it writes the wall 4 m straight ahead on the x axis.
  3. Where the wall really is. The robot really faces 5°, so the wall is at 4 × cos 5° = 3.98 m along x and 4 × sin 5° = 0.35 m to the side.
  4. The displacement. The map has the wall 0.35 m (about 0.7 cells) from its true place. The quick rule gives 4 × 0.087 = 0.35 m: close enough.

Over a drive. In the figure, the pose error at the first scan is zero. By the fifth scan it is 38 cm in position and 12° in heading. A 12° error at 4 m displaces a wall by 0.84 m, about 1.7 cells. That is why the right-hand map of the figure is so much worse than the left.

Try it yourself

Stand in the middle of a room and point at a wall, remembering exactly where on the wall you are pointing. Turn your whole body 10° to the right, without looking. Now point at the "same spot" on the wall without looking. (a) Where did your finger land, and was it nearer or further than the spot? (b) Move to the far side of the room and try again. What changes with the distance?

What to expect

(a) Your finger lands to one side of the spot. For a wall 3 m away, a 10° heading error moves the point by about 3 × 0.17 = 0.5 m. (b) From twice as far, the same 10° moves it twice as far: about 1 m. The error is the same angle, but its effect on the map is proportional to distance. A robot that looks at far walls, with a heading error, writes them far from where they are.

Common mistakes

"A map is made of what the sensor sees, so it is accurate if the sensor is accurate."

A scan is only half of what the map needs. The other half is the pose. A perfect sensor with a drifting pose draws a smeared map.

"A small angle error is a small problem."

The displacement is the angle times the distance. A 5° error is only 9 cm at 1 m and a third of a metre at 4 m. And the angle error does not stay small: it keeps growing as the robot drives.

"Fix the map afterwards by comparing it with the first scan."

It can be done, and that is what the correction steps of SLAM do. But it needs a way of saying how the scans should line up, which is more work than avoiding the error, and the next module starts with how.

Remember this

  1. A scan goes into the map using the robot's pose. The map is only as good as that pose.
  2. A heading error δ moves a wall at distance d sideways by about d × δ (δ in radians).
  3. A drifting pose smears the map: doubled walls, ghost walls, and real walls missing.
  4. Mapping needs the pose and localization needs the map: SLAM does both together.

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 has a heading error of 3° (0.052 rad). By about how much is a wall 5 m away displaced in the map?

Explanation

displacement ≈ distance × error = 5 × 0.052 = 0.26 m, about half a cell of 0.5 m. The same error moves a wall at 1 m by only about 5 cm.

Question 2

Two scans of the same wall, taken from different places on a drive, are written into the map. The wall appears twice, about 0.4 m apart. What probably went wrong?

Explanation

The robot's pose estimate had drifted between the two scans: it did not know its position or heading accurately at one or both of them, so the same wall was written in two places. The map is smeared because the pose, not the sensor, was wrong.

Question 3

Why can a robot not simply build the whole map first and then work out where it is?

Explanation

To build the map it needs to know where it was at every scan, and its pose estimate drifts as it moves. A map built from a drifting pose is smeared and then makes a poor reference for finding its position. Both must be improved together, which is the idea of SLAM.

What’s next

That finishes the theory for lab 4: you can read a map, build one from readings, and say what a wrong pose does to it. After the lab, module 7 asks how the robot can know where it is.

You are ready for the lab

Build the Robot's World

Turn range readings into an occupancy grid, explore a room, and see what a wrong pose does to the map. About 25–35 minutes.

Next lesson

Dead Reckoning: Position from Counting Wheel Turns

Compute a new pose from encoder counts, one small step at a time.

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.