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

3.1 Routes & waypoints

A Composer is one route. startAt sets where it starts, and each to(...) adds a waypoint, which the robot drives to in order.

The example on this page is the start of a REEFSCAPE 2025 auto. The robot scores its preload on the reef, drives to the left coral station for another coral, scores it on the reef, and goes back to the station. To run it, load the REEFSCAPE 2025 pack and connect the drivetrain first.

A route with four waypoints

Java
import com.tempo.Alliance;
import com.tempo.Arrival;
import com.tempo.Composer;
import com.tempo.Speed;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import static edu.wpi.first.units.Units.Degrees;
import static edu.wpi.first.units.Units.Meters;

Pose2d START_LEFT = new Pose2d(7.58, 5.85, Rotation2d.fromDegrees(180));
Pose2d REEF_IR = new Pose2d(5.13, 5.14, Rotation2d.fromDegrees(-120));
Pose2d REEF_KR = new Pose2d(3.85, 5.14, Rotation2d.fromDegrees(-60));
Pose2d STATION_LEFT = new Pose2d(1.13, 7.00, Rotation2d.fromDegrees(126));

Composer routine = Composer.startAt(START_LEFT)
    .originAlliance(Alliance.BLUE)
    .resetOdometry(true)
    .arrival(Arrival.STOP);

routine.to(REEF_IR)
    .runAfter(superstructure.scoreL4());

routine.speed(Speed.CAREFUL).to(STATION_LEFT)
    .arriveWithin(Meters.of(0.02), Degrees.of(1.5))
    .runAfter(intake.intakeCommand());

routine.speed(Speed.FULL).to(REEF_KR)
    .runAfter(superstructure.scoreL4());

routine.speed(Speed.CAREFUL).to(STATION_LEFT)
    .runAfter(intake.intakeCommand());
Python
import math
from tempo import Alliance, Arrival, Composer, Speed
from wpimath.geometry import Pose2d

START_LEFT = Pose2d(7.58, 5.85, math.radians(180))
REEF_IR = Pose2d(5.13, 5.14, math.radians(-120))
REEF_KR = Pose2d(3.85, 5.14, math.radians(-60))
STATION_LEFT = Pose2d(1.13, 7.00, math.radians(126))

routine = (Composer.start_at(START_LEFT)
    .origin_alliance(Alliance.BLUE)
    .reset_odometry(True)
    .arrival(Arrival.STOP))

(routine.to(REEF_IR)
    .run_after(superstructure.score_l4()))

(routine.speed(Speed.CAREFUL).to(STATION_LEFT)
    .arrive_within(0.02, math.radians(1.5))
    .run_after(intake.intake_command()))

(routine.speed(Speed.FULL).to(REEF_KR)
    .run_after(superstructure.score_l4()))

(routine.speed(Speed.CAREFUL).to(STATION_LEFT)
    .run_after(intake.intake_command()))
C++
#include <numbers>
#include <frc/geometry/Pose2d.h>
#include <frc2/command/CommandPtr.h>
#include <tempo/Composer.h>

const frc::Pose2d START_LEFT{7.58_m, 5.85_m, 180_deg};
const frc::Pose2d REEF_IR{5.13_m, 5.14_m, -120_deg};
const frc::Pose2d REEF_KR{3.85_m, 5.14_m, -60_deg};
const frc::Pose2d STATION_LEFT{1.13_m, 7.00_m, 126_deg};

// Composer borrows these pointers: keep every owner alive while the route can run.
frc2::CommandPtr score_preload = superstructure.ScoreL4();
frc2::CommandPtr collect_coral = intake.IntakeCommand();
frc2::CommandPtr score_second = superstructure.ScoreL4();
frc2::CommandPtr collect_again = intake.IntakeCommand();

auto routine = tempo::Composer::start_at(START_LEFT);
routine
    .origin_alliance(tempo::Alliance::Blue)
    .reset_odometry(true)
    .arrival(tempo::Arrival::Stop());

routine.to(REEF_IR)
    .run_after(score_preload.get());

routine.speed(tempo::Speed::Careful).to(STATION_LEFT)
    .arrive_within(0.02, 1.5 * std::numbers::pi / 180.0)
    .run_after(collect_coral.get());

routine.speed(tempo::Speed::Full).to(REEF_KR)
    .run_after(score_second.get());

routine.speed(tempo::Speed::Careful).to(STATION_LEFT)
    .run_after(collect_again.get());

The poses are written for blue, and Tempo mirrors the route when the robot is on red (Alliance flipping).

