Robot Foundations · Module 2: Describing a Robot with Numbers
Angles, Heading and Pose
Which way is the robot facing? One angle. Position and heading together are called the pose.
Two robots stand on the same spot. One faces the shelf and the other faces the wall. They are at the same position, and yet the command "drive forward one metre" sends them to different places. To predict what a robot will do, the position is not enough. You also need the direction it faces, and that takes exactly one more number.
What you will be able to do
- Describe a heading as an angle measured from the x axis.
- Say which direction of turning is positive.
- Convert an angle between degrees and radians.
- Write a pose as (x, y, θ) and explain why all three numbers are needed.
The idea
The heading of a robot is the direction its front points in. It is written as an angle, and by long-standing agreement the symbol for it is the Greek letter θ (theta).
An angle needs a starting line and a direction of turning, in the same way that a position needed an origin and axes. The agreement used across robotics is:
- θ = 0 means facing along the x axis (to the right on the page).
- Turning to the left, counter-clockwise, makes θ larger. Turning to the right makes it smaller.
Pose: position and heading together
Put the three numbers side by side and you have the robot's pose: (x, y, θ). It is the complete answer to "where is the robot?" for a robot on a flat floor.
Pose = position + heading = (x, y, θ). Three numbers pin down a robot on a floor.
Degrees and radians
You know degrees: a full turn is 360°. Programs and formulas in robotics use another unit, the radian (rad). The idea is simple. Walk around the edge of a circle whose radius is 1 m. The distance you have walked, in metres, is the angle you have turned through, in radians. A full lap of that circle is 2 × π ≈ 6.28 m, so a full turn is 6.28 rad. (π, "pi", is the number 3.14159…)
Half a turn is 180 degrees, which is π radians. So multiply degrees by π ÷ 180 to get radians.
radians = degrees × π ÷ 180
One radian is 180 ÷ π ≈ 57.3°: a bit less than a sixth of a full turn.
| Degrees | Radians | What it looks like |
|---|---|---|
| 0° | 0 | Along the x axis |
| 30° | 0.52 | A gentle left |
| 45° | 0.79 | Half way between x and y |
| 90° | 1.57 | Along the y axis: a quarter turn to the left |
| 180° | 3.14 | Backwards: a half turn |
| -90° | -1.57 | A quarter turn to the right |
| 360° | 6.28 | A full turn: facing the same way as 0° |
Why bother with a second unit? Because with radians, the distance a wheel rolls is simply its radius times the angle it turned, with no extra factor. You will use that in module 3. In this course, angles are shown in degrees when they are for you to picture and in radians when they go into a formula, and the unit is always written.
The same direction has many names
Turn a full circle and you face the same way: 0°, 360° and 720° are one heading. So are −90° and 270°. Programs keep headings in one agreed range, usually from −180° to +180°, and bring any angle back into it by adding or subtracting 360°. This is called wrapping the angle.
Forgetting to wrap is a classic beginner bug. A robot facing 170° that should face −170° is only 20° away from it, across the 180° line. A program that subtracts the raw numbers gets 340° and makes the robot spin almost a full turn the long way round.
Words to know
- Heading (θ, "theta")
- The direction the robot faces, as an angle from the x axis. Also called orientation or yaw. On Pip: 60° in the figure.
- Counter-clockwise
- The direction of a left turn seen from above. It is the positive direction for angles. On Pip: turning left increases θ.
- Degree (°)
- A unit of angle: 360 in a full turn. On Pip: a quarter turn left is +90°.
- Radian (rad)
- A unit of angle: 2π ≈ 6.28 in a full turn. Used in formulas and programs. On Pip: 60° is 1.05 rad.
- Pose
- Position and heading together: (x, y, θ). On Pip: (3 m, 2 m, 60°).
- Wrapping
- Adding or subtracting a full turn so that an angle falls in an agreed range. On Pip: 270° is stored as −90°.
A worked example: converting and wrapping
Convert 60° to radians.
- Multiply by π: 60 × 3.1416 = 188.5.
- Divide by 180: 188.5 ÷ 180 = 1.05 rad.
- Check: 60° is a third of 180°, so the answer should be a third of π, about 1.05. It is.
Pip faces 150° and turns left by another 80°. What is its heading?
- Add: 150 + 80 = 230°.
- 230° is outside the range −180° to +180°, so subtract a full turn: 230 − 360 = −130°.
- Check with a picture: 230° counter-clockwise from the x axis ends in the lower-left quarter. So does 130° clockwise. Same direction.
How far must Pip turn to go from 170° to −170°? Subtract: −170 − 170 = −340°. Wrap it: −340 + 360 = +20°. The answer is a small left turn of 20°, not a right turn of 340°.
Try it yourself
Stand up and face a wall: call that direction the x axis, θ = 0°. (a) Turn to face 90°. Which way did you turn? (b) From there, turn to −90° by the shortest way. How many degrees did you turn, and which way? (c) Write 45° in radians.
Answer
(a) A quarter turn to your left. (b) 180°, a half turn. Left or right are equally short here: the difference is −90 − 90 = −180°, which is exactly on the boundary. (c) 45 × π ÷ 180 = π ÷ 4 ≈ 0.79 rad.
Common mistakes
"Heading is measured from north, clockwise, like a compass."
That is how ships and hikers do it. Robotics measures from the x axis, counter-clockwise. Mixing the two turns left into right. Always check which one a tool or a data file uses.
"I gave the function 90 and the robot went somewhere strange."
Nearly every programming language expects radians in its sine and cosine functions. 90 radians is more than 14 full turns plus a bit. Convert first: 90° is about 1.57 rad.
"Position is enough to say where a robot is."
Two robots at one position with different headings will go to different places on the same command. The heading is part of where the robot is.
Remember this
- Heading θ is the angle from the x axis to the direction the robot faces. Left turns are positive.
- radians = degrees × π ÷ 180. A full turn is 360° or about 6.28 rad.
- Pose = (x, y, θ): three numbers describe a robot on a floor.
- Angles repeat every full turn, so wrap them into one range before comparing them.
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 (2, 2) faces θ = 180°. It drives forward 1 m. Where is it, and what is its heading?
Explanation
Facing 180° means facing along −x. Driving forward 1 m takes it to (1, 2). Its heading is unchanged: 180°. Position and heading are separate numbers, and driving straight changes only the position.
Question 2
Convert 270° to radians, then give the same heading as an angle between −180° and +180°.
Explanation
270 × π ÷ 180 = 1.5 × π ≈ 4.71 rad. Wrapped: 270 − 360 = −90°, which is about −1.57 rad. Both describe "facing along −y".
Question 3
A robot faces −160° and needs to face 170°. A program computes 170 − (−160) = 330° and turns left by 330°. What should it have done?
Explanation
It should have wrapped the difference: 330 − 360 = −30°. The shortest way is a right turn of 30°. The robot ends up facing the correct direction either way, but it wasted most of a full turn, and on a real robot that costs time and adds error.
What’s next
A pose is a snapshot: where Pip is at one instant. The next lesson adds time, and with it, motion.
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.