Skip to content
Tempo on GitHub (opens in a new tab)

4.13 Setlist

A Setlist builds one auto from Composer routes and WPILib commands. The guide is Build an auto from routes.

Create

approach is the route from the Composer example.

Java
import static edu.wpi.first.units.Units.Seconds;

import com.tempo.wpi.Setlist;

var match = Setlist.named("Left coral approach")
    .drive(approach)
    .wait(Seconds.of(0.25))
    .then(superstructure.scoreL4());
var matchAuto = match.command();
Python
from tempo.wpi import Setlist

match = (Setlist.named("Left coral approach")
    .drive(approach)
    .wait(0.25)
    .then(superstructure.score_l4()))
match_auto = match.command()
C++
#include <tempo/wpi/Setlist.h>

auto match = tempo::Setlist::named("Left coral approach")
    .drive(approach)
    .wait(units::second_t{0.25})
    .then(superstructure.ScoreL4());
auto match_auto = tempo::wpi::Setlist::command(match);

C++ has two classes named Setlist. tempo::Setlist builds the auto and tempo::wpi::Setlist is the WPILib side, with command(setlist). Its header, <tempo/wpi/Setlist.h>, includes <tempo/Setlist.h> and also declares tempo::wpi::configure(...).

ConstructorRegisters on TempoAutos.chooser()Command name
Setlist.named(name) (tempo::Setlist::named in C++)Yesname
new Setlist() (Setlist() in Python, default-constructed in C++)NoSetlist

A blank or null (None) name is refused. An unnamed Setlist can run as a step, as a hook when it doesn’t drive, or on its own.

Steps

Python and C++ spell waitUntil as wait_until.

StepRunsMoves on when
drive(route)A Composer route, after a connecting drive when the robot isn’t at the route’s startThe run ends and its runAfter commands finish
to(target)One leg from the robot’s pose to the target, the same as drive(Tempo.to(target))The run ends and its runAfter commands finish
then(command)A WPILib commandIt finishes
then(setlist)Another Setlist, in placeIts last step finishes
then(action)A function with no result, once (a Java Runnable, a Python callable or a C++ lambda)It returns
wait(time)NothingThe time passes
waitUntil(check[, timeout])NothingThe check returns true, or the timeout passes
Languagewait and the waitUntil timeout
Javawait takes a Time (Seconds.of(0.25)), or an int or double of seconds, and the waitUntil timeout takes a Time only. A long calls Java’s own Object.wait(long), which is not a step, so don’t pass one.
PythonA number of seconds. A wpimath.units time is already seconds
C++units::second_t or a std::chrono::duration. A bare number does not compile

to(target) takes the targets a Composer’s to(...) takes. A Bias can follow any of them except a function.

Languageto targets
JavaPose2d, Translation2d, x, y, x, y, Rotation2d, a PoseSupplier or a Supplier<Translation2d>
PythonA pose, a point, x, y, x, y, heading with the heading in radians or a Rotation2d, or a callable
C++Pose2d, Translation2d, x, y, x, y, heading_rad, or a function that returns an optional of either

A target off the field throws when to is called, the same as in a Composer. A heading that isn’t finite throws [Tempo] a waypoint heading must be a finite angle; got {value}. The step has one waypoint, so .at(2) fails the freeze.

A negative or non-finite time throws wait duration must be finite and non-negative. A waitUntil timeout is not a failure.

  • then(factory) in Java and Python takes a lambda that returns a command. The command is made when the auto reaches the step. then(factory, requirements...) (Python requirements=) declares its subsystems.
  • A nested Setlist shares the auto’s clock, connecting drives and its one odometry reset. A Setlist can’t contain itself.
  • A runOnce command finishes at once. A startEnd command never finishes, so it belongs in a group or a runWhile.

C++ then and group members take ownership of a moved CommandPtr.

