Lesson reading
live
55 min
Start with the lesson question, connect the representations, and test the model with evidence.
Inspect the opening phenomenon
Predict what changes, then name the evidence.
Apply in the lab
Name the evidence before reading the answer.
Read only what helps
Then use the lab and recall check.
More when needed
Transcript and resources stay available below.
Course progress
Reactive Rules, State Machines, and Behavior Trees
Decision challenge
Use the opening example to make a prediction, identify evidence, and explain which model supports it.
How Do Robots Decide? Rules vs FSMs vs Behavior Trees
How Do Robots Decide? Rules vs FSMs vs Behavior Trees
Lesson reading
live
55 min
Video script
draft
Transcript fallback
available
courses/ai-robotics/modules/08-planning-and-robot-behavior/lessons/01-reactive-rules-state-machines-behavior-trees/video-transcript.md
Design a Battery-Interruptible Delivery Behavior
draft
18 min
Mastery check
live
7 questions / 7 min
Descriptive transcript — Rules vs FSMs vs Behavior Trees This text-only path includes every spoken paragraph and the essential visual information from the full 2:23 v14 video. It can be read without sound, images, color perception, or video access. “Narrator” marks the actual speech; “Visual,” headings, timestamps, and bracketed notes are added descriptions, not speech. The owner-approved redesign is published on YouTube (https://www.youtube.com/watch?v=H411e_RK6DA). The original animated robot carries a parcel between a charging dock and a delivery bay. Small HumanoidHub branding is consistent throughout. Written status labels accompany colors; captions occupy their own band. Follow the scenes in order, and pause at the prediction before reading the answer. Scene 01 — Who gets control? Scene ID: hook Scene time: 00:00.000–00:09.131 Narrator: A delivery robot has a job to finish. Then its battery turns critical. Who gets control: delivery, or docking? Visual: A parcel-carrying robot travels toward the delivery bay. Its battery indicator changes to CRITICAL. Arrows point toward the parcel bay and toward the charging dock; a question mark marks the unresolved choice. Scene 02 — Same robot. New logic. Scene ID: map Scene time: 00:09.131–00:18.373 Narrator: Three designs can solve this problem: reactive rules, a finite state machine, or a behavior tree. Watch the same robot. Visual: Three choices are introduced one at a time: Rules (condition to response), State machine (mode, event, next mode), and Behavior tree (priority, check, act). The same robot continues along the route beneath them. Scene 03 — Two rules can compete Scene ID: rules Scene time: 00:18.373–00:30.784 Narrator: Rules say: if a parcel is waiting, deliver. If the battery is critical, dock. Both conditions can be true. Add an explicit priority: docking wins. Visual: Two requests appear: parcel waiting requests DELIVER; battery critical requests DOCK. Both feed a priority junction. DOCK WINS appears when the junction resolves the conflict, and the robot turns toward the dock. Scene 04 — Remember the mode Scene ID: fsm Scene time: 00:30.784–00:40.368 Narrator: A finite state machine remembers its current mode. This robot is Delivering. Only the arrows you define are legal transitions. Visual: Three states form a directed loop: Delivering to Docking on critical; Docking to Charging on docked; Charging to Delivering on charged. Delivering is the highlighted current mode while the robot travels toward the parcel bay. No Idle or Fault state appears in this video. Scene 05 — Change mode on purpose Scene ID: event Scene time: 00:40.368–00:51.781 Narrator: The critical-battery event moves it into Docking. Delivery exits; docking takes over. After charging, a defined transition can return it to Delivering. Visual: The event marker follows only the defined transition arrows. The robot stops delivery, turns toward the dock, and reaches the charging side. The battery indicator becomes healthy before the charged transition allows Delivering again. Charging time is compressed, not measured. Scene 06 — Try priorities in order Scene ID: tree Scene time: 00:51.781–01:01.997 Narrator: A behavior tree organizes checks and actions. This reactive selector tries the left, higher-priority branch before the delivery branch. Visual: A Reactive selector sits above a left Sequence and a right Deliver action. The Sequence contains Critical? followed by Dock. Numbered branches and moving tick markers show left-before-right evaluation; arrows carry the tick downward. Scene 07 — Check, then act Scene ID: sequence Scene time: 01:01.997–01:10.280 Narrator: Inside that branch, a sequence checks Battery critical, then runs Dock. A failed check prevents Dock from starting. Visual: Two alternative check outcomes are demonstrated separately. SUCCESS at Critical? permits Dock to return RUNNING. FAILURE at Critical? makes the Sequence fail and leaves Dock SKIPPED. This is a comparison of outcomes, not the battery reversing during a docking operation. Scene 08 — Healthy battery: deliver Scene ID: healthy Scene time: 01:10.280–01:20.416 Narrator: With a healthy battery, that branch fails, so Deliver runs. Yellow means Running: the action has started, but is not finished. Visual: Critical? returns FAILURE because the battery is healthy. Failure passes up the Sequence; the selector then ticks Deliver. Deliver and the selector show RUNNING, and the robot advances toward the parcel bay. The on-screen reminder says Running is not finished. Scene 09 — Critical battery: dock Scene ID: critical Scene time: 01:20.416–01:30.302 Narrator: Now the battery turns critical. On the next tick, the check succeeds. The delivery action must halt, and docking takes control. Visual: The battery becomes CRITICAL. On the next illustrated tick, Critical? reports SUCCESS; Deliver stays RUNNING until the halt is shown. Deliver then becomes HALTED, Dock becomes RUNNING, and the robot pauses and turns toward the dock. Tick propagation is deliberately slowed to make the handoff visible. Scene 10 — Can the action stop? Scene ID: preemption Scene time: 01:30.302–01:42.116 Narrator: That interruption is called preemption. It only works when the action returns control promptly and handles cancellation. A blocking action can freeze reevaluation. Visual: The upper control-flow diagram passes a marker from tick through action to return, representing prompt return and cancellation support. In contrast, a blocking-action bar stops the flow before another check, with the label NO RECHECK. This is execution flow, not a robot path. Scene 11 — Progress is not success Scene ID: recovery Scene time: 01:42.116–01:50.667 Narrator: Running is not Success. And retrying the same blocked route changes nothing; recovery must change something relevant. Visual: A moving robot has not yet reached its goal: RUNNING is not SUCCESS. A fixed obstacle blocks the original route. Repeating that same route is contrasted with a changed route around the obstacle. The example assumes unchanged obstacle and route information. Scene 12 — Different strengths Scene ID: compare Scene time: 01:50.667–02:03.113 Narrator: Which design should you choose? Rules for small responses. State machines for explicit modes. Behavior trees for reusable priorities. None is automatically safe. Visual: Three cards highlight different strengths: rules for small responses, state machines for explicit modes, and behavior trees for reusable priorities. A separate warning says no design is automatically safe. These are introductory choices, not a ranking or an exclusive taxonomy. Scene 13 — What makes it work? Scene ID: question Scene time: 02:03.113–02:13.523 Narrator: Your turn: the battery turns critical while Deliver is running. What two capabilities make this handoff work? Visual: A critical-battery robot is still labeled DELIVER IS RUNNING. Two unanswered boxes ask for the capabilities needed for handoff. After the question, the video pauses silently for 2.4 seconds before revealing the answer. [Silent retrieval pause: 02:11.123–02:13.523; 2.4 seconds.] Scene 14 — Recheck. Halt. Handoff. Scene ID: answer Scene time: 02:13.523–02:23.356 Narrator: Recheck priorities, and halt the running action. Trace those two steps in the EduQuest lab, then test your own design. Visual: Two answers appear in sequence: RECHECK PRIORITIES, then HALT RUNNING ACTION. The robot turns toward the dock. The closing prompt invites the learner to trace and test the mechanism in the EduQuest lab. Interpretation notes — not spoken This is an original mission-level example, not a ROS node lifecycle diagram or a safety-certified controller. The three-state FSM is specific to this video; the separate lesson board is a different worked example. The displayed reactive selector means `ReactiveFallback`, not ordinary `Fallback`. The inner `Sequence` resumes a RUNNING Dock without repeating the earlier successful battery check. Battery stays critical throughout this illustrated docking trace. A failed Dock can fall through to Deliver unless separate guards prevent it. Emergency stops and collision protection remain independent constraints. See Fallbacks (https://www.behaviortree.dev/docs/nodes-library/FallbackNode/), Sequences (https://www.behaviortree.dev/docs/nodes-library/SequenceNode/), and Asynchronous Actions (https://www.behaviortree.dev/docs/guides/asynchronous_nodes/) from BehaviorTree.CPP 4.8, verified September 6, 2026. Times mark scene boundaries rounded to milliseconds, not individual-word timing. The last rendered scene ends at 02:23.356; 30 fps encoding ends at 02:23.367. Status words accompany color: RUNNING is yellow, SUCCESS green, and FAILURE or HALTED red. Related learning Use the Core explanation on this page for the control-flow model and the Practice lab for an executable or paper trace. The Narrator paragraphs above reproduce the spoken narration; Visual paragraphs describe the animation. This format separates speech from added visual explanations following W3C WAI transcript guidance (https://www.w3.org/WAI/media/av/transcripts/); it is not a claim of complete WCAG conformance.
Reading lab
Connect the lesson's words, diagrams, graphs, evidence, and equations.
A delivery robot is halfway to a goal when its battery becomes critical. Should it finish the delivery, switch modes, or reconsider its priorities on the next control tick?
Watch the full 2:23 Humanoid Hub tutorial, approved and published as v14. For the same teaching without video, open the Reference drawer and then Transcript for accessibility and fallback. It includes all narration plus descriptions of every scene.
These are not intelligence levels. They are control-flow structures, and a real robot may combine all three.

Open the comparison diagram at full size to inspect the transition labels.
Use the board from top to bottom: the rule resolves a local conflict by priority, the FSM restricts legal mode changes, and the behavior tree rechecks its safety branch before continuing delivery.
Consider this tree:
ReactiveFallback
├─ Sequence
│ ├─ BatteryCritical?
│ └─ Dock
└─ DeliverPackage
BatteryCritical? fails, the first Sequence fails, so Fallback ticks DeliverPackage.DeliverPackage returns Running.Dock becomes the running action.The root must be ReactiveFallback for this example. In BehaviorTree.CPP 4.8, an ordinary Fallback resumes a running child on the next tick without rechecking earlier failed siblings. Its reactive variant starts again at the first child. See the official Fallback comparison.
For this simplified trace, battery stays critical while docking runs. The inner ordinary Sequence resumes Dock while it is Running; it does not continuously recheck the earlier successful battery condition. This is a control-flow example, not a complete safety controller: a failed docking branch can fall through to delivery unless separate guards forbid it. Emergency stops and collision protection must remain independent constraints.
The important design question is not “Which diagram is fashionable?” It is “When can priorities change, which action must be haltable, and what evidence makes a branch succeed?”
If a long-running delivery action never yields control while it is Running, can a higher-priority battery condition preempt it? Explain.
Suppose package release is an ordinary Sequence: UnlockBay → ReleasePackage → ConfirmEmpty. If all three synchronous children return immediately, that Sequence may advance through them during one tree tick. The outer reactive parent cannot reconsider the battery between those children unless control is deliberately yielded. In BehaviorTree.CPP v4.8, AsyncSequence creates a reevaluation point after each successful child. It still cannot interrupt the middle of one blocking child.
Mark the safe interruption boundaries in both versions. Then explain which operation must itself be asynchronous or stateful if it can take long enough for the battery state to change.
Use rules for bounded local reactions, FSMs for explicit modes and legal transitions, and BTs for modular priorities, sequences, alternatives, and interruption. Define observable completion evidence, halt long-running actions safely, and bound every recovery loop.
Compare a rule set, FSM, and behavior tree for the same simulated delivery mission.
Use paper, a spreadsheet, or any diagram tool. No robot hardware or paid software is required. Represent battery as normal or critical, delivery as idle/running/success/failure, and docking as idle/running/success/failure. If Node.js is available, the lesson also includes assets/battery-preemption-tick-trace.mjs, a deterministic reference trace.
Download the optional reference trace into a local folder named assets, or complete the same trace on paper.
BatteryCritical? → Dock and whose second branch is DeliverPackage.node assets/battery-preemption-tick-trace.mjs. Compare both written tables with your preemption and recovery traces. Change tick 3 back to normal and predict which assertion should fail before running it again. Then change the second PlanPath result to SUCCESS and predict all four recovery-summary fields.UnlockBay → ReleasePackage → ConfirmEmpty inside an ordinary Sequence, and assume all three children return immediately. Mark the only points at which the outer reactive parent can inspect the battery condition. Then replace it with AsyncSequence and mark the added reevaluation points. Do not claim that either structure can interrupt the middle of a single blocking child.PlanPath as the primary child, ClearCostmap as recovery, and a retry limit of one. Trace PlanPath: Failure → ClearCostmap: Success → PlanPath: Failure. Record finalControlStatus, primaryAttempts, recoveryOutcome, and missionOutcome as four separate fields so cleanup success cannot be mistaken for mission success.AsyncSequence yields between successful synchronous children, while an individual blocking child still prevents prompt preemption.Failure when the primary child never succeeds, even though the recovery child succeeds; the trace must preserve primary-attempt count, recovery outcome, and mission outcome separately.PASS:, an explanation of why the halt occurs on tick 3 rather than between ticks, and a recovery summary that keeps cleanup success separate from mission success.Sequence may advance through all immediately successful children in one tree tick.Use the text tree and a five-row table; color is optional and every status must be written as a word.
Which representation made interruption easiest to verify, which made legal modes easiest to audit, and which trace field prevented you from confusing recovery success with mission success?
Add a second interrupt. Explain its priority, legal transitions, cancellation requirements and independent protective constraints.