Robot Foundations · Module 2: Describing a Robot with Numbers
Two Points of View: the Robot and the World
"Two metres ahead of me" and "at x = 2, y = 3 in the room" can be the same spot. Which description you use depends on who is asking.
Pip's scanner reports a box 2 m ahead and 1 m to the left. That is perfectly clear to Pip. It is useless to anyone else until they know where Pip is and which way it faces. And when Pip drives on, "2 m ahead" stops being true, though the box has not moved. Robots constantly translate between descriptions like these. Getting the translation wrong is the most common bug in all of robotics, so it is worth understanding from day one.
What you will be able to do
- Explain what a frame is, and name the two this course uses.
- Say which frame sensor readings come in and which frame maps and goals are in.
- Convert a point from the robot frame to the world frame when the robot faces along an axis.
- Use the general formula with a calculator for any heading.
The idea
A frame (short for coordinate frame) is an origin together with a set of axes: a place to measure from and directions to measure along. The lesson Units, Position and Coordinates set one up in the corner of the workshop. There is nothing special about that corner. You can set up a frame anywhere, and robots use at least two.
| World frame | Robot frame | |
|---|---|---|
| Origin | A fixed point in the room, such as a corner | The centre of the robot |
| Axes | x and y along the walls | forward (out of the robot's nose) and left |
| Does it move? | Never | It travels and turns with the robot |
| What is naturally described in it | Walls, shelves, the goal, the map, the robot's pose | Everything the robot's own sensors measure |
The robot frame is like saying "the shop is 50 m ahead on my left". The world frame is like giving a street address. Both are correct. The first changes with every step you take, and the second never does.
Sensors answer in the robot frame. Maps and goals live in the world frame. The robot's pose is the translation between them.
That last sentence deserves a second look. The pose (x, y, θ) says where the robot frame sits inside the world frame: its origin is at (x, y), and its forward axis points along θ. So the pose is exactly the information needed to convert.
Converting when the robot faces along an axis
When the heading is 0°, 90°, 180° or −90°, you can convert by looking. Work out which world direction "forward" is, which world direction "left" is, and add.
| Heading | "Forward" is along | "Left" is along |
|---|---|---|
| 0° | +x | +y |
| 90° | +y | −x |
| 180° | −x | −y |
| −90° | −y | +x |
Converting for any heading
For other headings the forward and left distances are each shared between x and y, with the cosine and sine you met in the last lesson. Call the reading (f, l) for forward and left, and the robot's pose (x, y, θ):
Start at the robot. Add the forward distance along the heading, then the left distance at a right angle to it.
world x = x + f × cos θ − l × sin θ
world y = y + f × sin θ + l × cos θ
You do not need to memorise this. Know that it exists, that it needs the pose, and check it against a drawing whenever you use it.
Look at what the formula needs: the robot's pose. If Pip's belief about its own pose is wrong, every object it sees is placed in the wrong spot of the world. That single fact drives modules 6 and 7.
There are more frames than two
A real robot has a frame for each sensor too: a camera mounted 10 cm ahead of the centre and tilted downward measures from where it sits, not from the robot's centre. The principle is the same every time: know where one frame sits in another, and convert. For this course, two frames are enough.
Words to know
- Frame (coordinate frame)
- An origin and a set of axes to measure from. On Pip: the corner of the workshop with x and y along the walls.
- World frame
- A frame fixed to the surroundings. Also called the map frame. On Pip: the shelf is at (4, 5) and stays there.
- Robot frame
- A frame fixed to the robot, with axes pointing forward and left. Also called the body frame or base frame. On Pip: the box is 2 m forward and 1 m left.
- Transform
- The conversion of coordinates from one frame to another. On Pip: turning a scanner reading into a spot on the map.
- Relative and absolute
- Relative: measured from the robot. Absolute: measured from the fixed world origin. On Pip: "0.4 m ahead" is relative. "(3, 1.4)" is absolute.
A worked example: where is the box in the room?
Pip is at the pose (3, 1, 90°). Its scanner reports a box 2 m forward and 1 m to the left.
By looking. At 90° Pip faces along +y, so "forward" is +y and "left" is −x.
- Start at Pip: (3, 1).
- 2 m forward is 2 m along +y: (3, 3).
- 1 m left is 1 m along −x: (2, 3).
The box is at (2, 3) in the world frame, as in the figure.
By formula, to check. cos 90° = 0 and sin 90° = 1.
- world x = 3 + 2 × 0 − 1 × 1 = 2
- world y = 1 + 2 × 1 + 1 × 0 = 3
The two methods agree.
A heading that is not along an axis. Pip is at (1, 2, 30°) and sees a box 2 m forward and 0.5 m left. With cos 30° = 0.866 and sin 30° = 0.5:
- world x = 1 + 2 × 0.866 − 0.5 × 0.5 = 2.48
- world y = 2 + 2 × 0.5 + 0.5 × 0.866 = 3.43
Check with a rough sketch: from (1, 2), mostly to the right and somewhat up. (2.48, 3.43) fits.
Try it yourself
A robot is at (4, 4) facing 180° (along −x). It sees a cone 3 m forward and 1 m to its right. Where is the cone in the world frame? Draw it first, then compute. (A point to the right has a negative "left" distance.)
Answer
At 180°, forward is −x and left is −y, so right is +y. Start at (4, 4). 3 m forward: (1, 4). 1 m right: (1, 5). By formula with l = −1, cos 180° = −1, sin 180° = 0: world x = 4 + 3 × (−1) − (−1) × 0 = 1, world y = 4 + 3 × 0 + (−1) × (−1) = 5. The cone is at (1, 5).
Common mistakes
"The sensor said the wall is at (2, 0), so I marked (2, 0) on the map."
The reading is in the robot frame. Marking it on the map without converting puts every wall in the wrong place, and differently wrong each time the robot moves. Convert with the pose first.
"The goal is 3 m ahead, so I will store that."
"Ahead" changes as soon as the robot turns. Store goals and anything else that should stay put in the world frame, and convert to the robot frame only at the moment you need to steer.
"Left is always +y."
Only when the robot faces 0°. Left is a direction of the robot. Which way that is in the room depends on the heading.
Remember this
- A frame is an origin plus axes. The world frame is fixed to the room. The robot frame rides on the robot, with axes forward and left.
- Sensor readings arrive in the robot frame. Maps, goals and the pose are in the world frame.
- The pose converts between them: world x = x + f cos θ − l sin θ, world y = y + f sin θ + l cos θ.
- Every number that describes a place should come with its frame.
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 at (1, 1) facing 0° sees a door 4 m forward and 2 m left. Where is the door in the world frame?
Explanation
At 0°, forward is +x and left is +y. The door is at (1 + 4, 1 + 2) = (5, 3).
Question 2
A robot sees a chair 1 m straight ahead. It then turns 90° to the left without moving. Where is the chair now in the robot frame, and has its world position changed?
Explanation
After a left turn, the chair that was ahead is now on the robot's right: 0 m forward and 1 m to the right (a left distance of −1). Its world position has not changed at all. Only the robot frame turned.
Question 3
A robot believes it is at (2, 2) facing 0°, but it is really at (2, 2) facing 90°. It sees a wall 3 m ahead and marks it on its map. Where does it mark the wall, and where is the wall really?
Explanation
It marks the wall at (2 + 3, 2) = (5, 2). The wall is really at (2, 2 + 3) = (2, 5). An error in the pose, here in the heading alone, put the wall more than 4 m from its true place. Maps are only as good as the pose used to draw them.
What’s next
That completes the toolkit: units, position, heading, pose, time steps and frames. In everything so far, Pip went exactly where the numbers said. Module 3 looks at the motors and wheels that have to make it true, and at what happens when they do not.
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.
- LaterVectors and Coordinates
Positions as vectors, with the algebra.
- LaterCoordinate Frames
Frames done properly, in two and three dimensions.