3.11 Build an auto from routes
A Setlist runs routes and commands one after another as one auto. This example scores the
preload at REEF_IR, drives to STATION_LEFT with the intake running, and then keeps
intaking for up to 1.5 s.
toReefIR and toStation are Composer routes on the
REEFSCAPE 2025 pack. The routes in the later
examples are named <start>To<end>, like stationToKr.
A two-route auto
import static edu.wpi.first.units.Units.Seconds;
import com.tempo.wpi.Setlist;
// Once at startup, after Tempo.configure(...) and the routes.
Setlist leftCoral = Setlist.named("Left coral")
.drive(toReefIR) // toReefIR sets resetOdometry(true)
.then(superstructure.scoreL4())
.drive(toStation)
.run(0, 1, intake.intakeCommand()) // for this run of toStation only
.then(intake.intakeCommand().withTimeout(Seconds.of(1.5)));from tempo.wpi import Setlist
# Once at startup, after Tempo.configure(...) and the routes.
left_coral = (Setlist.named("Left coral")
.drive(to_reef_ir) # to_reef_ir sets reset_odometry(True)
.then(superstructure.score_l4())
.drive(to_station)
.run(0, 1, intake.intake_command()) # for this run of to_station only
.then(intake.intake_command().withTimeout(1.5)))#include <tempo/wpi/Setlist.h>
// intakeCommand_ is a stored frc2::CommandPtr member; a run's commands borrow it.
tempo::Setlist left_coral = tempo::Setlist::named("Left coral")
.drive(to_reef_ir) // to_reef_ir sets reset_odometry(true)
.then(superstructure.ScoreL4())
.drive(to_station)
.run(0, 1, intakeCommand_.get()) // for this run of to_station only
.then(intake.IntakeCommand().WithTimeout(1.5_s));.run(0, 1, ...) after a drive runs the command from 0% to 100% of the way along that route
and interrupts it when the drive ends. The last step starts the intake again for the wait at
the station.
Build routes and Setlists once, after Tempo.configure(...), because Composer.startAt throws
before that.
Setlist.named("Left coral") makes an auto that shows up on the
auto chooser. new Setlist() (Setlist() in Python, a
default-constructed tempo::Setlist in C++) makes one that isn’t listed. You can use it as a
step in another Setlist, as a hook, or run
it on its own. Schedule and cancel shows how to start either kind.
A Setlist freezes the first time it’s used. Freezing checks the whole auto and throws on errors like two commands that run at the same time and use the same subsystem. After that the Setlist can’t be edited.
Steps
Each step starts when the one before it finishes.
drive(route)runs a route. The step finishes when the route ends and itsrunAftercommands finish.to(target)drives to one pose from wherever the robot is (Drive to a pose).then(command)runs a command until it finishes, and the command can require the drivetrain.thenalso takes another Setlist, or a plain method, which runs once.wait(time)waits for a duration.waitUntil(check, timeout)(wait_untilin Python and C++) waits until the check returns true or the timeout passes. The timeout is optional, and the next step runs either way.
finallyDo(action) (finally_do in Python and C++) isn’t a step. It runs once when the Setlist
ends, whether its steps finished or it was interrupted. Write it last, because .run(...) and
the other per-run commands can’t follow it.
A drivetrain command like a vision align goes in a then step, and the next drive(route)
starts from wherever the align left the robot. A command that runs during a drive goes on the
drive with .run(...), and it can’t require the drivetrain.
Condition.matchTime counts from the start of the auto in every route of a Setlist. The
Setlist reference has the arguments and errors for each step.
Drive to a pose
var scoreAndLeave = Setlist.named("Score and leave")
.drive(toReefIR)
.then(superstructure.scoreL4())
.to(STATION_LEFT)
.run(0.5, intake.intakeCommand());score_and_leave = (Setlist.named("Score and leave")
.drive(to_reef_ir)
.then(superstructure.score_l4())
.to(STATION_LEFT)
.run(0.5, intake.intake_command()))// intakeCommand_ is a stored frc2::CommandPtr member.
tempo::Setlist score_and_leave = tempo::Setlist::named("Score and leave")
.drive(to_reef_ir)
.then(superstructure.ScoreL4())
.to(STATION_LEFT)
.run(0.5, intakeCommand_.get());to(target) drives from wherever the robot is to the target, and the path is planned when the
step starts. There’s no connecting drive before it, and it
never resets odometry. In the example, .run(0.5, ...) starts the intake command once the
robot is halfway along the drive.
The target is written like a waypoint in a Composer’s to(...), and a
Bias can follow it. It’s written
for blue and mirrored on red. It can also be a function that returns the target, the same as in
Tempo.to, and a function’s target isn’t mirrored.
Commands written after to(target) work the same as after drive(route). In a group, write
Step.to(target).
The step uses the limits and tolerances from your config. If you want different limits, an
arrival or more waypoints, build a Composer and use drive(route).
Groups
import com.tempo.wpi.Step;
var stationCycle = Setlist.named("Station cycle")
.deadline(Step.drive(toStation).at(1).run(0.75, intake.intakeCommand()),
superstructure.stow())
.parallel(stationToKr, superstructure.prepareL4())
.then(superstructure.scoreL4());from tempo.wpi import Step
station_cycle = (Setlist.named("Station cycle")
.deadline(Step.drive(to_station).at(1).run(0.75, intake.intake_command()),
superstructure.stow())
.parallel(station_to_kr, superstructure.prepare_l4())
.then(superstructure.score_l4()))auto station_cycle = tempo::Setlist::named("Station cycle")
.deadline(tempo::Step::drive(to_station).at(1).run(0.75, intakeCommand_.get()),
superstructure.Stow())
.parallel(station_to_kr, superstructure.PrepareL4())
.then(superstructure.ScoreL4());sequence runs its members in order. parallel runs them together until all of them finish,
and race until the first one finishes. deadline runs until the member listed first
finishes, then interrupts the rest. In this example the drive is listed first, so stow() is
interrupted if it’s still running when the drive ends.
A member can be a Composer route, a command, a Setlist, a plain method, or Step.drive(route)
with commands for that one drive.
In Java a method reference needs a cast to be used as a member, as in
(Runnable) intake::stop.
In Python, a callable that returns a command runs that command. The Setlist can’t read its
subsystems ahead of time, so list them with requirements=[...] on the group.
Members that run at the same time can’t use the same subsystem, and that includes the hooks on their routes. This is checked when the Setlist is frozen, and the error names both members.
Branch on a condition
Setlist scoreFromPickup = new Setlist()
.drive(pickupToKr).run(0, 1, superstructure.prepareL4())
.then(superstructure.scoreL4());
Setlist groundIntake = Setlist.named("Ground intake left")
.drive(toReefIR).then(superstructure.scoreL4())
.drive(irToPickup).run(0, 1, intake.intakeCommand()).endWhen(intake::hasPiece)
.when(intake::hasPiece, scoreFromPickup)
.otherwise(pickupToStation);score_from_pickup = (Setlist()
.drive(pickup_to_kr).run(0, 1, superstructure.prepare_l4())
.then(superstructure.score_l4()))
ground_intake = (Setlist.named("Ground intake left")
.drive(to_reef_ir).then(superstructure.score_l4())
.drive(ir_to_pickup).run(0, 1, intake.intake_command()).end_when(intake.has_piece)
.when(intake.has_piece, score_from_pickup)
.otherwise(pickup_to_station))// prepare_ and intakeCommand_ are stored frc2::CommandPtr members.
auto has_piece = [this] { return intake.HasPiece(); };
tempo::Setlist score_from_pickup = tempo::Setlist()
.drive(pickup_to_kr).run(0, 1, prepare_.get())
.then(superstructure.ScoreL4());
tempo::Setlist ground_intake = tempo::Setlist::named("Ground intake left")
.drive(to_reef_ir).then(superstructure.ScoreL4())
.drive(ir_to_pickup).run(0, 1, intakeCommand_.get()).end_when(has_piece)
.when(has_piece, score_from_pickup)
.otherwise(pickup_to_station);In the example, endWhen(intake::hasPiece) ends the drive to the pickup as soon as the intake
has a coral, and when then reads the same check to pick the next step.
when(check, a) reads the check once, when the auto gets to it, and runs a if it’s true.
otherwise(b) right after it runs b if the check is false. With no otherwise, a false
check skips the step. Each side can be anything a group takes, including a single route.
The check can be a method that returns a boolean, Condition.matchTime(t) or
Condition.when(check). Other conditions throw. The auto holds the subsystems of both sides
for its whole run.
Commands for this run only
var groundCycle = Setlist.named("Ground cycle")
.drive(irToKr)
.run(0, 1, superstructure.stow()) // the whole run
.at(2)
.runBefore(intake.deploy()) // the drive to waypoint 2
.run(0.75, intake.intakeCommand())
.endWhen(intake::hasPiece)
.at(3)
.runAfter(superstructure.scoreL4());ground_cycle = (Setlist.named("Ground cycle")
.drive(ir_to_kr)
.run(0, 1, superstructure.stow()) # the whole run
.at(2)
.run_before(intake.deploy()) # the drive to waypoint 2
.run(0.75, intake.intake_command())
.end_when(intake.has_piece)
.at(3)
.run_after(superstructure.score_l4()))// stow_, deploy_, intakeCommand_ and score_ are stored frc2::CommandPtr members.
auto ground_cycle = tempo::Setlist::named("Ground cycle")
.drive(ir_to_kr)
.run(0, 1, stow_.get()) // the whole run
.at(2)
.run_before(deploy_.get()) // the drive to waypoint 2
.run(0.75, intakeCommand_.get())
.end_when([this] { return intake.HasPiece(); })
.at(3)
.run_after(score_.get());Commands written after drive(route) apply only to that step. The route itself doesn’t change,
and other steps that drive it don’t get them. You can use the
hooks runBefore, run, runWhile and runAfter, and the
failure calls endWhen, giveUpAfter and runOnFailure.
Failure handling for one run
covers what the failure calls do over a whole run.
Before any .at(n), a command covers the whole route and fractions count along the whole path.
After .at(n) it applies to the drive to waypoint n. Waypoints are counted from 1, the same
way Tempo’s GUI numbers them, and the start pose isn’t one of them. In the example, irToKr has
three waypoints, where waypoint 2 is the floor pickup and waypoint 3 is REEF_KR.
The remaining, passed, entered and exited conditions measure
one waypoint’s drive, so they need an .at(n) first. The
Setlist reference has what each call does over
the whole run and after .at(n).
then, wait, waitUntil and the group calls always start a new step, so .waitUntil(...)
after a drive waits once the drive has finished. To hold the robot on a check before or
after one drive, pass the check to runBefore or runAfter.
In Python that’s run_before(wait_until=check) or run_after(wait_until=check).
Between routes: connecting drives
Before each route after the first, the robot compares its pose with the start of the route. If it’s outside the arrival tolerance of the route that just ended, it drives to the start first. That extra drive is the connecting drive.
The tolerance is the arriveWithin of the previous route’s last waypoint. If that waypoint
doesn’t set one, it’s the tolerance set with TempoConfig.withTolerance(...), 5 cm and 3
degrees unless changed. The connecting drive uses the robot’s limits from your config and ends
at the route’s start heading. If it fails,
the run fails and its
route isn’t driven.
The first route has no connecting drive. It resets odometry if it was built with
resetOdometry(true), and later routes never reset odometry.
When two drive steps follow each other, the robot keeps moving from one route into the next.
It stops between them when the first route ends on Arrival.STOP or has a runAfter, when the
next step isn’t a drive, and in a few other cases. The
Setlist reference lists every case, and it has how the
tolerance is compared and how the speed at the join is set.
Blue and red routes can be mixed in one Setlist. Mixing them with neutral routes fails when the Setlist is frozen.
If it fails…
The robot was too far from the next route’s start, or facing too far from its start heading, when the route before it ended. The distance and angle allowed are the arrival tolerance of the previous route’s last leg. Start the next route where the last one ends, or widen arriveWithin on that leg.
Two members that run at the same time use the same subsystem, counting the hooks on their routes. The error names both. Run one of them in a sequence instead.
Blue and red routes are mixed with neutral routes. Give every route in the auto a blue or red origin, or make all of them neutral.