The auto requires every subsystem its steps and commands use, for its whole run. When the steps finish while runOnFailure recoveries are still running, an auto the Commands v2 scheduler runs directly ends, and each recovery continues in its own command that requires only its subsystems. These autos keep running until their recoveries end instead:

  • A Commands v3 auto, which holds its requirements until then.
  • An auto started with start() and run by Tempo.update(), without the command scheduler.
  • An auto wrapped in a decorator such as withTimeout(...), or placed inside a command group.

Groups

GroupMoves on when
sequence(a, b, ...)The last step finishes
parallel(a, b, ...)Every step finishes
race(a, b, ...)Any one step finishes, and the others are interrupted
deadline(leader, b, ...)The leader, the step listed first, finishes, and the others are interrupted. Takes at least one step besides the leader.

A member is a Composer route, a command, a Setlist or an action. To give a drive in a group its own per-run hooks, write it as Step.drive(route) or Step.to(target), which take the same hooks as Setlist.drive(route). Any other type throws at the call (IllegalArgumentException in Java, TypeError in Python) or fails to compile in C++. Members that run at the same time must not share a requirement.

In Python a member can be a callable that returns a command, with requirements= declaring what it requires.

Java
import com.tempo.Condition;
import com.tempo.wpi.Setlist;
import com.tempo.wpi.Step;

var stationCycle = Setlist.named("Left station cycle")
    .deadline(Step.drive(irToStation).at(1).run(Condition.progress(0.75), intake.intakeCommand()),
              superstructure.stow())
    .parallel(new Setlist().drive(stationToKr), superstructure.prepareL4())
    .then(superstructure.scoreL4());
Python
from tempo import Condition
from tempo.wpi import Setlist, Step

station_cycle = (Setlist.named("Left station cycle")
    .deadline(Step.drive(ir_to_station).at(1).run(Condition.progress(0.75), intake.intake_command()),
              superstructure.stow())
    .parallel(Setlist().drive(station_to_kr), superstructure.prepare_l4())
    .then(superstructure.score_l4()))
C++
#include <tempo/Condition.h>
#include <tempo/wpi/Setlist.h>

auto station_cycle = tempo::Setlist::named("Left station cycle")
    .deadline(tempo::Step::drive(ir_to_station).at(1)
                  .run(tempo::Condition::progress(0.75), intakeCommand_.get()),
              superstructure.Stow())
    .parallel(tempo::Setlist().drive(station_to_kr), superstructure.PrepareL4())
    .then(superstructure.ScoreL4());

irToStation and stationToKr are Composer routes, built like approach in the Composer example.

intakeCommand_ is a stored CommandPtr member, and the hook borrows its pointer.

A group locks the Step.drive it accepts, and a later edit throws [Tempo] this step is already part of an auto; start a new Step.drive. A locked step can be reused as it stands.

Branches

when(check, a).otherwise(b) checks once, when the auto reaches it, and runs a or b. Without otherwise a false check runs nothing. otherwise must directly follow when.

  • The check is a BooleanSupplier (a Python callable, a C++ std::function<bool()>), Condition.matchTime(t) or Condition.when(...). Any other Condition throws at the call.
  • A missing check throws NullPointerException, ValueError or std::invalid_argument.
  • The freeze checks both sides, and the auto requires the subsystems of both.

Per-run hooks and .at(n)

Commands written after drive(route) are hooks for that one use of the route, and the Composer isn’t changed. Before at(n) they cover the whole run. After it they apply to the drive to waypoint n, counting from 1, until the next at(...) or step. wait, waitUntil and then written after a drive are new steps and not hooks of that drive.

In the example irToKr is a Composer route with three waypoints.

Java
var groundCycle = Setlist.named("Ground cycle")
    .drive(irToKr)
        .run(0, 1, superstructure.stow())
        .at(2)
            .runBefore(intake.deploy())
            .run(Condition.progress(0.75), intake.intakeCommand())
            .endWhen(intake::hasPiece)
        .at(3)
            .runAfter(superstructure.scoreL4());
Python
ground_cycle = (Setlist.named("Ground cycle")
    .drive(ir_to_kr)
        .run(0, 1, superstructure.stow())
        .at(2)
            .run_before(intake.deploy())
            .run(Condition.progress(0.75), intake.intake_command())
            .end_when(intake.has_piece)
        .at(3)
            .run_after(superstructure.score_l4()))
