Skip to content

2.7 Setlists, route joins and hooks

This covers how a Composer route freezes, how a Setlist runs its routes and commands in order, how the robot decides whether to drive to the next route’s start, and how hooks and recoveries run inside the auto. Read it before changing Composer, Setlist, RouteCommand, AutoRun or their Python and C++ twins, rust/core/src/auto_runtime.rs, rust/core/src/route_join.rs, or any file under tests/fixtures/sequencing/.

The deep rules are elsewhere and this chapter links to them: Architecture for the core sequencer, Wrapper conventions for hook semantics, Behavior parity and Setlist joins that flow for joins, and Ending early and robot actions for endWhen, giveUpAfter and runOnFailure.

Who does what

LayerOwnsFiles
Rust core, AutoRuntimeone route: leg order, phases, merged planning groups, junctions, triggers, fail cases, replans, the auto clockrust/core/src/auto_runtime.rs
Rust core, authoringfreeze-time validation and exit headings, the connecting drive’s legrust/core/src/authoring.rs (query, validate, cross_problem, connector), FFI tempo_authoring_query_v1, tempo_route_connector_v1
Rust core, join rulethe translation offset and heading testrust/core/src/route_join.rs
Binding, route commandruns one route’s runtime each loop, runs its hooks, reports arrival and blocking-phase endsJava com.tempo.wpi.RouteCommand, Python tempo/wpi/tempo_command.py, C++ cpp/src/internal/RouteSteps.cpp (RouteCommandCore)
Binding, Setlistthe step tree, compiled to a command tree each run; route steps, joins, whole-run commandsJava com.tempo.wpi.Setlist, Python tempo/wpi/setlist.py, C++ cpp/src/Setlist.cpp, cpp/src/internal/RouteSteps.cpp, TreeAssembly.h
Binding, run statethe auto clock origin, the join inputs, recoveriesJava com.tempo.wpi.AutoRun, Python tempo/wpi/_auto_run.py, C++ cpp/src/internal/AutoRun.h
Binding, join testthe same test as the core, in host mathJava com.tempo.wpi.RouteJoin, Python tempo/wpi/_route_join.py, C++ cpp/src/internal/RouteJoin.h

Within a route the Rust core drives every leg, and there is no host-side leg sequencer and no fallback. The module doc of auto_runtime.rs states the seam. WPILib commands never cross into the core, hooks travel as labels and come back as (segment, kind, index) references from AutoRuntime::drain_fired, the blocking waits end through AutoRuntime::notify_blocking_done, and host predicates (endWhen, Condition.when) arrive each tick as bits of AutoTickInputs. The order of steps in a Setlist (a route, then a command, then a when) is the compiled command tree’s order in the binding, and each route step inside it runs one core runtime.

A Setlist’s to(target) step is a route step whose Composer has no start pose (Wrapper conventions), so it never joins, and the route after it joins with its arrival tolerance like any other.

A Composer that is scheduled or started on its own runs as a one-drive Setlist (SetlistAccess.installAnonymousAuto and the FreshRootCommand installed in Setlist’s static block), so every route goes through the same route step.

Freezing a route

A Composer freezes the first time it is run, warmed or fingerprinted (Composer.freeze, under FreezeTransaction.MONITOR). prepareDefinition closes the open leg and sends the legs to the core as an authoring query with "op": "route" (CoreAuthoring.validate in Java, python/tempo/_authoring.py, cpp/src/Composer.cpp). authoring::validate returns a list of problems and the binding raises the first:

Problem codeRaised whenJavaPythonC++
packa .cross() id names no [[terrain]] entry (cross_problem; the message says whether the id is an avoid zone, another element, or unknown)TempoExceptionTempoExceptionstd::invalid_argument
missing_track_widtha leg’s Control resolves to a differential base, the leg has no trackM, and the configured track width is not positiveIllegalStateExceptionValueErrorstd::logic_error
missing_start, empty_routeno start pose (and no live start), or no completed legIllegalStateExceptionValueErrorstd::logic_error
statea live start with an odometry reset, or a differential leg with a rotation target, an aim, a waypoint heading where it does not stop, or a start bias off its headingIllegalStateExceptionRuntimeErrorstd::logic_error

The mapping is in com.tempo.internal.AuthoringQuery, tempo._authoring.query and cpp/src/internal/Authoring.h. The track-width message has one text per language (Language::missing_track). With Tempo configured, .cross() also asks the core at the call ("op": "cross", Composer.requireCrossableTerrain), so the freeze check catches a route authored before Tempo.configure(...). RouteSerializer.requireCrossingsInPack and RouteSerializer.requireTrackWidth are backstops for a spec that did not come through a Composer.

