ProjekinAja. Robotics Stage 6 · Planning Deployment Lesson 6.6
● Stage 6 · Lesson 6.6

Behavior Trees: Architecture, Ticks, and Reactive Mission Management

A bad state machine cannot recover from unexpected events — a behavior tree can, but only if you design the fallback hierarchy correctly; most field robot failures are in the decision layer, not the planner.

⏱ ~22 min read 🧠 Decision architecture ⚙ FollowBot mission

🎯 By the end you'll understand

The five BT node types (Action, Condition, Sequence, Fallback, Decorator) and what each returns. How the tick mechanism propagates through a tree and why that propagation gives BTs their reactive character. The concrete modularity and recoverability advantages over FSMs — and the conditions under which those advantages disappear. How to design FollowBot's mission BT with fallbacks for person lost, nav stuck, and battery low. And the structural failure mode that silently halts a robot mid-mission: a Sequence wrapping a long-running action with no Fallback.

KEY INSIGHTThe decision layer is where field robots fail

Every field robot that "got stuck" had a planner that computed a perfectly valid path and a controller that executed it precisely. The problem was in between: nobody decided what to do when the first plan stopped working.

When FollowBot loses sight of the person it is following, the SLAM map stays valid, the DWA local planner is ready to compute, and the velocity controller is spinning at 100 Hz. None of those subsystems are broken. What is missing is the answer to a deceptively simple question: what should the robot do next? That is the decision layer — and for the last decade, behavior trees have been the dominant answer in production mobile robotics, from the Nav2 stack to Boston Dynamics' field robots.

🔑 Hold onto this

A behavior tree does not plan paths. It does not estimate state. It does not control motors. Its entire job is to decide, at each tick, which capability to invoke — and to handle the case where that capability fails. The quality of your BT is measured almost entirely by the quality of its fallback hierarchy: what does the robot do when the thing it was trying to do stops working? Most BT bugs are missing fallbacks, not incorrect actions.

CORE CONCEPTFive node types, three return values

A behavior tree is a rooted directed tree. The root is ticked at a fixed rate (typically 10–50 Hz in Nav2). Each tick propagates down from the root to the leaves, collecting return values on the way back up. Every node returns exactly one of three values:

Return valueMeaningAnalogy
SUCCESSThe node achieved its goal or its condition is satisfiedFunction returned true
FAILUREThe node cannot currently achieve its goalFunction returned false
RUNNINGThe node is in progress; tick me again next cycleAsync callback not yet complete

These three values, flowing up from leaves to root through five node types, produce the reactive behavior. Here are the five node types:

1

Action node (leaf)

Calls a capability — navigate_to_pose, rotate_in_place, send_arm_gesture. Returns RUNNING until complete, then SUCCESS or FAILURE. Actions are the only nodes that communicate with external systems (Nav2 servers, hardware interfaces). They are where RUNNING is most common: a navigation action might return RUNNING for 30 seconds while the robot moves across the room. During that time, the BT root keeps ticking, and the action keeps being polled — which is exactly how the BT can preempt a navigation if the person disappears mid-path.

2

Condition node (leaf)

Checks a fact — IsPersonDetected?, IsBatteryAbove30%?, IsPathClear?. Returns SUCCESS or FAILURE immediately; never RUNNING. Conditions are the BT's eyes: they read from the blackboard (a shared key-value store) or from ROS 2 topics and decide the current state of the world. A well-designed BT uses many conditions in its hierarchy so that facts about the world are continuously tested at every tick, not just once at the start.

3

Sequence node (composite, →)

Executes children left-to-right like a logical AND. Ticks child 1; if it returns SUCCESS, ticks child 2; and so on. If any child returns FAILURE, the Sequence immediately returns FAILURE without ticking the remaining children. If any child returns RUNNING, the Sequence returns RUNNING. A Sequence succeeds only when all children succeed in order. Use for: "do A, then B, then C — and abort the whole thing if any step fails." This is the node that bites you when it wraps a long-running action with no Fallback: if the action fails halfway, the Sequence returns FAILURE and the robot gets stuck.

4

Fallback node (composite, ?)

