CodeTheRobot

Ubuntu Linux for Robotics · Lesson 90 of 96

Safety systems

Watchdogs, emergency stops, service restarts and the limits of software safety.

Estimated time · 60–90 min

Learning goals

What you will understand

  • Explain safety systems in your own words
  • Use it in a small workstation example
  • Verify the result instead of assuming it worked

Understand the idea first

The mental model

A safe robot fails into a safe state. Use a command watchdog (zero velocity if commands stop), velocity and acceleration limits, a collision monitor and geofences in software; add a hardware emergency stop that cuts motor power without depending on Linux. systemd can supervise services with Restart=on-failure and a WatchdogSec so a hung process is restarted.

Software checks are not a certified safety function. Real robots need a risk assessment, certified safety hardware (safety lidar, e-stop, safe torque off) and compliance with standards such as ISO 13849 and ISO 3691-4. Test failure modes on purpose: unplug the network, kill a node, cover a sensor.

Guided lesson

Work through these steps

  1. 1.

    Open a terminal and record the current state before changing anything.

  2. 2.

    Read the safety systems commands and predict what each one does.

  3. 3.

    Run the commands one at a time and compare each output with your prediction.

  4. 4.

    Write the commands that worked in a setup note you can repeat later.

Worked example

Read it before you run it

[Service]
# Section of a systemd unit file.
Restart=on-failure
# Restart the robot software if it crashes.
RestartSec=2
# Wait two seconds before restarting.
WatchdogSec=10
# Restart it if it stops reporting for ten seconds (the program must notify systemd).
ros2 topic pub --once /cmd_vel geometry_msgs/msg/Twist '{}'
# Publish a zero velocity by hand to stop the robot.
sudo systemctl kill -s SIGKILL robot-bringup.service
# Test: kill the service and confirm it restarts and the robot stops.

What the example is doing

  1. 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
  2. 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
  3. 3.Comments beginning with # explain safety checks and are not executed by the shell.

Watch it run · The robot's computer

See what this code does

The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.

robot computercpumemdiskdriverstoppedplannerstoppedloggerstoppedsafetystoppedTHE ROBOT'S COMPUTER

Demo for Safety systems. Expected result: The service restarts after being killed

Practice code

Now type it yourself

Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.

# TODO: kill the service robot-bringup with SIGKILL through systemctl kill, then show its status

Expected output

The service restarts after being killed
Stuck? Show the full solution (try it yourself first)
sudo systemctl kill -s SIGKILL robot-bringup.service
sleep 3
systemctl status robot-bringup.service

Expected result

How you know it worked

  • Each command completes without an unexplained error.
  • Your notes contain the command, the important output, and what it proves.

Practical exercise

Apply the lesson

Add a 0.5 s command watchdog to a simulated robot, kill the teleop node while it moves, confirm it stops, and configure a systemd unit that restarts the bringup after a crash. List hazards that software cannot cover.

Before you continue

  • You recorded the starting state
  • Every command and output is understood
  • The change can be repeated from your notes

If something goes wrong

A command says permission denied.

Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.

A command or package is not found.

Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.