The same answer carries the route’s static exit heading (authoring::exit_heading), which the join test reads later. Every binding keeps it with the frozen route (Java’s RouteSection, C++‘s static_exit_heading_rad, Python’s definition key static_exit_heading_rad), so compiling a Setlist’s next run as a run ends asks the core nothing, but a connecting drive’s definition has none and asks. The freeze also resolves per-leg replanning (resolveLegReplanning), infers footprint extensions, prints the over-Speed.FULL line once (warnLimitsAboveFull), and builds the ComposerAccess.RouteSection that carries the last leg’s translationToleranceM and rotationToleranceRad and whether the first leg’s heading is free.

Freezing a Setlist

A Setlist freezes its tree once, and the checks that matter here are:

  • every route hook and whole-run hook must stay off the drivetrain. requireHooksOffTheDrivetrain (Java), _require_hooks_off_the_drivetrain (Python) and detail::require_hooks_off_the_drivetrain (C++) throw [Tempo] <hook> requires the drivetrain, which its route already drives. arriveWith is exempt, because its command takes the drivetrain over once the route stops driving. A hook factory whose command turns out to drive fails with factoryMessages.drivetrain in tests/fixtures/api/runnableAcceptance.json, and a hook Setlist with a drive or a drivetrain step fails with Setlist.HOOK_DRIVES;
  • mixing routes that mirror with routes that never flip fails (requireOneFrame);
  • a Python hook factory annotated to return a command, with no declared subsystems, fails (factoryMessages.undeclaredAtFreeze). A Java Supplier hook is read as it runs, since a value-returning action reaches the same overload;
  • a check given to then or a group fails (checkStep).

The refusal texts are in shared fixtures that all three binding suites read: tests/fixtures/api/setlistMessages.json for most, runnableAcceptance.json for factory refusals and commandWorkflow.json for checkStep.

Requirements are the union. A route command built for a Setlist calls RouteCommand.requireHooks, which sets inlineHooks and adds every hook’s requirements beside the drivetrain. The root (FreshRootCommand) requires definition.metadata.requirements, built by Metadata.union over the tree, so a hook cannot interrupt its own auto through the scheduler.

Running a Setlist

Each run builds a fresh command tree and a fresh AutoRun, and the run’s order of events is:

  1. The root’s first loop calls AutoRun.markStart(now), which is the auto clock.
  2. Each route step, as its drive starts, calls AutoRun.startsFirstRoute(). The first route of the run uses its authored reset policy and never connects, and every later one runs FORCE_NO_RESET and runs the join test.
  3. The route command builds or adopts its runtime, anchors the core’s clock to the auto’s start on its first tick (auto.coordination().anchorAutoClock(sharedRun.startS() - startTimeS), reaching AutoRuntime::set_auto_start_time through tempo_auto_set_auto_start), and drives.
  4. As a route or connecting drive ends, RouteCommand.finishRoute calls AutoRun.routeEnded(staticExitHeading, translationTol, rotationTol, flow) with its last leg’s arriveWithin tolerances, else the configured defaults.
  5. A native step that requires the drivetrain (Setlist.CommandLeaf, Python _CommandLeaf, C++ CommandLeafCore) calls AutoRun.driveCommandStarted(), which clears the tolerances to NaN, clears the flow and sets compareHeading true.

That is why Condition.matchTime counts from the auto’s start in every route, in nested Setlists and in hook Setlists. The Setlist’s own whole-run matchTime checks read run.startS() directly (Setlist.Check). The core starts its clock on the route’s first tick with or without a pose, so a late first pose does not move matchTime (Architecture covers the pose-loss rules). rust/core/tests/auto_clock_origin.rs pins the anchor through the C ABI.

Connecting drives

The decision on the robot

Before each route after the auto’s first, the route step compares the live pose with the route’s runtime-frame start. Java Setlist.RouteStep.connectorFromLivePose, Python _RouteStep._connector_from_live_pose and C++ RunStepCore::connector_from_live_pose do the same thing:

translation = run.joinTranslationTolerance  (NaN -> config default, 0.05 m)
rotation    = run.joinRotationTolerance     (NaN -> config default, 3 deg)
compare     = comparesHeading(run.compareHeading, nextRoute.entryHeadingFree)
connect     = coreConnects || needsConnector(live, start, compare,
                                             config.isDifferential(),
                                             translation, rotation, run.joinFlow)