resetOdometry(true) resets the pose estimator to the start pose when the auto starts. arrival(Arrival.STOP) makes the robot stop at every waypoint, because it scores or intakes at each one.

The drive to each waypoint is called a leg. The runAfter command after a to(...) runs once the robot arrives at that waypoint.

speed(Speed.CAREFUL) slows the legs to the station. speed(Speed.FULL) goes back to full speed for the leg to the reef. The first trip to the station also tightens arriveWithin to 2 cm and 1.5 degrees.

Angles are radians in Python, so the poses and arrive_within use math.radians(...).

arrive_within takes meters and radians as plain numbers. The _m and _deg literals need no using line.

To drive the route, call routine.schedule(). Schedule and cancel covers the other ways to start and stop it.

The commands attached to a route are called hooks. They can’t require the drivetrain, because the route is driving it. A runAfter command still runs when the robot ends a leg outside its arrival tolerance. Have your scoring command check that the robot is in position (Missed arrivals).

Which legs an option changes

Speed, arrival and curve style stay in effect for later legs until you change them. Put speed(...) before the to(...) it applies to. Put arrival(...) and curve(...) after the to(...) of the first leg they change, or before the first to(...) to set them for every leg, as the example does with arrival(Arrival.STOP).

Commands, rotation targets and arriveWithin apply only to the leg they follow, so the tight arriveWithin on the first station trip doesn’t change the others. The option scope table lists every option.

Shape the curve with a Bias

A Bias sets the direction the robot travels through a waypoint, and a longer reach holds that direction longer. It’s the same as dragging a bias handle on the Paths screen in Tempo GUI.

Java
import static edu.wpi.first.units.Units.Degrees;
import static edu.wpi.first.units.Units.Meters;
import com.tempo.Bias;

Composer.startAt(START)
    // Pass (5.0, 3.0) traveling toward 30 deg, with a 0.8 m reach.
    .to(5.0, 3.0, Bias.toward(Degrees.of(30), 0.8))
    .to(8.0, 3.0)
    // Arrive at (8.0, 6.0) facing 90 deg, coming in from below.
    .to(8.0, 6.0, Rotation2d.fromDegrees(90), Bias.toward(Math.PI / 2, Meters.of(0.5)));

Bias.toward takes the direction as an Angle, a Rotation2d or radians, and the reach as a Distance or meters.

Python
import math
from tempo import Angles, Bias, Composer

(Composer.start_at(START)
    # Pass (5.0, 3.0) traveling toward 30 deg, with a 0.8 m reach.
    .to(5.0, 3.0, Bias.toward(Angles.deg(30), 0.8))
    .to(8.0, 3.0)
    # Arrive at (8.0, 6.0) facing 90 deg, coming in from below.
    .to(8.0, 6.0, Angles.deg(90), Bias.toward(math.pi / 2, 0.5)))

Bias.toward takes the direction in radians or as a Rotation2d, and the reach in meters. Angles.deg(...) converts degrees to radians.

C++
#include <numbers>
#include <tempo/Composer.h>

auto routine = tempo::Composer::start_at(START);
// Pass (5.0, 3.0) traveling toward 30 deg, with a 0.8 m reach.
routine.to(5.0, 3.0, tempo::Bias::Toward(30_deg, 0.8_m))
    .to(8.0, 3.0)
    // Arrive at (8.0, 6.0) facing 90 deg, coming in from below.
    .to(8.0, 6.0, std::numbers::pi / 2, tempo::Bias::Toward(std::numbers::pi / 2, 0.5));

Bias::Toward also takes radians and meters as plain numbers, and a WPILib Rotation2d.

The bias goes last in to(...), after the position or pose. Write the direction for blue, like the poses, because it mirrors with the route.

On the last waypoint, a bias sets the direction the robot is traveling as it arrives, for example straight into a scoring position (Approach direction).

Start bias

A bias passed to startAt(...) sets the direction the robot leaves the start in. It only applies when the robot is stopped at the start pose. A robot that’s already moving keeps going the way it’s moving.

Java
// Pull away traveling 20 deg below the x axis.
Composer.startAt(START, Bias.toward(Degrees.of(-20), 0.6))
    .to(5.0, 3.0);
Python
# Pull away traveling 20 deg below the x axis.
(Composer.start_at(START, Bias.toward(Angles.deg(-20), 0.6))
    .to(5.0, 3.0))
C++
// Pull away traveling 20 deg below the x axis.
auto routine = tempo::Composer::start_at(START, tempo::Bias::Toward(-20_deg, 0.6_m))
    .to(5.0, 3.0);

