Skip to the lesson
FixTheRobot Explore Robotics / Robot Foundations / Module 8 / Lesson 3

Robot Foundations · Module 8: The Robot as a System, and Your Next Step

When Things Go Wrong: Failing Safely

Assume something will go wrong, and decide in advance what the robot does when it does. The safest default is to stop.

  • Lesson 3 of 4
  • Beginner
  • No code
  • About 10 minutes

A robot that works is a robot that has not yet met a bad day. A cable works loose. A wheel catches on a threshold. The scanner program crashes and stops sending scans, while the rest of the software happily goes on using the last one. The question is never whether such things happen but what the robot does when they do. The answers are not clever. They are a handful of simple rules, written down in advance, that turn a surprise into a stop.

What you will be able to do

  • Name common ways a robot fails, and the sign each one gives.
  • Describe the simple defences: limits, timeouts, sanity checks and a stop that always works.
  • Compute a stopping distance and see why speed matters so much.
  • Explain why the safe default is to stop.

The idea

Common failures, and how a robot can notice

A robot cannot see a broken part directly. It sees symptoms in its own data, and the defences are rules that watch for them.

Common robot failures, the sign each gives and a simple defence
What goes wrongThe sign in the dataThe defence
A sensor program crashes or a cable comes looseNo new messages for longer than the sensor's usual intervalA timeout: if nothing fresh arrives in time, stop.
A wheel is stuck or the robot is blockedThe motors are commanded to turn and the encoders show little or no motionCompare what was commanded with what was measured; if they disagree for long, stop and report.
An obstacle appears too close to stop forA scan reading inside the stopping distanceA stop zone: limit the speed by the distance to the nearest obstacle.
A sensor returns nonsenseA value that is not a number, or is far outside the sensor's rangeA sanity check: reject impossible values, and do not act on them.
The robot no longer knows where it isThe estimate has gone a long time without a landmark correctionSlow down or stop, and look for a landmark.
The software freezesThe program stops sending commands, or its heartbeat stopsA watchdog: a separate part that cuts power to the motors if the heartbeat stops.
The battery runs lowThe voltage falls below a set levelHead for the charger early enough, and stop before the battery is flat.

The four simple defences

  • Limits. The software never commands more than a fixed top speed, turning speed or acceleration, whatever the planner or the user asks. Limits stop a bug from becoming a fast bug.
  • Timeouts. Every message the robot depends on has a time it must arrive by. Missing the deadline means the data is stale and the robot must not act on it. Stale data is worse than none, because it looks fine.
  • Sanity checks. Reject values that cannot be true, such as a distance that is negative or not a number.
  • A stop that always works. Software can crash. A real robot has an emergency stop button wired so that it cuts the power to the motors without going through the software, and a watchdog that does the same if the software goes quiet. Neither depends on the part that may have failed.

Decide in advance what the robot does when something is wrong. The default should be the safe action, and the safe action is usually to stop.

Why speed matters so much

A robot cannot stop at once. From the moment something appears there is a delay (the scanner updates, the program thinks, the motors respond) during which the robot keeps going. Then it takes a braking distance to slow down:

Stopping distance is the distance covered during the delay, plus the braking distance.

stopping distance = speed × delay + speed² ÷ (2 × braking)

braking is how hard the robot can slow down, in m/s². The speed is squared: doubling the speed quadruples the braking distance.

For Pip suppose a total delay of 0.2 s and a braking of 0.5 m/s². Both are assumptions for the example, typical of a small indoor robot, not measurements of Pip.

Stopping distance against speedA plot of stopping distance against speed from 0 to 1.5 metres per second. An orange curve, for braking at 0.5 metres per second squared, rises slowly at first then steeply, reaching about 2.55 metres at 1.5 metres per second. A blue curve, for braking at 1 metre per second squared, rises less steeply, reaching about 1.4 metres. A dashed vertical line marks the robot's top speed of 0.5 metres per second.00.250.50.7511.251.500.511.522.53speed (m/s)stopping distance (m) brakes 0.5 m/s²brakes 1.0 m/s² Pip's top speed
The stopping distance grows faster than the speed. The curve bends upward because of the squared term.
The stopping distance for four speeds, with a delay of 0.2 s and braking of 0.5 m/s²
SpeedDistance during the delayBraking distanceStopping distanceCompared with 0.25 m/s
0.25 m/s0.05 m0.06 m0.11 m1 times
0.5 m/s0.1 m0.25 m0.35 m3.1 times
1 m/s0.2 m1 m1.2 m10.7 times
1.5 m/s0.3 m2.25 m2.55 m22.7 times

Four times the speed needs about 11 times the room to stop, since the speed is squared. A robot that drives fast through a crowd is not just four times as dangerous as one that drives slowly, but more.

A speed limit from the distance to the nearest obstacle

Turn the formula round: given how far away the nearest obstacle is, how fast may the robot go and still stop short of it, with a margin of 0.2 m?

The fastest speed that can still stop short of an obstacle at four distances
Nearest obstacleFastest safe speedFor Pip (top speed 0.5 m/s)
0.5 m0.46 m/s0.46 m/s
1 m0.8 m/s0.5 m/s
2 m1.25 m/s0.5 m/s
4 m1.85 m/s0.5 m/s

