Software · Controls

Behavior Tree Lab

Watch a behavior tree drive a pretend robot, one tick at a time.

Step 1 of 6

The tree

RUNNINGSUCCESSFAILUREIDLE t = 0.00 s · tick 0 · tree IDLE
Loading the Arborist viewer…

More controls

Robot

2026 field, blue half
Robot stateAUTO
Fuel scored0
More readouts
Wanted stateAUTO
Fuel held8
IntakeSTORE
ShooterIDLE
path being followed other paths in the tree fuel
Show the log

Tree XML

The same files Arbor opens
More: copy, download, node list

The download is an Arbor project: bt_project.json, nodes.xml and trees/. Unzip it and open the folder in Arbor.

Go deeper

Things to try
  1. One node stays orange forever. On Drive, aim, shoot, blind the camera. RetryUntilSuccessful asks forever. That is why Pickup and score wraps it in a Timeout.
  2. Stuck behind a robot. Tick "Another robot blocks the path". FollowTrajectory gives up after max_paused_sec (3 s) and the Sequence fails. Wrap it in <ForceSuccess> and the auto carries on.
  3. ParallelDeadline. In the Real auto, watch DriveP1: when the path ends, IntakeOnEvent is halted if it is still waiting. Then try a middle_wait_msec of 0 (under More readouts).
  4. Reactive vs. plain. Change a Sequence to ReactiveSequence. Every tick starts from the first child, and finished children are reset, so Drive path starts over and over. Reactive is for conditions, not steps.
  5. Typos are errors. Change AIM to AIMM, or add a node that doesn't exist. The lab marks the node and won't run it.
What the four colours mean
  • RUNNING not done yet, ask again next tick.
  • SUCCESS done, and it worked.
  • FAILURE done, and it didn't work.
  • IDLE not started yet, halted, or reset by its parent. After a parent finishes, its children go back to IDLE; the viewer keeps their last result, faded, until the next run.

The tree is drawn by Arborist, the viewer inside Arbor, so it looks exactly like Arbor's live view of the real robot.

The pretend robot

Trees only ask for a state with SetWantedState (instant). The robot's state machine decides when it is really there, which IsSystemState checks. It is written the way our RobotContainer is: every condition in handleStateTransition(), and updateLogic() only asks subsystems for states.

handleStateTransition():
  switch (wanted):
    AIM   -> system = aimed ? AIM : AIMING
    SHOOT -> system = ready ? SHOOT_FEED
                            : SHOOT_WAIT
    else  -> system = wanted

updateLogic():
  switch (system):
    AIMING, AIM -> shooter AIMING
    SHOOT_WAIT  -> shooter SHOOT
    SHOOT_FEED  -> shooter SHOOT, intake SQUEEZE
    INTAKE      -> intake INTAKE
    AUTO        -> nothing (the auto
                   sets subsystems)

Aiming takes 0.8 s and needs the camera, except right in front of the hub. The flywheel takes 0.6 s to spin up. The robot is never in SHOOT itself, so IsSystemState SHOOT never succeeds; that is why ShootFor uses a Sleep. The AIMING step state is made up for this lab. The robot runs each 20 ms loop before the tree, and the auto period ends at 20 s.

Read more in the docs