Executes children left-to-right like a logical OR. Ticks child 1; if it returns FAILURE, ticks child 2; and so on. Returns SUCCESS as soon as any child succeeds. If all children fail, returns FAILURE. If any child returns RUNNING, returns RUNNING. A Fallback is a priority-ordered list of strategies: "try the first; if it fails, try the second; if that fails, try the third." This node is what makes BTs recoverable. A BT with no Fallback nodes is just a rigid linear script.

5

Decorator node (wrapper)

Wraps a single child and modifies its return value or behavior. Common examples: Inverter (flips SUCCESS↔FAILURE, effectively NOT), Retry(N) (re-ticks the child up to N times before propagating FAILURE), ForceSuccess (always returns SUCCESS regardless of child's result — useful for optional steps you don't want to block recovery). Decorators are often overused: a tree with ten decorators is usually one that has the wrong structure. Use them surgically.

→ Sequence AND · all children must succeed ? Fallback OR · first succeeding child wins Action [navigate] leaf · calls a capability may return RUNNING Condition? [is_detected] leaf · tests a fact never RUNNING ◇ Dec [Inverter] wraps 1 child modifies return value Return values propagate up: SUCCESS · FAILURE · RUNNING Composite nodes aggregate children's values; leaf nodes produce them
The five BT node types and their symbols. The diamond (Decorator) wraps exactly one child; rectangles (Sequence, Fallback, Action) and ellipses (Condition) are the most common. The arrow and question mark symbols for Sequence and Fallback match the Nav2 BT XML convention.

HOW IT WORKSThe tick mechanism: why BTs are reactive

The defining property of a behavior tree is that the root is ticked at a fixed rate — typically at 10–50 Hz in a robot system — and every tick traverses the tree fresh from the root. This is radically different from a state machine's event-driven transitions. In an FSM, the system stays in its current state until an event arrives. In a BT, the system re-evaluates the entire decision hierarchy at every tick.

Here is what a single tick looks like for FollowBot's top-level tree structure:

📖 Reactive property defined

A BT is reactive because every tick starts at the root and re-checks conditions before re-entering long-running actions. If the person disappears while FollowBot is navigating, the next tick finds the IsPersonDetected? condition returning FAILURE. The Sequence above the navigation action immediately returns FAILURE. The Fallback above that sequence ticks its next child — the recovery behavior — automatically. No event needs to be explicitly sent. No state transition needs to be programmed. The structure of the tree does the work.

Consider a simplified Sequence: [IsPersonDetected?] → [NavigateToGoal]. At tick T₁, the person is visible — both succeed. At tick T₂, the person is still visible and navigation is in progress — the Condition returns SUCCESS and NavigateToGoal returns RUNNING. At tick T₃, the person vanishes — the Condition now returns FAILURE. The Sequence immediately returns FAILURE without re-ticking NavigateToGoal. The Nav2 action client receives a cancel request. The BT's Fallback parent then ticks its recovery child. All of this happens within 20–100 ms (one or two tick cycles).

💡 Memory vs. reactive Sequence/Fallback

Nav2's BT.CPP library offers two variants: the reactive Sequence (re-ticks running children from the left each tick) and the memory Sequence (skips already-succeeded children). Reactive Sequences are the default and support the property described above. Memory Sequences can be faster but sacrifice the continuous re-evaluation of conditions. The failure mode of a memory Sequence: a condition that was true when first ticked becomes false mid-execution, but the memory Sequence never re-checks it. Always choose reactive unless you have measured a performance reason not to.

followbot_mission.xmlNav2 BT XML · simplified
<!-- Root ticks at 10 Hz. Fallback = "?" / Sequence = "-->" convention -->
<root main_tree_to_execute="MainTree">
  <BehaviorTree ID="MainTree">
    <Fallback name="MissionFallback">

      <!-- Primary: detect → navigate to person -->
      <Sequence name="FollowSequence">
        <Condition ID="IsPersonDetected" topic="/person_tracker/status"/>
        <Condition ID="IsBatteryOK"       threshold="0.20"/>
        <Action    ID="NavigateToGoal"    goal_topic="/person_tracker/goal"/>
      </Sequence>

      <!-- Fallback 1: person lost — rotate to search -->
      <Sequence name="SearchSequence">
        <Inverter>
          <Condition ID="IsPersonDetected"/>
        </Inverter>
        <Action ID="RotateSearch" angular_vel="0.4" max_turns="1"/>
      </Sequence>

      <!-- Fallback 2: nav stuck — clear costmap + back up -->
      <Sequence name="RecoverSequence">
        <Action ID="ClearCostmap"/>
        <Action ID="BackUpSlowly" distance="0.3"/>
      </Sequence>

      <!-- Fallback 3: battery critical — dock -->
      <Action ID="NavigateToDock" goal="$(dock_pose)"/>

    </Fallback>
  </BehaviorTree>