When a bias would collide

If a bias would send the robot into a field element, Tempo keeps the direction and shortens the reach until the path clears. If no reach clears, the bias is dropped and the leg routes around the obstacle. Each case prints its own warning that names the leg:

[Tempo] leg 2: the bias at this waypoint was shortened to clear an obstacle.
[Tempo] leg 2: the bias at this waypoint would collide, so the path routes around it without the bias.

To clear the warning, shorten the reach or turn the direction. Bias lists every warning.

Differential drives

A differential drive always faces along its path, so on its routes a bias also sets which way the robot faces at a waypoint. A start bias has to point forward or backward along the robot’s starting heading, because the robot can’t drive sideways. Any other start bias fails the route when it freezes.

Drive straight lines

curve(CurveStyle.STRAIGHT) makes legs straight lines, for example along a wall. If a field element is in the way, the leg goes around it in straight lines. A straight leg takes no bias, and one given to it is ignored without a warning.

Java
import com.tempo.CurveStyle;

Composer.startAt(START_LEFT)
    .curve(CurveStyle.STRAIGHT)       // default for every leg from here
    .to(REEF_IR)
    .to(STATION_LEFT)
    .to(REEF_KR)
        .curve(CurveStyle.SMOOTH);    // this leg and later ones curve again
Python
from tempo import Composer, CurveStyle

(Composer.start_at(START_LEFT)
    .curve(CurveStyle.STRAIGHT)       # default for every leg from here
    .to(REEF_IR)
    .to(STATION_LEFT)
    .to(REEF_KR)
        .curve(CurveStyle.SMOOTH))    # this leg and later ones curve again
C++
#include <tempo/Composer.h>
#include <tempo/CurveStyle.h>

tempo::Composer::start_at(START_LEFT)
    .curve(tempo::CurveStyle::Straight)   // default for every leg from here
    .to(REEF_IR)
    .to(STATION_LEFT)
    .to(REEF_KR)
        .curve(tempo::CurveStyle::Smooth);  // this leg and later ones curve again

Build a route in a loop

to(...) also works on a route kept in a variable, so a loop can add the waypoints. Add every waypoint before the route is first used. The route freezes at that point and a later to(...) throws.

Java
import java.util.List;

Composer route = Composer.startAt(START_LEFT);
for (Pose2d waypoint : List.of(REEF_IR, STATION_LEFT, REEF_KR, STATION_LEFT)) {
    route.to(waypoint);
}
Python
route = Composer.start_at(START_LEFT)
for waypoint in (REEF_IR, STATION_LEFT, REEF_KR, STATION_LEFT):
    route.to(waypoint)
C++
#include <array>

auto route = tempo::Composer::start_at(START_LEFT);
for (const auto& waypoint : std::array{REEF_IR, STATION_LEFT, REEF_KR, STATION_LEFT}) {
    route.to(waypoint);
}

Check the result

Build routes when the robot starts up, after Tempo.configure(...). A typo in a stayWithin, cross or condition id, or a misplaced option, then throws in the pits instead of during a match. Composer.startAt throws before Tempo.configure(...), so don’t build a route in a static or field initializer that runs first.

Other checks, such as a hook that requires the drivetrain, run when the route freezes on its first use. SimRun simulates a route without a robot, and a SimRun test of each auto catches those. This gets the pose the route ends at:

Java
import com.tempo.sim.SimRun;

Pose2d end = SimRun.of(routine).go().finalPose();
Python
from tempo.sim import SimRun

end = SimRun.of(routine).go().final_pose
C++
#include <utility>
#include <tempo/sim/SimRun.h>
#include <tempo/wpi/Geometry.h>

auto run = tempo::SimRun::of(std::move(routine));
run.go();
auto end = tempo::wpi::final_pose(run);

If the end pose is more than a few centimeters from the last waypoint, the route isn’t reaching it. Test an auto has the other checks, like a route’s time, the commands it fires and a red-alliance run.

If it fails…

A bias was shortened or dropped Above → [Tempo] leg 2: the bias at this waypoint was shortened to clear an obstacle.

The bias pointed the robot into a field element. Shorten the reach or turn the direction.

A differential-drive route fails at its first command() Above → [Tempo] leg 1: a differential drivetrain leaves its start along its heading, so a start bias must point along the start heading or straight back from it; turn the bias or remove it

Point the start bias forward or backward along the starting heading, or remove it.

esc

Loading search...