C++
// the commands are stored members; a run's commands borrow their pointers.
auto ground_cycle = tempo::Setlist::named("Ground cycle")
    .drive(ir_to_kr)
        .run(0, 1, stow_.get())
        .at(2)
            .run_before(deploy_.get())
            .run(tempo::Condition::progress(0.75), intakeCommand_.get())
            .end_when([this] { return intake.HasPiece(); })
        .at(3)
            .run_after(score_l4_.get());
CommandWhole runAfter at(n)
runBefore(cmd)Before the run and its connecting driveBefore the drive to waypoint n
run(f, cmd), run(from, to, cmd)Fractions of the route’s whole path, not counting the connecting driveFractions of that drive
run(condition, cmd)progress, matchTime, when, inside, near or a combinationAny condition Composer.run takes
runWhile(condition, cmd)From the connecting drive until this run endsFrom the drive to waypoint n until this run ends
runAfter(cmd)Once the run ends, unless it gave up or its drive failed (a failed build or start, a fault partway through or a failed last leg). A last waypoint that is only missed still runs it (one run in a Setlist)Once that drive ends, unless it failed
endWhen(check)Ends the runEnds that drive, and the route goes on
giveUpAfter(time)Connecting drive includedThat drive
runOnFailure(cmd)Once, at the first leg that fails or is missed, or when the run gives up or its drive failsWhen that drive fails. On a fault, only if that leg was still driving

Python and C++ spell these run_before, run_while, run_after, end_when, give_up_after and run_on_failure.

giveUpAfter takes a Time in Java and seconds in Python and C++.

runBefore(check) and runAfter(check) in Java, and the same calls with a lambda returning bool in C++, hold the robot still until the check is true.

Python writes this as run_before(wait_until=check) and run_after(wait_until=check). They hold the robot still until the check is true.

These commands merge with the route’s own commands for the same leg. They run after the route’s. An endWhen from either one ends the leg, and the shorter give-up time applies.

CauseMessage
A command before any drive[Tempo] a run's commands follow .drive(path); write .drive(path) first
at(0)[Tempo] .at(n) counts waypoints from 1; got 0
A waypoint the route lacks (freeze)[Tempo] .at(4) is not a waypoint of the route from (1.00, 2.00), which has 3 waypoints
A remaining, passed, entered or exited condition before at(n)[Tempo] a remaining condition is measured along the drive to one waypoint; pick the waypoint with .at(n) first

When a runOnFailure recovery and a runAfter command in the same scope share a subsystem, the freeze prints a warning, and the runAfter command interrupts the recovery when it starts.

Running

Python and C++ spell isFinished, finallyDo, getStartPose and getEndPose as is_finished, finally_do, get_start_pose and get_end_pose.

MemberEffect
command()A fresh WPILib Command per call (tempo::wpi::Setlist::command(setlist) in C++)
warmup()Plans the next run while disabled, for an auto picked on a chooser other than TempoAutos
schedule(), start()Run it, with or without the scheduler
isFinished(), cancel()Whether the latest run, from schedule() or start(), has ended, and the call that ends it
getStartPose(), getEndPose()The first route’s start and the last route’s end, for the alliance the robot is on (Start and end poses). Empty when the Setlist drives no route, when that route’s own pose is empty, when the sides of a when would start or end in different places, or when the last route is in a race or is a deadline’s companion
finallyDo(action)Runs once as the Setlist ends, however it ends, after recoveries are handed off. Several run in the order written. Write it last, because it belongs to the whole Setlist and per-run commands can’t follow it
Setlist.sharedBindings() (Java)The Bindings record Tempo.configure(...) installed: driveRequirement(), poseGetter(), poseSetter(), velocityRunner(), robotRelativeSpeeds()

Each run is one auto with one clock, started on its first loop. Condition.matchTime counts from it in every route, including nested Setlists.

Route joins

