3.13 Schedule and cancel
Every Composer route and every Setlist is an Auto, with
schedule(), start(), isFinished() (is_finished() in Python and C++), cancel() and
warmup(). The examples run leftCoral, the Setlist from
Build an auto from routes.
With the command scheduler
import com.tempo.Auto;
private Auto auto;
// Once at startup, after Tempo.configure(...) and the routes.
auto = leftCoral;
@Override public void autonomousInit() { auto.schedule(); }
@Override public void teleopInit() { auto.cancel(); }def robotInit(self):
# after Tempo.configure(...) and the routes
self.auto = left_coral
def autonomousInit(self):
self.auto.schedule()
def teleopInit(self):
self.auto.cancel()void Robot::AutonomousInit() { left_coral.schedule(); }
void Robot::TeleopInit() { left_coral.cancel(); }Each schedule() call starts a fresh run of the auto. The scheduler runs it every loop and
cancels it when the robot is disabled. Build the auto after Tempo.configure(...).
isFinished() and cancel() act on the latest run. isFinished() is false while the auto
runs and true once it has ended, whether it finished or was canceled.
A route or Setlist also has command(), which returns the auto as a command without
scheduling it. Use it to put the auto in a command group or wrap it in a decorator. The Auto
type doesn’t have it, so call it on the route or Setlist.
In C++ the command is tempo::wpi::Setlist::command(setlist) for a Setlist
(the WPILib-side class) and
tempo::wpi::command(route) for a route.
Without the command scheduler
If your robot doesn’t use the command scheduler, leave the subsystem out of
Tempo.configure(...), start the auto with start(), and call Tempo.update() every loop:
| Command-based | Without the scheduler | |
|---|---|---|
| Setup | Tempo.configure(getPose, resetPose, getRobotRelativeSpeeds, runVelocity, config, drive) | Tempo.configure(getPose, resetPose, getRobotRelativeSpeeds, runVelocity, config) |
autonomousInit() | auto.schedule() | auto.start() |
robotPeriodic() | CommandScheduler.getInstance().run() | Tempo.update() |
teleopInit() | auto.cancel() | auto.cancel() |
disabledInit() | the scheduler cancels it | Tempo.stop() |
drive is the drivetrain subsystem.
In C++ the setup call is tempo::wpi::configure(...). A command-based robot passes {this}
as the last argument and a robot without the scheduler leaves it out. The other rows are
CommandScheduler::GetInstance().Run(), tempo::Tempo::update() and tempo::Tempo::stop().
import com.tempo.Auto;
import com.tempo.Tempo;
import edu.wpi.first.wpilibj.TimedRobot;
public class Robot extends TimedRobot {
private final Auto auto;
public Robot() {
// The drivetrain, Tempo.configure(...) and the routes come first.
auto = leftCoral;
}
@Override public void robotPeriodic() { Tempo.update(); }
@Override public void autonomousInit() { auto.start(); }
@Override public void teleopInit() { auto.cancel(); }
@Override public void disabledInit() { Tempo.stop(); }
}import wpilib
from tempo import Tempo
class Robot(wpilib.TimedRobot):
def robotInit(self):
# after Tempo.configure(...) and the routes
self.auto = left_coral
def robotPeriodic(self):
Tempo.update()
def autonomousInit(self):
self.auto.start()
def teleopInit(self):
self.auto.cancel()
def disabledInit(self):
Tempo.stop()#include <tempo/Tempo.h>
void Robot::RobotPeriodic() { tempo::Tempo::update(); }
void Robot::AutonomousInit() { left_coral.start(); }
void Robot::TeleopInit() { left_coral.cancel(); }
void Robot::DisabledInit() { tempo::Tempo::stop(); }Tempo.update() runs one loop of the started auto and its
hooks. Starting an auto ends any auto Tempo is already
running. If the robot is disabled while an auto is running, the next Tempo.update() ends it,
as the scheduler would.
isFinished() is false before the first run and becomes true once the run has ended. If your
auto is a state machine or an action tree, you can use start() as its start action and
isFinished() as its end check.
If Tempo.configure(...) was given the drive subsystem, start() schedules the auto’s command
and Tempo.update() has nothing to run.
Tempo.configure(...) without the subsystem gives the scheduler no drivetrain requirement.
On a command-based robot a scheduled auto then leaves the drivetrain’s default command running,
and both drive at once.
Warm up while disabled
Warming an auto builds its routes and plans its first legs before the auto starts. Tempo
warms the auto picked on a TempoAutos chooser while the robot is
disabled. The command scheduler, or Tempo.update() on a robot without it, has to keep running
while disabled for that.
If you use any other chooser, do one of these:
- Call
warmup()on the selected auto fromdisabledPeriodic(), as in the example below. - Pass the selection to
TempoAutos.prePlan(supplier)once at startup (pre_planin Python and C++). Tempo then reads the supplier while the robot is disabled and warms the auto it returns.
Both still work when
warmWhileDisabled(false) has turned Tempo’s own
warm-up off.
An auto that isn’t on a chooser, such as a route returned straight from
getAutonomousCommand(), isn’t planned while disabled. Its first leg is planned when the auto
starts, and the console prints [Tempo] leg 1 waited ... no plan had been made ahead for the leg.
To plan it ahead, pass it to prePlan once at startup:
TempoAutos.prePlan(() -> route).TempoAutos.pre_plan(lambda: self.route).tempo::TempoAutos::pre_plan([this] { return &route_; }).
@Override public void disabledPeriodic() {
Auto selected = chooser.getSelected();
if (selected != null) selected.warmup();
}def disabledPeriodic(self):
selected = self.chooser.getSelected()
if selected is not None:
selected.warmup()void Robot::DisabledPeriodic() {
if (tempo::Auto* selected = chooser_.GetSelected()) selected->warmup();
}Later calls reuse the routes and plans unless the alliance changes. A Setlist warms every
route, including both sides of each when.
The first leg drives the warmed plan when the robot is within the route’s default arrival tolerance of the pose the plan was made from, in position and heading. If it’s farther off, or it’s already moving a different way, the first leg is planned again.
Routes in your own command group stay warm the same way. Call warmup() on each route every
disabled loop, and each route command starts on its own plan.
If your chooser holds commands, warm the selected command the same way. Put the command from
the auto’s own command() in the chooser, because a decorator such as withName hides the
warm-up calls.
In Java the command is a com.tempo.wpi.Warmable, with warmup() and warmProgress().
warmProgress().ready() becomes true once every requested plan is done.
In Python the command has warmup() and warm_progress(). warm_progress().ready becomes
true once every requested plan is done.
In C++ a command is warmed with tempo::wpi::warmup(cmd.get()), which takes a frc2::Command*.
In Java, Tempo also runs a boot warm-up while the robot is disabled, because the first auto
would wait on class loading and JIT compilation. On a command-based robot the scheduler runs it
as a command named TempoWarmup, so the scheduler has to keep running while disabled. In
simulation, Tempo.warmup() in robotInit does the same work
(Tempo reference).
In Python, the first auto also pays for lazy imports and the first calls into the native core.
Call Tempo.warmup() once at startup, after Tempo is configured. It returns at once and does
that work on a background thread.
Start and end poses
getStartPose() returns the pose the auto starts at and getEndPose() returns the pose it
ends at, for the alliance the robot is on right now. They’re empty when the pose isn’t fixed
before the auto runs, like a route with no startAt. They don’t plan anything, and you can call
them every loop while disabled, for example to check the robot is on its start spot.
Optional<Pose2d> start = leftCoral.getStartPose();
Optional<Pose2d> end = leftCoral.getEndPose();start = left_coral.get_start_pose() # a Pose2d, or None
end = left_coral.get_end_pose()std::optional<frc::Pose2d> start = left_coral.get_start_pose<frc::Pose2d>();
std::optional<frc::Pose2d> end = left_coral.get_end_pose<frc::Pose2d>();A Setlist gives its first route’s start and its last route’s end. The Composer and Setlist reference pages list when each one is empty.
Run the robot loop at real-time priority
On a bench roboRIO running warmed Java autos, the slowest loop spent 9.7 ms in Tempo’s calls at normal priority and 2.9 ms at real-time priority.
Raise the robot thread’s priority after Tempo is configured. Tempo’s planning threads start
during configuration and keep normal priority. If the loop thread isn’t at real-time priority
on a roboRIO, Tempo prints a warning once, starting with
[Tempo] the robot loop thread is not at real-time priority.
import edu.wpi.first.wpilibj.Threads;
// Robot.java: last line of the constructor or robotInit().
Threads.setCurrentThreadPriority(true, 99);import wpilib
# robot.py: last line of robotInit().
wpilib.setCurrentThreadPriority(True, 99)#include <frc/Threads.h>
// Robot.cpp: last line of the constructor or RobotInit().
frc::SetCurrentThreadPriority(true, 99);These calls are for the roboRIO. On a SystemCore the call takes the priority alone, and
real-time priority is capped at 50:
Threads.setCurrentThreadPriority(50) in Java (org.wpilib.system.Threads),
wpilib.set_current_thread_priority(50) in Python and
wpi::SetCurrentThreadPriority(50) in C++ (<wpi/system/Threads.hpp>). WPILib 2027 marks the
Java and C++ calls deprecated, so the compiler’s deprecation note for them is expected. Tempo’s
loop priority warning is for the roboRIO only. On the bench SystemCore the slowest loop was
under 2 ms at either priority.
A real-time loop that never yields starves every thread below it, including Tempo’s. Keep blocking calls and busy waits out of the robot loop.
The first tick
In Java, every route command prints one line on its first tick:
[Tempo] first tick 0.812 ms (init 0.340 ms, odometry reset 0.096 ms, live plan, phase DRIVING)init is the time spent in initialize(), and odometry reset is the pose-setter call
inside it. first tick is the whole first execute(). The delay from scheduling to the first
output is init plus first tick.
The words before phase say whether the first leg drove the plan warmed while disabled or
planned again, and why. The Planning reference lists
them.
If it fails…
Call Tempo.update() every loop in robotPeriodic(). A started auto never runs without it.
The auto’s command was never scheduled, another command took the drivetrain, or a leg couldn’t be planned and was skipped.