Far from anything, Pip may go at its top speed. As an obstacle gets closer, the limit falls, and a robot that obeys it slows down smoothly on the approach. This is a stop zone, and almost every robot that shares space with people has one.

A safe robot is not one that never fails. It is one whose failures are boring: it notices, it stops, and it tells someone.

Words to know

Timeout
A deadline for a message. If it is missed, the data is treated as stale and the robot stops relying on it. On Pip: no scan for 0.3 s means stop.
Sanity check
A test that rejects values that cannot be right. On Pip: a distance of "not a number" is refused.
Watchdog
A part, separate from the main software, that cuts power to the motors if the software stops sending a heartbeat. On Pip: it makes a software freeze into a stop.
Emergency stop
A button that cuts power to the motors directly, not through the software. On Pip: a red button on the robot's top.
Stopping distance
The distance covered from the moment of the event to standstill: delay distance plus braking distance. On Pip: 0.35 m at 0.5 m/s in this lesson's example.
Stop zone
The region round the robot where an obstacle forces a speed limit or a stop. On Pip: it grows with speed.
Fail-safe
Designed so that a failure leads to the safe state, usually stopped. On Pip: cutting power stops it, rather than leaving it running.

A worked example: how long can the scanner be silent?

Pip's scanner sends ten scans a second, so a new one is due every 0.1 s. The robot drives at 0.5 m/s. What should the timeout be?

  1. What a missed deadline costs. While no scan arrives, Pip is driving blind. In 0.3 s at 0.5 m/s it covers 0.5 × 0.3 = 0.15 m.
  2. Then it stops. The robot has been commanded to stop at the timeout, and now needs its stopping distance: 0.5 × 0.2 + 0.5² ÷ (2 × 0.5) = 0.1 + 0.25 = 0.35 m.
  3. Total. 0.15 + 0.35 = 0.5 m from the last good scan to standstill.
  4. Is that acceptable? Anything the last good scan showed to be further away than 0.5 m is still safe: the robot stops short of it. A timeout of 0.3 s allows 3 missed scans before reacting. A timeout of 3 s would let Pip drive 1.5 m blind. A timeout of 0.1 s, one scan period, would stop it at every ordinary delay.

So the timeout is a trade between false alarms (too short) and blind distance (too long), and 0.3 s is a reasonable middle for this robot. Doubling the speed to 1 m/s doubles the blind distance to 0.3 m and raises the stopping distance to 1.2 m: the timeout would have to be shortened, or the speed limited.

Try it yourself

Write a "what if" card for a robot lawn mower. List five things that could go wrong (a sensor, the battery, a blade jam, the mower being picked up, rain). For each, say what sign it would give, and what the safe response is. Which of your five responses is "stop the blade immediately"?

One possible answer

Lifted: a tilt sensor reads a sudden steep angle, so stop the blade at once. Blade jam: the blade motor draws a high current and the speed falls, so stop the blade and the wheels. Boundary sensor silent: no signal for a few seconds, so stop and wait. Low battery: the voltage falls below a set level, so drive to the charger, or stop if too far. Rain: a rain sensor, or wet wheels slipping, so return to the dock. The blade-stopping ones are lifting and jams: the cases where a person could be hurt by the thing that spins.

Common mistakes

"A good robot does not need an emergency stop."

No robot is perfect, and the emergency stop is for the day it is not. It exists because the software may be what has failed, so it must not depend on the software.

"If a message stops, keep using the last one: it is the best I have."

Not for long. The last scan was true a moment ago and may be dangerously wrong now. Give every input a deadline, and stop when it passes.

"Going twice as fast is twice as dangerous."

The stopping distance grows with the square of the speed. At twice the speed the braking distance is four times as long, and the robot reaches obstacles in half the time.

Remember this

  1. A robot sees failures only as symptoms in its data. Rules watch for them.
  2. The simple defences are limits, timeouts, sanity checks and a stop that does not depend on the software.
  3. Stopping distance = speed × delay + speed² ÷ (2 × braking): speed matters more than it seems.
  4. The safe default is to stop, and to tell someone why.

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 moves at 0.8 m/s. Its delay is 0.25 s and its braking is 0.8 m/s². What is its stopping distance?

Explanation

Distance during the delay: 0.8 × 0.25 = 0.20 m. Braking distance: 0.8² ÷ (2 × 0.8) = 0.64 ÷ 1.6 = 0.40 m. Total: 0.60 m.

Question 2

The odometry of a robot reports that its wheels have turned for 10 s at 0.5 m/s, but the scanner shows the wall ahead has not moved closer. What is probably wrong, and what should the robot do?

Explanation

The robot is probably stuck or its wheels are spinning on the spot: it is commanding motion and not getting it. It should stop the motors (to avoid burning them out), report that it is blocked, and not carry on trusting its odometry, which now says it has moved 5 m that it did not.

Question 3

Why must an emergency stop cut power directly instead of sending a "stop" message to the software?

Explanation

The failure that makes a stop necessary may be in the software. A stop that depends on the software to carry it out may not happen at the very moment it is needed. A direct cut of motor power works whatever the software is doing.

What’s next

You now have the parts of a robot, and the habits that keep it safe. The last lesson is a map: where this course leaves you, and how to choose among the other tracks on this site.

Next lesson

Where to Go Next

Choose a next track on this site from what you want to build, and know what each one expects you to know.

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.