The defaults are DEFAULT_TRANSLATION_TOLERANCE_M = 0.05 and DEFAULT_ROTATION_TOLERANCE_RAD = Math.toRadians(3.0) in java/src/main/java/com/tempo/config/TempoConfig.java, and defaultTolerance in routeJoins.json records the same pair.

needsConnector (Java and C++) and needs_connector (Python, Rust):

  • a pose with any non-finite component never connects;
  • the translation offset is the plain distance, or after a route that ended moving (flow set, finite positive speed) the parts of the offset along and across the travel beyond the last leg’s moving handover distance, combined as one distance (route_join::translation_offset);
  • an offset over tolerance + 1e-12 (SLACK) connects;
  • otherwise, with compare true and a holonomic drive, a wrapped heading error over tolerance + 1e-12 connects. A differential drive compares translation only, since its connecting drive cannot correct a heading alone.

comparesHeading(previousEndStatic, nextStartFree) is previousEndStatic && !nextStartFree, so the heading counts when the next route’s first waypoint names one, unless the last route ended on a dynamic heading. coreConnects is the case where the core already ended the last route moving into a drive to this start (flow[4] == 0.0), and that drive runs wherever the robot reads.

Building the drive

buildConnector (Java), _build_connector (Python) and build_connector (C++) mirror the live pose into the route’s authored frame when the route is flipped, ask the core for the one leg (tempo_route_connector_v1, authoring op connector), and run it as a FORCE_NO_RESET occurrence inside the route step, so its requirements and cancellation are the route’s. When the route’s first leg runs no runBefore, the connector flows into the route. A connector that cannot be built prints a [Tempo] line and the route runs from the live pose. The route step logs the join as a connects event (RouteLog.connect).

The core makes the same decision

The core applies the same rule when a route decides whether to end moving into the next drive (AutoRuntime::flow_into and flow_into_route, the tempo_auto_flow_into_v2 boundary), from the authored end of the route before. It ends at rest where the headings would be compared and miss, and for the exitStops cases. The editor preview makes the same joins (route_join_query in rust/wasm/src/lib.rs, flowJoins.ts in gui/web/src/features/autos/). The link and flow rules are in Setlist joins that flow and Architecture.

The shared table

tests/fixtures/sequencing/routeJoins.json (schema tempo.route-joins/v7) is one table every implementation reads:

SectionRowsRead by
cases: live, start, previous tolerance, compareHeading, differential, optional flow, expected connect52Rust tests/route_join_cases.rs, Java RouteJoinTest, Python test_route_joins.py, C++ RouteJoinTest.EverySharedCaseDecidesAsRecorded (cpp/tests/test_setlist_routes.cpp), the editor’s flowJoins.test.ts (rows with finite poses)
headingCompared: previous end fixed, free, dynamic or none against next start fixed or free8Rust, Java, Python and C++ (EverySharedHeadingCaseDecidesAsRecorded), and the editor for rows other than none
waypointHeadings: how a first waypoint classifies4Java ComposerDirectTest, Python test_rotation_locks.py, C++ test_composer.cpp
exitStops: whether a route flows into a next route whose first leg crosses terrain5Rust tests/route_flow.rs, Java SetlistLinksTest, Python test_setlist_links.py, C++ SetlistFlowTest.ARouteEndsAtRestBeforeAFirstLegThatStopsForACrossingHeading, the wasm crate’s tests, flowJoins.test.ts
connectingDriveEndings: how a connecting drive ended, and whether the run’s route drives, its runOnFailure starts and its runAfter runs5Java SetlistRunTest, Python test_setlist_runs.py, C++ SetlistRunTest.AFailedConnectingDriveFailsItsRunAsTheSharedTableSays

A null previous means no route precedes the join and defaultTolerance applies. Change a row only together with the rule in all four implementations, and the description string at the top of the file is the specification.

Hooks

Hook kinds reach the core as labels and come back through drain_fired as AutoFiredKind: RunDuring, Trigger, FailCase, ArriveWith and WindowEnd. The phase machine (AutoPhase) waits in PreBlocking and PostBlocking while the leg’s runBefore and runAfter hooks run, and the host ends each wait with notify_blocking_done. A leg handed to arriveWith is HandedOff until notify_handoff_done.

A route command built by Tempo (inlineHooks true) runs its hooks as part of itself, as a command group runs its members. RouteCommand.startHook initializes the hook directly, after AutoRun.blocker and the route’s own hookBlocker approve it. A hook that is the same command as, or shares a subsystem with, a running hook or recovery takes over from it unless that one is kCancelIncoming. Nothing reaches the scheduler, so a hook cannot cancel its auto. As the route ends, its hooks end with it (finishRoute). A RouteCommand built through the public constructors cannot see its hooks before it runs, requires the drivetrain alone, and schedules them, and that path is the !inlineHooks branch and scheduledHooks.