When the robot isn’t at a route’s start, Tempo adds a connecting drive that takes it there first. The first route started applies its resetOdometry setting and has no connecting drive, and neither does a route with no start pose. Before each later route, the robot’s pose is compared with the route’s start for the alliance the robot is on. The guide is Between routes.

CaseRule
ToleranceThe last leg’s arriveWithin of the route that ended, else the tolerance set with TempoConfig.withTolerance(...), 5 cm and 3 degrees unless changed
A drivetrain command ran since the last routeThe TempoConfig.withTolerance(...) tolerance
Differential drive, a last route ending on a dynamic heading (an aim or a heading supplier), or a next route whose first waypoint has no headingTranslation only
The route before ended movingAn offset from the start of up to the last leg’s replanning threshold doesn’t count. Only the part of the offset beyond the threshold is compared with the tolerance. The heading is compared as usual
Outside toleranceDrive to the start first, ending at its heading, at the robot’s configured limits, with the route’s alliance and avoid settings
Connecting drive failsThe run fails

Join speed

When a drive step is followed directly by another drive step in the same Setlist, the robot doesn’t stop between them unless a case in the list below applies. The next step starts on the loop the first route ends.

  1. The exit speed starts as the last waypoint’s through fraction times the lower of the two legs’ top speeds. The through fraction is the number given to Arrival.through(...), and Arrival.THROUGH is 1.
  2. That speed is lowered to the speed both routes reach through the turn into the next route or connecting drive.
  3. A sharp turn is rounded. A turn that nearly reverses direction stops, and so does a turn where rounding is no faster than stopping (corners).
  4. The next route is never entered faster than its first leg’s speed limit allows.

A connecting drive entered moving goes into its route without stopping.

The robot stops at the join when:

  • the last waypoint is STOP or has a pause
  • the last leg has runAfter, waitUntil, arriveWith, a custom controller or output filter, or a terrain crossing with a heading
  • the step has a runAfter, or the next step has a whole-run or first-leg runBefore
  • the next step doesn’t start with a drive (a command, wait, waitUntil, parallel, race, deadline or branch)
  • the next route has no start pose, or reads a target from a supplier at start
  • the next route’s first leg has stayWithin, or a terrain crossing with a heading
  • headings are compared and the next route starts outside the heading tolerance, and then a connecting drive turns the robot
  • the last leg gave up, failed or ended early
  • it is the last route of the auto

A nested Setlist or a sequence whose first step is a drive counts as that drive, and its last drive joins the step after it the same way, unless the nested Setlist has a finallyDo. A connecting drive stops before a route whose first leg has runBefore or stayWithin.

The connecting drive is part of the route’s step, so it has the same requirements and group. It runs after the whole-run runBefore commands. It has no hooks of its own, and a whole-run giveUpAfter counts its time. It can stall like any leg. Its console line calls it leg 1 with the route’s start as the target.

If a route’s last leg stalls short of its heading and the next route’s first waypoint has a heading, the connecting drive is a turn in place. If the same obstruction holds, that turn ends on the heading stall check after another 2 s. Start the next route at a heading the robot can reach, or leave its first waypoint’s heading unset.

Routes authored for blue and for red can mix. Mixing either with a route whose originAlliance is NEUTRAL, which never mirrors, fails the freeze.

Freeze and conflicts

A Setlist freezes the first time it is used (command(), schedule(), start(), warmup(), the chooser’s planning while disabled, or a simulation). A nested Setlist freezes when the Setlist around it does. If the freeze fails the Setlist can still be edited, and after it passes, edits throw Setlist definition is frozen and cannot be modified. The freeze refuses:

  • steps that run at the same time and share a requirement, hooks included. The error names both
  • a hook, or a command attached to a run, that requires the drivetrain
  • a check given as a step: [Tempo] a check given as a step would run once and not wait; wait for it with .waitUntil(check)

Python refuses a check only when the callable is annotated -> bool. A check with no annotation is taken as an action, so it runs once and the auto moves on.

Interrupting the auto cancels its running children, hooks and recoveries, and the Setlist can be run again afterward.

esc

Loading search...