Skip to content
Tactiverge

School/○ Innovator/Week 29

No state left behind

A robot hits a wall, enters FAULT, and stays there forever, even after someone clears the path. The code has no bug. The design does.

About 35 min · 3 goals · Checked by automated tests

1.Why should I care?

Most state-machine failures are not typos: they are missing transitions. A state nobody can leave, or a state nobody can reach, passes every test you thought to write. Engineers check completeness systematically.

  • ◇ Check a state machine for unreachable states, trap states and unhandled events.
  • ◇ Add safe default and fault states with explicit ways out.
  • ◇ Pass an automated safety audit for a timed state machine.

2.Discover

Build the junction's controller as a cycle of states and run the server's safety audit. Start from the starter design and fix one failure at a time, re-running the audit after each fix.

Can't use the interactive? Read a description instead

In the traffic-system build, the starter state cycle fails the audit for missing amber, missing all-red clearance and no pedestrian walk phase; adding those states in order makes the audit pass.

3.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

Which state in the worked example is a trap?

4.Apply it

Write the full state × event table for the delivery robot (5 states, 6 events). Fill every cell with a target or 'ignore: reason'. Find at least one cell where 'ignore' would be unsafe and fix it.

Open BUILD 005: Build a Traffic Management System →

5.Understand

Three completeness checks

Reachability: can every state be entered from the initial state? An unreachable state is dead code, or a sign a transition is missing. Escape: does every state have a way out? A trap state freezes the robot. Coverage: for every state, is every event either handled or deliberately ignored?

Fault and safe states

Real robots need a FAULT or SAFE_STOP state reachable from every state where something can go wrong, and an explicit, deliberate way out (a reset, after the cause is cleared). The way out is part of the design, not an afterthought.

Tables beat diagrams for checking

Diagrams are good for understanding; tables are good for checking. Write a grid with states as rows and events as columns. Every cell must say a target state or 'ignore', with a reason. An empty cell is a decision nobody made.

Explain it another way

Like a building's floor plan: every room needs a door in and a door out, and every corridor sign must point somewhere real.

Worked example 1

States IDLE, DRIVING, DELIVERING, FAULT. Transitions: IDLE→DRIVING (order), DRIVING→DELIVERING (arrived), DELIVERING→IDLE (done), DRIVING→FAULT (bump). Which check fails?

Escape: FAULT has no way out, so it is a trap. Add FAULT + reset → IDLE, ideally guarded by 'obstacle cleared'.

Common mix-ups

  • If the code runs without errors, the state machine is complete.
    ✓ Missing transitions produce no errors at all; only systematic reachability, escape and coverage checks find them.

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2

A state machine has 5 states and 6 events. How many cells must a complete coverage table fill in?

Practice 3

A state CHARGING exists in the code but no rule leads into it. What should you conclude?

Practice 4 · a fresh version every time

A delivery robot starts in IDLE (state 0) with its battery at 45 %. Rules: IDLE(0) + order → DRIVING(1) if battery ≥ 30 %, else → CHARGING(3). DRIVING(1) + arrived → DELIVERING(2). DRIVING(1) + bump → FAULT(4). DELIVERING(2) + done → IDLE(0) and the battery drops by 20 %. CHARGING(3) + charged → IDLE(0) with the battery at 100 %. FAULT(4) + reset → IDLE(0). Any other event in any state is ignored. Events arrive in this order: bump, reset, arrived, done, arrived, order. Which state number is it in at the end?

state number

Practice 5

What is the best way out of a FAULT state on a delivery robot?

7.Predict

A junction's state machine goes from NS green straight to EW green. What is missing?

Guess first. Being wrong here is how the surprise works.

8.Reflect

Concepts: Super-loops and finite state machines · Robot safety and ethics