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

Robot Foundations · Module 2: Describing a Robot with Numbers

Units, Position and Coordinates

Where is the robot? Two numbers, in metres, measured from a corner you agree on.

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

"Pip is over by the window, a bit to the left" is fine between people. A program cannot use it. A program needs numbers, and the numbers need two agreements before they mean anything: what unit they are in, and where they are measured from. This lesson makes both agreements and uses them to write down where Pip is.

What you will be able to do

  • Name the units robotics uses for length, time and speed.
  • Write the position of a point on a floor as (x, y).
  • Explain what the origin and the axes are, and why they must be agreed first.
  • Find the distance between two positions.

The idea

First agreement: units

Robotics uses the metric system, and nearly always these base units. Stick to them and whole families of mistakes never happen.

The units used in this course
QuantityUnitSymbolA feel for the size
Length, distance, positionmetremA long stride. A door is about 2 m high.
TimesecondsOne heartbeat, roughly.
Speedmetres per secondm/s1 m/s is a slow walk. 1.4 m/s is a normal walk.

Small lengths are still written in metres: Pip's wheels are 0.1 m across, which is 10 cm. A program that mixes centimetres with metres will be wrong by a factor of 100, and nothing in the program will complain. Convert once, at the edge, and use metres inside.

Second agreement: where to measure from

Picture the workshop floor from above, like a sheet of squared paper. Choose one corner and call it the origin. Draw one line from it along a wall and call it the x axis. Draw another line from it along the other wall, at a right angle, and call it the y axis.

Now any spot on the floor has an address of two numbers:

  • x: how far to go from the origin along the x axis,
  • y: then how far to go in the y direction.

The pair is written (x, y), always x first. These two numbers are the coordinates of the spot, and together they are a position.

The workshop floor from above with a grid in metresA six by six metre floor drawn as a grid. The origin is the bottom-left corner. The x axis runs to the right and the y axis runs up. Pip is at x = 1, y = 1. Shelf B is at x = 4, y = 5. A dashed line of 3 metres along x and a dashed line of 4 metres along y join them, and a straight line of 5 metres connects them directly.01234560123456x (m)y (m) 3 m along x 4 m along y 5 m Shelf B (4, 5) Pip (1, 1) origin (0, 0)
The workshop from above. Each square is 1 m. Pip is at (1, 1): 1 m along x and 1 m along y. Shelf B is at (4, 5).

Two things in that picture are choices, and robotics makes them the same way almost everywhere: x points to the right and y points up the page, as in school graphs. A position can also be negative. A spot 1 m to the left of the origin has x = −1.

A position means nothing until you know its unit and its origin. (4, 5) in metres from the south-west corner is a place. (4, 5) alone is two numbers.

How far apart are two positions?

To get from Pip to shelf B you could go 3 m along x and then 4 m along y. The straight line is shorter. The two legs and the straight line form a triangle with a right angle, and for such a triangle there is an old rule (Pythagoras' theorem): square the two legs, add them, and take the square root.

The distance between two positions is the square root of (the difference in x, squared, plus the difference in y, squared).

distance = √( (x₂ − x₁)² + (y₂ − y₁)² )

Squaring a number means multiplying it by itself. The square root, written √, undoes that: √25 = 5 because 5 × 5 = 25. Every calculator and programming language has it.

You will use this one formula constantly: distance to the goal, distance to an obstacle, how far off a path the robot is. It is the most used piece of mathematics in mobile robotics.

Words to know

Metre (m)
The unit of length. On Pip: its wheels are 0.3 m apart.
Origin
The agreed point where x = 0 and y = 0. Everything is measured from it. On Pip: the south-west corner of the workshop.
Axis (plural: axes)
A straight reference line through the origin. Two axes at right angles cover a floor. On Pip: x runs along the south wall, y along the west wall.
Coordinates
The numbers (x, y) that say where a point is. On Pip: (1, 1) at the start of this lesson.
Position
Where something is, given as coordinates. On Pip: (1, 1), in metres.
Distance
The length of the straight line between two positions. It is never negative. On Pip: 5 m to shelf B.

A worked example: how far is Pip from the shelf?

Pip is at (1, 1) and shelf B is at (4, 5), both in metres.

  1. Difference in x. 4 − 1 = 3 m.
  2. Difference in y. 5 − 1 = 4 m.
  3. Square each. 3 × 3 = 9, and 4 × 4 = 16.
  4. Add. 9 + 16 = 25.
  5. Square root. √25 = 5.

The shelf is 5 m away in a straight line. Going along the two legs instead would be 3 + 4 = 7 m. Check the answer against the figure: the straight line crosses about five squares' worth of floor, so 5 m is believable. Get into the habit of that check. A result of 50 or 0.5 would mean a slip somewhere.

The order of the two points does not matter. Starting from the shelf, the differences are −3 and −4, and squaring removes the minus signs: (−3) × (−3) = 9.

Try it yourself

On squared paper, draw a floor 6 squares by 6 and mark the origin at the bottom left. Mark a charger at (5, 1) and a door at (2, 5). (a) How far apart are they? (b) Pip is at (2, 1). Which is closer, the charger or the door?

Answer

(a) Differences: 5 − 2 = 3 and 1 − 5 = −4. Squares: 9 and 16. Sum: 25. Distance: √25 = 5 m. (b) To the charger: the difference is 3 in x and 0 in y, so 3 m. To the door: 0 in x and 4 in y, so 4 m. The charger is closer.

Common mistakes

"I will write (y, x), it is the same thing."

It is a different place. (1, 4) and (4, 1) are on opposite sides of the room. The order is always x first.

"Distance is the difference in x plus the difference in y."

That is the length of the trip along the two legs, which is longer unless you travel straight along an axis. The straight-line distance needs the squares and the square root.

"Units are obvious, I do not need to state them."

A length of 30 could be centimetres, millimetres or inches. A Mars probe was lost in 1999 because two teams used different units for the same number. Write the unit, and keep everything in metres and seconds inside a program.

Remember this

  1. Use metres, seconds and metres per second.
  2. A position on a floor is (x, y): x first, measured from an agreed origin along agreed axes.
  3. Distance = √( difference in x, squared, plus difference in y, squared ).
  4. Always check a computed number against a rough picture.

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 is at (2, 3) and its goal is at (8, 11), in metres. How far is the goal?

Explanation

Differences: 8 − 2 = 6 and 11 − 3 = 8. Squares: 36 and 64. Sum: 100. Distance = √100 = 10 m.

Question 2

Two engineers measure the same robot. One says it is at (3, 2), the other says (−1, 0). Both are right. How?

Explanation

They are using different origins (or axes pointing in different directions). A position only has meaning together with the origin and axes it is measured in. This is why every team must agree on them, and it is the subject of the last lesson of this module.

Question 3

A program receives a wall distance of 150 from a sensor and treats it as metres. The sensor reports centimetres. What does the robot believe, and what is true?

Explanation

It believes the wall is 150 m away. In truth it is 1.5 m away. The program is wrong by a factor of 100 and will not slow down. Converting to metres at the point where the reading enters the program prevents this.

What’s next

A position says where Pip is. It does not say which way Pip is pointing, and a robot that can only drive forward needs to know that just as badly.

Next lesson

Angles, Heading and Pose

Describe which way a robot faces with one angle, convert between degrees and radians, and write a pose as x, y and heading.

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.