Skip to the lesson
FixTheRobot Explore Robotics / Robot Foundations / Module 5 / Lesson 4

Robot Foundations · Module 5: Reaching a Goal

When the World Changes: Obstacles and Replanning

A plan is a guess made from the map the robot had when it made it. When the map changes, the plan has to be made again.

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

Pip has a perfect plan, and it is half way along it when a pallet it had never seen turns out to be standing in the one gap it was heading for. The plan is not wrong because the planner was careless. It was the best answer to the map at that moment, and the map was incomplete. What matters is what Pip does next. A robot that keeps following a stale plan hits the pallet. A robot that notices, updates its map and plans again drives round it. This lesson is about that habit.

What you will be able to do

  • Give three reasons a plan goes stale.
  • Describe the loop that keeps a plan current: sense, update the map, plan again.
  • Say why a planner treats unknown space as free, and what that costs.
  • Choose how often to replan, and say what a robot should do when no path remains.

The idea

A plan was made from a map, a start and a goal. If any of the three changes, the plan may no longer be a good one. In practice the map is the usual culprit, for three reasons.

  • The robot had not seen everything. A map built from the doorway is empty behind the door. Things only appear when the robot gets there.
  • The world moved. A person walks through the planned route. A pallet is pushed into the corridor.
  • The map was wrong. A door that was marked open is closed. A wall was drawn a little off.

The robot is also not always where it thinks it is. Module 7 comes to that: a plan made from a wrong position is as stale as one made from a wrong map.

Optimism: unknown space is free

What should the planner assume about cells the robot has not seen? Two choices exist. If it assumes unknown cells are blocked, it will never plan through anything unexplored, and the robot cannot get anywhere new. If it assumes they are free, it plans boldly through the unknown, and sometimes finds out it was wrong. The lab's planner takes the second choice, and so do most real ones: assume the way is clear until you see otherwise. The price is the replanning in this lesson.

The loop that keeps a plan current

  1. Sense. The scanner reports what is around the robot.
  2. Update the map. Cells the beams passed through are marked free. Cells where a beam stopped are marked blocked.
  3. Check the plan. Is the path still free? Is there now a shorter one?
  4. Plan again if needed, from where the robot is now, to the same goal.
  5. Keep driving. The controller always follows the newest plan.
A plan before and after a hidden block is discoveredTwo copies of the same nine by six grid. In the left copy, labelled plan made at the start, a green path goes from the start up the left side, along the third row, through a gap and down to the goal. A cell in the gap is marked with a question mark: a block nobody knew about. In the right copy, labelled replan after the block is seen, the cell is a wall, the robot stands in the third row, and a new green path goes back left, up and over the top and down the right side to the goal.Plan made at the startSG?Replan after the block is seenGrobot
Left: the first plan assumes the gap is open and is 14 steps. The orange cell marked ? is a block that is not on the map. Right: the robot has reached the third row and seen the block. The same wave method, started from the robot's cell, gives a 20-step route over the top.

Replanning is not a failure of the plan. It is how a plan stays honest about a world it only partly knows.

How often should the robot replan?

Planning is cheap on a small grid and costly on a big map, and the world changes at its own speed. There are costs on both sides.