</root>

Notice the structure: the outermost node is a Fallback. The primary behavior (detect + follow) is a Sequence inside it. When that Sequence fails — for any reason — the Fallback automatically tries the search recovery, then the stuck recovery, then the battery dock. Priority is encoded in left-to-right child order, not in explicit condition flags. Adding a new recovery does not require touching any existing node.

COMPARISONBT vs FSM: not a close race for recovery tasks

Finite state machines and behavior trees are sometimes presented as equivalent alternatives. They are not equivalent in practice for mission management in robots that encounter unexpected events. The gap comes from two structural differences:

PropertyFinite State MachineBehavior Tree
Transition encoding Explicit: every (state, event) pair needs a defined transition. N states × M events = O(N×M) transitions to define. Implicit: tick propagation through the tree structure. Adding a new fallback adds one subtree, no matrix entries.
Modularity Adding a new state requires adding transitions from every state that might reach it and every state it might reach. Combinatorial coupling. Adding a new subtree only requires choosing its position in the parent's child list. Subtrees are independently testable.
Reactivity Event-driven: the system stays in its state until something explicitly triggers a transition. Missing an event = missed recovery. Tick-driven: conditions are re-checked every tick regardless of events. No "missed event" failure class exists.
State explosion N behaviors × K failure modes = N×K states. A 10-behavior robot with 4 failure modes per behavior needs 40 states minimum. N behaviors as leaf nodes; K failure modes as Fallback children. Still N+K nodes, not N×K.
Where FSMs still win Strictly sequential workflows with no unexpected events (e.g., a manufacturing arm's fixed cycle). Formal verification of safety properties. Simpler runtime overhead. BTs are overkill for systems that truly never need recovery.
💡 The honest version: BTs are not universally better

BTs win on modularity and reactivity for mission-management layers — the "what to do" question. They are not planners; they don't replace A* or DWA for path computation. They are also harder to formally verify than FSMs: a BT's emergent behavior from nested Sequence/Fallback combinations can be non-obvious. The BT.CPP library and Nav2 address this with tree-visualization tools (Groot), but verifying safety properties of a large BT still requires careful analysis. For safety-critical branches (battery critical, collision imminent), consider whether a simpler, separately-running watchdog FSM is clearer than nesting safety conditions inside the main BT hierarchy.

SEE ITBT runner: step-tick and inject failures

The tree below models FollowBot's mission BT. Use the preset configurations to load different trees, inject a fault, then step-tick to see how the tick propagates and which fallback activates. The tick trace panel shows the return value at every node for each tick cycle. Pay attention to what happens to NavigateToGoal when a Condition above it returns FAILURE.

⚙ Interactive · BT builder and tick runner

Choose a tree preset, optionally inject a fault, then step-tick to see the propagation.

Inject fault:
Sequence (→) Fallback (?) Action Condition SUCCESS FAILURE RUNNING

Tree: Nominal following

Select a preset and step-tick to see the tick propagation. The tick trace below shows each node's return value in order of visitation.

Tick trace will appear here — step-tick to start.

Notice how the No fallback (broken) preset reveals the structural failure mode: when NavigateToGoal fails mid-execution, the Sequence above it returns FAILURE immediately, and there is no Fallback to recover. The robot stops, and the BT root returns FAILURE with no further action. This is the "stuck mid-sequence" failure that causes most field robot stoppages. The fix is never "retry the same action" — it is structuring the parent as a Fallback with a meaningful recovery as the next child.

FOLLOWBOTFollowBot's mission BT: full design

With the Nav2 stack from Lesson 6.5 — A* global planner, DWA local planner, LIDAR costmap — FollowBot now has all the planning machinery it needs. The behavior tree is the layer that decides which of that machinery to invoke, and when to give up and try something else.

Here is the complete mission BT design with the rationale for each structural choice:

1

Root: Fallback (priority-ordered recovery)

The root node is always a Fallback, not a Sequence. If the root were a Sequence, any child failure would halt the entire mission with no recovery. The Fallback structure means: try the primary behavior; if it fails, try recovery 1; if that fails, try recovery 2; and so on. The final child of a root Fallback should always succeed (or signal for human intervention) — it must never leave the robot in a state where the root returns FAILURE with nothing left to do.

2

Primary: Sequence [IsPersonDetected, IsBatteryOK, NavigateToGoal]

The primary behavior is a Sequence of two conditions followed by the action. The conditions are checked at every tick — if the person disappears mid-navigation, IsPersonDetected returns FAILURE on the next tick, the Sequence returns FAILURE without ticking NavigateToGoal again, and Nav2 receives a cancel. Why IsBatteryOK before NavigateToGoal? Because NavigateToGoal could return RUNNING for minutes on a long path; the battery check ensures that condition is continuously re-evaluated, not just once at the start of the navigation action.

3

Recovery 1: Search [Inverter(IsPersonDetected), RotateSearch]

The search behavior activates when the person is not detected. It uses an Inverter decorator to turn NOT IsPersonDetected into a Condition that succeeds when the person is absent — ensuring the search Sequence only runs when needed. RotateSearch turns in place at 0.4 rad/s for one full revolution. If the person is re-detected during the rotation, the next tick's root will try the primary Sequence first and succeed, preempting the search. This is the reactive property in action.

4

Recovery 2: Stuck recovery [ClearCostmap, BackUpSlowly]

The stuck recovery activates when the search also fails — typically when the person is still absent after the full rotation. At this point the robot may be in an uncomfortable position (close to a wall, mid-doorway). ClearCostmap resets the local costmap's temporary obstacles (inflation artifacts, stale scan data), then BackUpSlowly moves 0.3 m in reverse to create maneuvering room. This recovery does not check a person-detection condition — it runs regardless, because by this point the primary goal (person) is lost and clearing the nav state is the right thing to do unconditionally.

5

Final fallback: NavigateToDock (mission abort)

The dock behavior is a mission abort — not a battery-triggered low-power action — and fires when both search and stuck-recovery have failed, meaning the robot is either hopelessly lost or the path network is blocked. In practice this means the person has been gone for more than one rotation period and the robot cannot navigate freely. Note: this fallback also fires when the path to the person is blocked (stuck mid-navigation) and recovery has exhausted its retries; the person may still be visible. For a battery-specific dock return, add a separate IsBatteryLow condition in the primary Sequence and place its own NavigateToDock branch before the search fallback. Going to dock on mission abort saves the battery and announces the failure clearly (robot at dock = "I gave up, find me here"). A real deployment would also publish a diagnostic event to the monitoring system. The dock navigation uses the same Nav2 planner, so it inherits all the costmap obstacle avoidance for free.

🔑 FollowBot Stage 6 milestone

The full Nav2 stack is now configured: A* global planner on the SLAM map from Stage 5, DWA local planner with FollowBot's dynamic constraints, costmap with LIDAR obstacle layer and inflation radius tuned to FollowBot's body radius (0.22 m + 0.08 m safety margin). The behavior tree orchestrates: detect person → navigate to tracked goal → maintain following distance → handle occlusion → recover. This mission BT is the final behavioral layer before sim-to-real transfer, which Lesson 6.7 addresses as a first-class engineering problem.

One important implementation detail: the person tracker goal (published on /person_tracker/goal) is a continuously updated PoseStamped. The NavigateToGoal action uses Nav2's FollowDynamicPoint capability rather than NavigateToPose, which expects a fixed goal. FollowDynamicPoint re-plans at each tick based on the latest goal pose — exactly the behavior needed for a moving person. If you use NavigateToPose with a dynamic goal, the robot navigates to where the person was when the action was first called, not where they are now. This is a frequent integration mistake.

WEAKNESSWhere behavior trees bite

✗ Sequence with no Fallback around a long-running action

The most common BT structural bug: you write a Sequence like [IsReady?, LongRunningAction] and wrap it in nothing. When LongRunningAction fails mid-execution (Nav2 reports aborted because the goal became invalid), the Sequence returns FAILURE, the root returns FAILURE, and the robot stops — with no recovery, no diagnostic, and no indication to the operator of what happened. The fix is not to add a Retry decorator (retrying a failed nav is rarely the right answer). The fix is to add a meaningful Fallback sibling that makes the failure explicit and recovers the robot to a safe state. Every long-running Action in a mission BT should have a Fallback cousin that handles its failure case.

✗ Using conditions as guards instead of re-checks

A subtler mistake: placing a Condition that should be continuously re-evaluated inside a memory Sequence (or only at the start of a run), then wondering why the robot doesn't stop when the condition becomes false mid-execution. This happens when developers treat BT conditions like if-statement guards rather than as continuously re-polled facts. In a reactive Sequence, every condition is re-ticked from the left at every root tick. If you switch to a memory variant for performance reasons, you must manually account for every condition that can change while an action is running. Nav2 defaults to reactive — change this with explicit understanding, not for performance guesswork.

✗ Fallback children that always succeed

If a Fallback child can never return FAILURE — for example, a StopRobot action that always succeeds — then all subsequent Fallback children are unreachable. The BT short-circuits at the first always-succeeding child. This is correct behavior from the BT's perspective, but it makes subsequent recovery strategies dead code. It bites most often in the battery-critical fallback: if NavigateToDock can fail (the dock is blocked), then ForceSuccess wrapping it hides that failure from the root. A BT where the final fallback returns FAILURE should signal a hardware-level stop or alert, not silently return FAILURE to nobody.

KEY INSIGHTHow it connects

  • 6.5 · The Nav2 Stack: Architecture, Lifecycle Nodes, and Failure Modes — the planning and control machinery that FollowBot's BT orchestrates. NavigateToGoal, ClearCostmap, and BackUpSlowly are all Nav2 BT action plugins operating on the stack built in that lesson. Lifecycle node management means the BT must also handle the case where a Nav2 server is in the inactive lifecycle state — not just navigation failures.
  • 4.9 · Multi-Sensor Fusion on FollowBot: Architecture and Covariance Design — the IsPersonDetected condition reads from the person tracker, which fuses LIDAR and RGB-D data with the EKF architecture designed in that lesson. The BT's reactivity is only as fast as the person tracker's update rate; a tracker that updates at 5 Hz limits the BT's effective reaction time to 200 ms regardless of tick rate.
  • 6.7 · The Sim-to-Real Gap: Taxonomy, Root Causes, and Honest Mitigations — the mission BT designed here runs first in Gazebo. The sim-to-real gap for the decision layer takes a specific form: the BT's timing assumptions (how quickly IsPersonDetected transitions, how long NavigateToGoal takes to return) may be calibrated to simulation latencies that don't match hardware. Lesson 6.7 categorizes these behavioral sim-to-real gaps and shows how to diagnose them.

Behavior trees sit at the intersection of all prior stages: they consume state estimation (Stage 4), perception results (Stage 5), and drive planning and control (Stage 6). A BT designed without understanding what its Action and Condition nodes actually do — latency, failure modes, update rates — produces a robot that behaves strangely in the field in ways that are hard to trace. The structural elegance of a well-designed BT is worth nothing if the leaf nodes feeding it return garbage.

GLOSSARYKey terms

Behavior tree (BT)
A hierarchical task representation where a root node is ticked at a fixed rate, propagating the tick through composite and leaf nodes that return SUCCESS, FAILURE, or RUNNING. The standard mission management architecture in Nav2 and many production robot systems.
Tick
One traversal of the BT from root to leaves (and back), collecting return values. The BT root is ticked at a fixed rate (e.g., 10 Hz); the effective reactivity of the system is bounded by the tick rate.
Sequence node
A composite BT node that ticks children left-to-right and returns SUCCESS only if all children succeed. Returns FAILURE immediately when any child fails. Encodes AND logic; used for "do A then B then C."
Fallback node
A composite BT node that ticks children left-to-right and returns SUCCESS as soon as any child succeeds. Returns FAILURE only if all children fail. Encodes OR logic with priority; used for "try A, else try B, else try C."
Decorator node
A BT node that wraps exactly one child and modifies its return value or tick behavior. Common examples: Inverter (NOT), Retry(N), ForceSuccess, RepeatUntilFailure.
Blackboard
A shared key-value store that BT nodes use to communicate. Action nodes write results to the blackboard; Condition nodes read from it. In Nav2/BT.CPP, the blackboard is the primary mechanism for passing data between BT nodes without coupling them directly.
Reactive Sequence
A Sequence that re-ticks all children from the leftmost at every root tick, including re-checking conditions that came before a currently-running action. The default in Nav2; contrast with memory Sequence, which skips already-succeeded children.
FollowDynamicPoint
A Nav2 BT action plugin that re-plans to a continuously updated goal pose at each tick, as opposed to NavigateToPose which navigates to a fixed goal. Required for following a moving person whose position updates every perception cycle.

ACTIVE RECALLCheck your understanding

Answer in your own words first, then reveal.

1A Fallback node has three children. Child 1 returns FAILURE, child 2 returns RUNNING. What does the Fallback return, and is child 3 ticked?›

The Fallback returns RUNNING, and child 3 is not ticked. A Fallback ticks children left-to-right and returns as soon as any child returns something other than FAILURE. Child 1 returned FAILURE, so child 2 is ticked. Child 2 returned RUNNING, so the Fallback returns RUNNING without proceeding to child 3. On the next tick, the Fallback re-ticks from child 1 again (in the reactive variant) or from child 2 directly (in the memory variant). Child 3 will only be ticked if child 2 eventually returns FAILURE.

2FollowBot's mission BT is ticking normally — NavigateToGoal is returning RUNNING. The person suddenly walks behind a wall and IsPersonDetected transitions to FAILURE. What happens on the next tick?›

On the next tick, the root Fallback ticks the primary FollowSequence. The Sequence starts from child 1 (IsPersonDetected), which now returns FAILURE. The Sequence immediately returns FAILURE without ticking IsBatteryOK or NavigateToGoal. NavigateToGoal receives a cancellation via the Nav2 action client. The root Fallback then ticks its second child — the SearchSequence — which checks Inverter(IsPersonDetected) (now SUCCESS since person is absent) and then ticks RotateSearch (RUNNING). The root Fallback returns RUNNING. The robot begins rotating to search, and NavigateToGoal has been cleanly cancelled. All of this happens within one or two effective response cycles (100–200 ms, bounded by action server feedback latency).

3Why is a BT more modular than a finite state machine for a robot with 6 behaviors and 3 failure modes per behavior?›

An FSM for this system requires approximately 6 × 3 = 18 states plus explicit transitions between every pair of states that might be connected — potentially O(18²) = 324 transitions to define and maintain. Adding a 7th behavior means defining transitions from every existing state to the new state and back — 36 new transitions. In a BT, the 6 behaviors are 6 leaf Action nodes; the 3 failure modes per behavior are handled by Fallback siblings or subtrees at each behavior's level. Adding a 7th behavior adds one Action node and its associated Fallback subtree. No existing node changes. The total node count grows linearly with behaviors and failure modes, not quadratically. The structural coupling in the FSM's transition table is absent in the BT's tree structure.

4A developer uses a memory Sequence instead of a reactive Sequence to reduce tick overhead. What failure mode does this introduce for FollowBot?›

A memory Sequence skips already-succeeded children on subsequent ticks. For FollowBot's primary Sequence [IsPersonDetected, IsBatteryOK, NavigateToGoal], this means that once IsPersonDetected and IsBatteryOK both return SUCCESS on the first tick, they are not re-checked on subsequent ticks while NavigateToGoal is running. If the person disappears or the battery drops below threshold mid-navigation, the BT will not detect either event — NavigateToGoal will continue running as if both conditions are still met. The reactive Sequence re-checks both conditions from the leftmost child every tick, at the cost of two extra condition-node evaluations per tick (negligible overhead for condition nodes, which return instantly).

Next: the sim-to-real gap — where FollowBot's BT meets the physical world →