Robot Foundations · Module 5: Reaching a Goal
Following a Path
Aim at a point a little further along the path, steer toward it with the feedback of module 3, and repeat. How far ahead you aim decides how the robot takes corners.
A path is a list of corner points, and a corner is a place where a robot with momentum and a limited turning rate has to start turning before it gets there. A controller that steers at "the next waypoint" overshoots every corner, then oscillates back. A controller that steers at the goal ignores the path altogether. The method most robots use sits between the two: aim at a point that travels ahead of the robot along the path, like a carrot on a stick held in front of a donkey.
What you will be able to do
- Turn the cells of a grid path into waypoints in metres.
- Explain the look-ahead (carrot) method for path following.
- Compute the turning command for one step of path following.
- Say what happens when the look-ahead is too short or too long.
The idea
From cells to waypoints
The wave method of the last lesson gives a chain of cells. The controller needs positions in metres, so each cell becomes the position of its centre. With 0.5 m cells, the cell in row r and column c has its centre at x = (c + ½) × 0.5 m. A path of 14 steps visits 15 cells, so it gives 15 waypoints about half a metre apart. Neighbouring waypoints in a straight run lie on one line, so planners usually drop the middle ones and keep only the corners.
The carrot
Following a path means staying close to it while moving along it. Do it in three steps on every pass of the loop.
- Where am I along the path? Find the point on the path nearest to the robot. Call its distance from the start of the path s.
- Where is the carrot? Go a fixed extra distance L further along the path, to the point at distance s + L. That is the target. The fixed distance L is the look-ahead.
- Steer toward the carrot. This is exactly the feedback of module 3, aimed at the carrot instead of the goal: heading error = direction to the carrot minus the robot's heading, and ω = gain × heading error. Keep a steady forward speed v.
The turning speed is a gain times the angle between where the robot points and where the carrot is.
ω = gain × (direction to the carrot − heading)
The same rule as in the lesson on feedback. Keep the heading difference between −180° and +180° so the robot turns the short way.
Because the carrot is always ahead, it moves forward as the robot does, and the robot never reaches it. It reaches the goal because the carrot stops at the end of the path.
How far ahead to look
The look-ahead L is the one number that matters most, and it pulls two ways.
- Too short: the carrot is almost under the robot's nose. Small sideways errors look like big angles, so the robot twitches and weaves.
- Too long: the robot aims far down the path, so as it nears a corner the carrot is already round it, and the robot starts to turn early and cuts the corner. In open space that is smooth and fast. Beside a wall it is a collision.
| Look-ahead L | Furthest from the path | Time to the goal |
|---|---|---|
| 0.2 m | 15 cm | 12 s |
| 0.5 m | 9 cm | 11.7 s |
| 1 m | 24 cm | 11.1 s |
| 1.5 m | 39 cm | 10.6 s |
| 3 m | 87 cm | 9.2 s |
The table shows the trade. Both the very short and the long look-ahead stray further than the middle value: the short one weaves, the long one cuts corners. The long one arrives sooner, because it takes a shorter route. The right value depends on how much room the corners leave. The lab lets you tune it with a slider from 0.2 to 3 m.
Look-ahead is a dial between "tight and twitchy" and "smooth and corner-cutting". Set it from the clearance you need.
The speed matters too. At 0.5 m/s a corner is easy. At 2 m/s the same robot would run wide, because it moves further while it turns. A robot that must stay tight slows down for corners.
Words to know
- Waypoint
- One point of a path, with a position in metres. On Pip: the centre of a grid cell on the path, or a corner.
- Look-ahead (L)
- How far ahead on the path the carrot is. On Pip: a slider from 0.2 to 3 m in the lab.
- Carrot (target point)
- The point on the path that the robot steers toward. On Pip: always ahead of it, until the end of the path.
- Path following
- Steering so that the robot stays close to a path while moving along it. On Pip: the controller's whole job once the planner has finished.
- Heading error
- The direction to the target minus the robot's heading. On Pip: -11.3° in the first worked example.
- Cross-track error
- How far the robot is to the side of the path. On Pip: 20 cm in the first worked example.
- Cutting a corner
- Taking a route inside a turn of the path because the target is already beyond it. On Pip: a long look-ahead does this.
A worked example: one step of path following
The path has corners at (1, 1), (4, 1) and (4, 4), 6 m long. The gain is 2 and the look-ahead is 1 m. Pip is at (2, 1.2) facing 0°.
- Where am I? The nearest point on the path is (2, 1), 0.2 m below the robot, 1 m from the start of the path. So s = 1 and the robot is 20 cm to the side of the path.
- Where is the carrot? s + L = 2 m along the path: the point (3, 1).
- Direction to the carrot. It is 1 m ahead and -0.2 m to the side, so the direction is -11.3°. The heading error is -11.3° − 0° = -11.3°, which is -0.197 rad.
- Turning command. ω = 2 × -0.197 = -0.39 rad/s. Negative: turn right, back toward the path, which is where the robot should go, since it is above it.
Near the corner. Now Pip is at (3.6, 1) on the path, facing 0°, 0.4 m before the corner. With L = 0.3 m the carrot is at (3.9, 1), straight ahead. The heading error is 0°, so ω = 0 rad/s: no turn yet. With L = 1.0 m the carrot is already round the corner at (4, 1.6). The heading error is 56° and ω = 1.97 rad/s, which starts a turn while the robot is still 0.4 m from the corner. That is the corner being cut.
Try it yourself
Lay a long piece of string on the floor in an L shape. Walk along it, but with a rule: always look at a spot on the string a certain distance ahead of your feet, and walk toward that spot, not toward your feet. (a) Try looking just a step ahead. (b) Try looking five metres ahead. (c) Which one stays on the string at the corner, and which is smoother?
What to expect
(a) Looking one step ahead, you correct constantly and your walk is a little jerky, but you stay on the string. (b) Looking five metres ahead, you turn well before the corner and walk across the inside of it, off the string. (c) The short look keeps you on the line and is jerky. The long look is smooth and cuts the corner. A robot has the same choice, which is why the dial matters.
Common mistakes
"The robot should steer at the next waypoint."
It then arrives at each corner pointing the wrong way and has to swing round. A carrot moving ahead of the robot lets it start the turn early, and no waypoint ever has to be reached exactly.
"A longer look-ahead is always smoother, so use a large one."
Smoother, yes, and it cuts corners. Next to a wall that is a collision. Pick the look-ahead from how much room the corner has, and slow down for tight ones.
"Heading error can be computed by simple subtraction."
Not near ±180°. A robot at 170° with a carrot at −170° is 20° off, and plain subtraction says 340°, which sends it spinning the long way. Wrap the difference into −180° to +180° first.
Remember this
- Path following steers at a carrot: the point on the path a distance L ahead of the robot.
- The steering rule is the proportional feedback of module 3, aimed at the carrot.
- Short look-ahead stays close to the path and weaves. Long look-ahead is smooth and cuts corners.
- Wrap the heading error and slow down for tight corners.
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, 0.5) facing 0° on a path along y = 0 that runs through x from 0 to 10. The look-ahead is 1 m. Where is the carrot, and does the robot turn left or right?
Explanation
The nearest point on the path is (2, 0), so the carrot is 1 m further along: (3, 0). The robot is above the path and facing along it, so the carrot is ahead and below: the direction is about −26.6°, a heading error of −26.6°, which is a right turn, back toward the path.
Question 2
A delivery robot cuts corners and clips a pillar. Give two changes that would help.
Explanation
Shorten the look-ahead, so the carrot does not get round the corner before the robot does. Slow down for corners, so that the robot covers less ground while it turns. Making the planner keep a bigger margin from the pillar also helps, whatever the controller does.
Question 3
Why does the robot never "catch" its carrot, and why does it still reach the goal?
Explanation
The carrot is always a distance L ahead of the robot along the path, so it moves away as the robot moves. It stops only at the end of the path, where it cannot go further than the goal. When the robot is within L of the goal, the carrot is the goal itself, and the robot steers to it and arrives.
What’s next
Plan, follow: the robot can now reach a goal in a room it has fully mapped. The world is rarely so cooperative. The last lesson of this module is about what happens when it changes.
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.
- LaterNavigation
Sixty lessons on planning and driving, from costmaps to fleets.
- LaterA* Search with a Heuristic
The grid search of this module, made fast.