The trade-off in how often a robot replans
If it replansThe goodThe bad
Too rarely (every ten seconds, say)Little computingIt may drive on towards an obstacle for a long time before it reacts.
About once a second (the lab's choice)Reacts to new obstacles before it reaches them at walking speedsUses some computing every second.
On every loop pass (20 times a second)Reacts at onceWastes most of its work, and the path can flip between two equally good routes, so that the robot dithers.

Many robots replan when something happens: when a newly seen obstacle touches the current path, or when the robot has drifted too far from it. It is the cheapest rule and avoids most of the dithering.

When no path is left

Sometimes the new map has no way through. The wave method finds this out without help: it runs out of wave before reaching the goal. The robot must then do something sensible. It can stop, it can wait and look again, since people move on, or it can report to whoever sent it that the goal is unreachable. What it must not do is keep driving along the old plan.

Replanning is also what makes lab 3 work: the robot starts with a map that has not been explored, assumes the unknown is free, and corrects its plan as the scanner uncovers walls.

Words to know

Stale plan
A plan made from a map that no longer matches the world. On Pip: the route through the gap, after the gap closed.
Replanning
Making a new plan from the robot's current position to the same goal. On Pip: every second in the lab.
Map update
Changing cells of the map from the newest sensor readings. On Pip: the scanner marks the gap cell as blocked.
Free-space assumption
Treating cells not yet seen as free, so that the planner will plan through them. On Pip: the lab's planner does it.
Dithering
Flipping back and forth between two nearly equal plans, so that the robot barely moves. On Pip: what happens if it replans too often with no tie-break rule.
Unreachable goal
A goal for which no path exists on the current map. On Pip: the wave runs out before it labels the goal.

A worked example: the cost of a surprise

The grid is the one from the last lesson, with 0.5 m cells. Pip's first plan has 14 steps, which is 7 m, and goes through the gap at row 4, column 7. Nobody has told the robot that a pallet stands in that cell.

  1. Driving. Pip follows the plan. After 8 steps (4 m) it is at the cell in row 3, column 6, next to the gap, and the scanner sees the pallet.
  2. The map changes. The cell at row 4, column 7 becomes blocked. The path ahead now goes through a wall: the plan is stale.
  3. The old plan. It had 6 steps left. It would end at the pallet.
  4. Replanning. The wave method runs again from the robot's cell. The shortest way round is now 20 steps, 10 m: back along the third row, up the left side, over the top and down the right side.
  5. The price. The robot drove 4 m, learned about the pallet, and now has 10 m to go. The whole trip is 14 m, against the 7 m it hoped for: 7 m extra, which is the cost of not knowing.

If the other gap closes too. Suppose, on top of that, a second obstacle also blocks the right-hand corridor at row 3. The wave starts from the robot, labels 29 cells, and never reaches the goal: no path. The robot has found out that the goal is, for now, unreachable.

Try it yourself

Walk through your home from the front door to the kitchen, planning the route in your head as you go. Now imagine a chair has been left in the hallway. (a) At what point do you notice it? (b) What do you do? (c) Which of the five steps of the loop (sense, update the map, check the plan, plan again, keep driving) did you do, probably without noticing?

What to expect

(a) As soon as it comes into view, which depends on lighting and corners: you cannot react to what you cannot see. (b) Walk round it, or choose another route through another room if the hallway is blocked. (c) All five: you saw it (sense), you now know the hall is not clear (update the map), you saw that your route went through it (check), you picked a route around (plan again) and you walked it (keep driving). People replan constantly. The robot has to be told to.

Common mistakes

"A good enough plan never needs changing."

The plan is only as good as its map. Every real map is incomplete when the robot sets out, so every plan is provisional.

"If the plan fails, the robot should stop and ask for help."

It should replan first, which usually works, and ask for help only when the wave runs out and no path remains.

"Replan as often as possible to be safe."

The planner burns time, and replanning every pass can make the robot switch between two equal routes without getting anywhere. Replan when the plan is actually in trouble, or on a steady timer of about a second.

Remember this

  1. Plans go stale because the map was incomplete, the world moved, or the map was wrong.
  2. The loop is: sense, update the map, check the plan, plan again if needed, keep driving.
  3. Planners treat unknown space as free, which is bold and means occasional replanning.
  4. If the wave runs out, the goal is unreachable: stop, wait and look again, or report it.

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 assumes unknown cells are blocked and plans only through cells it has seen. What goes wrong?

Explanation

It can never plan a route into the unexplored, so it cannot go anywhere new: it is stuck inside the area it has already seen. Treating unknown space as free lets it plan boldly and correct as it learns.

Question 2

After a scan, the robot's current path still passes through only free cells. Does it need to replan?

Explanation

Not necessarily. If the path is free, it can keep following it. It may still replan if a shorter route has opened up, but if the plan is still safe and about as short as it can be, replanning wastes effort. Checking the plan against the new map is cheap, and the full planning step only needs to run if it fails the check.

Question 3

A robot replans on every pass of a 20 Hz loop and keeps turning left, then right, then left, without getting anywhere. What is likely wrong?

Explanation

Dithering: two routes of nearly equal length are trading places as small changes in the map or in the robot's position tip the balance. Replanning only when needed, or sticking to the current plan unless the new one is clearly better, fixes it.

What’s next

That completes the robot's ability to reach a goal, with a map it was given. Lab 3 puts it all together: plan, follow and replan on a map that starts out unknown. After the lab, module 6 asks where that map comes from.

Next lesson

What Is a Map?

Explain what a robot needs a map for, and compare a grid map, a landmark map and a map of connected places.

The lab of this module (after lesson 3)

Make the Robot Reach the Goal

Driving straight at the goal fails. Build the world model, plan a path and follow it to reach the goal. About 20–30 minutes.

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.