runBefore and runAfter hooks of one leg run one after another in written order, and a Setlist run’s whole-run runBefore and runAfter commands do too. Triggered whole-run hooks can overlap, because RunHooks.execute runs every running hook each loop. Wrapper conventions has the full rules: native actions and checks, waitUntil, finallyDo, runWhile windows, the 64-slot condition budget, and hook Setlists. tests/fixtures/sequencing/runWindows.json pins window, point-trigger and runAfter order across arrival, give-up and endWhen, read by NativeHooksDirectRunTest, test_native_hooks_e2e.py and test_native_hooks_e2e.cpp.

Recoveries and interruption

A leg’s fail case and a run’s whole-run runOnFailure are recoveries. They start in the auto (AutoRun.adopt), execute each loop after its steps, and can outlive the route that started them. When the auto’s steps finish with recoveries still running:

  • a root the scheduler runs directly ends, and AutoRun.handOff gives each running recovery its own AutoRun.RecoveryTail (Python RecoveryTail, C++ RecoveryTail in AutoRun.h), which requires only that recovery’s subsystems and carries on without initializing it again. A Setlist’s root schedules the tails in FreshRootCommand.end (Setlist.java), and RouteCommand.end does it only for a route that owns its own run;
  • a root running inside a larger command keeps running them to the end;
  • on the Commands v3 adapter the root stays alive with its requirement union until its recovery children end (Java command framework boundary).

Whichever way a route ends, RouteCommand.finishRoute cancels and closes its core runtime (AutoRuntime::cancel, after which ticks return zero speeds), ends any arriveWith command still driving and ends every hook still running. An interrupted auto ends everything it started. RouteCommand.end(true) clears the flow so the drivetrain receives zero speeds and ends every recovery (AutoRun.end), and none is handed off.

Frozen traces

tests/fixtures/sequencing/*.route.json and *.trace.json are host-recorded truth, where each trace is the per-tick sequencing a recorded route produced (phase order, leg order, firing order, tick counts, commands). No recorder for them exists in the repository, so their producer is independent of the code under test.

ReplayFileRoutes
Rust, through AutoRuntimerust/core/tests/sequencing_traces.rs, every_wrapper_trace_replays_identically_through_the_core_sequencer20 in ROUTES
Rust, through the tempo_auto_* C ABIthe same file, every_wrapper_trace_replays_identically_through_the_c_abithe same 20
Java, through JNAjava/src/test/java/com/tempo/SequencingTraceOracleTest.java, everyRouteReproducesItsRecordedTracethe same 20

The two further files, geometric and pathTight, use removed control modes, and frozen_routes_with_removed_control_modes_are_rejected checks that route_from_json refuses them. Discrete facts compare exactly and floats to 1e-9. The Rust replay reports every diverging route with its first differing field.

TEMPO_REGEN_TRACES=1 fails the Java oracle with an explanation and rewrites nothing. A trace changes only by a hand edit, in a commit that names the behavior that moved, reviewed as code (Fixtures and when to regenerate them). TEMPO_REGEN_FIXTURES=1 on the Rust conformance test is a different switch and does not touch these files.

Tests to run

Shell
cd rust && cargo test -p tempo-core --test sequencing_traces --test route_join_cases --test route_flow --test auto_clock_origin
cd java && sh gradlew test --tests 'com.tempo.SequencingTraceOracleTest' --tests 'com.tempo.wpi.RouteJoinTest' --tests 'com.tempo.wpi.SetlistLinksTest'
cd python && sh run-suites.sh
cd cpp/build && ctest -R 'RouteJoinTest|SetlistFlowTest'

run-suites.sh is the only Python gate, because a bare python -m pytest skips the tempo/wpi tests behind importorskip("commands2"). The C++ tests link the libtempo_core.so copied into cpp/build (see Building and testing).

Changing sequencing

  • A change to the join rule moves route_join.rs, RouteJoin.java, _route_join.py, RouteJoin.h and the editor’s flowJoins.ts together, with new rows in routeJoins.json.
  • A change to what resets the join inputs (routeEnded, driveCommandStarted) moves all three AutoRun classes.
  • A change that moves a recorded trace is a hand edit of the trace in the same commit, named in its message.
  • A new freeze refusal adds its text to setlistMessages.json or the language table in authoring.rs, and a case in each binding’s suite.
esc

Loading search...