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

The examples on this page add to a Composer route named route. The coordinates are on the REEFSCAPE 2025 pack. Every overload is listed in Rotation targeting.

Tempo’s GUI shows these calls as markers on the Paths screen, and you can edit them there.

Waypoint heading

Java
import com.tempo.Angles;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;

route.to(6.5, 4.0);                                              // no heading
route.to(8.0, 2.0, Angles.deg(90));                              // arrive facing 90 deg
route.to(new Pose2d(5.77, 4.03, Rotation2d.fromDegrees(180)));  // the pose's heading
Python
from wpimath.geometry import Pose2d, Rotation2d
from tempo.angles import deg

route.to(6.5, 4.0)                                         # no heading
route.to(8.0, 2.0, deg(90))                                # arrive facing 90 deg
route.to(Pose2d(5.77, 4.03, Rotation2d.fromDegrees(180)))  # the pose's heading
C++
#include <tempo/Angles.h>

route.to(6.5, 4.0);                                   // no heading
route.to(8.0, 2.0, tempo::angles::deg(90));           // arrive facing 90 deg
route.to(frc::Pose2d{5.77_m, 4.03_m, 180_deg});      // the pose's heading

The three lines add three waypoints, one for each way to write one. Headings are counterclockwise positive. On red they’re mirrored along with the positions.

to(x, y, heading) takes a Rotation2d, which Angles.deg returns.

The heading is a plain number in radians, which deg returns.

On swerve, the robot keeps the heading it has when no later waypoint names one. If a later waypoint heading or rotation target needs a turn, the turn is spread by distance over the legs with no heading before it and the leg that reaches it. Where turning wouldn’t fit past an obstacle, the robot keeps its heading through that stretch and makes the turn on the leg into the waypoint that names the heading. If a gap needs a heading, give one or use a Rotation Lock.

On mecanum, the robot turns to face the straight line from the leg’s start to its end, front or back first, whichever is the smaller turn. Legs that share a plan count as one, from the first one’s start to the last one’s end.

A differential drive always faces along its path (Differential drives).

Approach direction

A heading sets which way the robot faces at the waypoint. A Bias sets the direction it’s traveling as it gets there. This robot arrives at the station facing 126 deg and traveling at 126 deg too.

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

route.to(1.13, 7.00, Rotation2d.fromDegrees(126), Bias.toward(Degrees.of(126), 0.6));
Python
from tempo import Bias

route.to(1.13, 7.00, deg(126), Bias.toward(deg(126), 0.6))
C++
route.to(1.13, 7.00, tempo::angles::deg(126), tempo::Bias::Toward(126_deg, 0.6_m));

The second argument is the bias’s reach in meters, and a longer reach holds the direction longer. On a differential drive the approach bias is also the arrival heading, or its opposite on a leg the robot drives backward. See Shape the curve with a Bias for units and what happens when the curve would hit something.

Rotation targets

rotationTarget(fraction, heading) (rotation_target in Python and C++) turns the robot to heading by fraction of the way along the leg. This leg faces 45 deg by 30% of the way and 90 deg by 80%.

Java
route.to(7.5, 4.0)
    .rotationTarget(0.3, Angles.deg(45))
    .rotationTarget(0.8, Angles.deg(90));
Python
(route.to(7.5, 4.0)
    .rotation_target(0.3, deg(45))
    .rotation_target(0.8, deg(90)))
C++
route.to(7.5, 4.0)
    .rotation_target(0.3, tempo::angles::deg(45))
    .rotation_target(0.8, tempo::angles::deg(90));

The fraction is of distance along the path, not time. 0 is leaving the previous waypoint and 1 is arriving. Targets on a leg are reached in order of their fractions, and a waypoint heading counts as a target at 1. If the robot can’t turn fast enough to reach the angle in time, it gets there late.

Locks and Keys

rotationLock(position) holds whatever heading the robot has from position on, and rotationKey(position) lets it turn again (rotation_lock and rotation_key in Python and C++). position is a fraction of the way along the leg, like a rotation target’s. A Lock lasts across waypoints until a Key, so one pair can hold a heading through a gap that spans two legs.

Java
Composer.startAt(start)
    .to(gapEntry)
        .rotationLock(0.5)     // hold the heading from halfway to gapEntry
    .to(gapExit)
    .to(destination)
        .rotationKey(0.3);     // turn again from 30% of the way to destination
Python
(Composer.start_at(start)
    .to(gap_entry)
        .rotation_lock(0.5)    # hold the heading from halfway to gap_entry
    .to(gap_exit)
    .to(destination)
        .rotation_key(0.3))    # turn again from 30% of the way to destination
C++
tempo::Composer::start_at(start)
    .to(gap_entry)
        .rotation_lock(0.5)    // hold the heading from halfway to gap_entry
    .to(gap_exit)
    .to(destination)
        .rotation_key(0.3);    // turn again from 30% of the way to destination

Inside the locked stretch Tempo plans with the robot’s footprint at the held heading. The robot can drive through a gap that it fits through one way but is too narrow to turn in. Rotation targets and waypoint headings in the stretch are ignored, and an aim has no effect until the Key. Tempo prints a warning naming the leg in each case, and another when a Lock has no Key. That Lock holds to the end of the route.

After the Key the robot turns as fast as the angular limits allow. If the turn can’t finish before the leg ends, the robot finishes it stopped at the waypoint. Differential drives ignore Locks and Keys.

Aim at a point

aimTarget(point) (aim_target) keeps the front of the robot pointed at a field point. The point can be a Translation2d or a Pose2d, and Python also takes an (x, y) tuple.

The example shows the four ways to aim on a leg, each on its own route:

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

import com.tempo.Condition;
import edu.wpi.first.math.geometry.Translation2d;

Translation2d REEF_CENTER = new Translation2d(4.489, 4.026);

wholeLeg.to(7.5, 4.0).aimTarget(REEF_CENTER);            // whole leg
fromHalfway.to(7.5, 4.0).aimTarget(0.5, REEF_CENTER);    // from halfway to the end
window.to(7.5, 4.0).aimTarget(0.2, 0.6, REEF_CENTER);    // 20% to 60%, then the planned heading
nearReef.to(7.5, 4.0).aimTarget(Condition.near(REEF_CENTER, Meters.of(4)), REEF_CENTER);  // within 4 m
Python
from tempo import Condition
from wpimath.geometry import Translation2d

REEF_CENTER = Translation2d(4.489, 4.026)

whole_leg.to(7.5, 4.0).aim_target(REEF_CENTER)            # whole leg
from_halfway.to(7.5, 4.0).aim_target(0.5, REEF_CENTER)    # from halfway to the end
window.to(7.5, 4.0).aim_target(0.2, 0.6, REEF_CENTER)     # 20% to 60%, then the planned heading
near_reef.to(7.5, 4.0).aim_target(Condition.near(REEF_CENTER, 4.0), REEF_CENTER)  # within 4 m
C++
#include <tempo/Condition.h>

const frc::Translation2d REEF_CENTER{4.489_m, 4.026_m};

whole_leg.to(7.5, 4.0).aim_target(REEF_CENTER);            // whole leg
from_halfway.to(7.5, 4.0).aim_target(0.5, REEF_CENTER);    // from halfway to the end
window.to(7.5, 4.0).aim_target(0.2, 0.6, REEF_CENTER);     // 20% to 60%, then the planned heading
near_reef.to(7.5, 4.0).aim_target(tempo::Condition::near(REEF_CENTER, 4_m), REEF_CENTER);  // within 4 m

While an aim is active it overrides waypoint headings and rotation targets. A whole-leg aim drops the leg’s waypoint heading. If a leg has several aims, the one that started most recently sets the heading.

With a state condition such as near, inside or when, the robot aims only while the condition holds. With a moment such as entered, exited or passed, it aims from that moment to the end of the leg (Conditions).

A leg with an aim plans its clearance with the circle the footprint sweeps while turning. A gap the robot fits through at one heading can be too narrow for an aimed leg.

Live aim targets

Every form of aimTarget also takes a supplier, which is read every loop. It returns a point to face or a heading to hold. The first call in this example supplies a point and the second a heading. robotState stands for your own code that works out the target.

Java
// Face the vision-estimated reef center.
route.to(7.5, 4.0)
    .aimTarget(() -> robotState.reefTarget());

// Hold the shot solver's heading from 60% of the way.
route.to(7.5, 4.0)
    .aimTarget(0.6, () -> robotState.getTargetAngle());
Python
# Face the vision-estimated reef center.
route.to(7.5, 4.0).aim_target(lambda: robot_state.reef_target())

# Hold the shot solver's heading from 60% of the way.
route.to(7.5, 4.0).aim_target(0.6, lambda: robot_state.target_angle())
C++
// Face the vision-estimated reef center.
route.to(7.5, 4.0)
    .aim_target([&]() -> std::optional<frc::Translation2d> {
        return robotState.ReefTarget();
    });

// Hold the shot solver's heading from 60% of the way.
route.to(7.5, 4.0)
    .aim_target(0.6, [&]() -> std::optional<double> {
        return robotState.TargetAngleRad();
    });

A supplier’s value is used as it is and is never mirrored on red. When the supplier returns no value (null, None or std::nullopt), the robot turns back to the planned heading. It turns toward the target again when a value comes back.

A lambda that returns a Translation2d is a point and one that returns a Rotation2d is a heading. Pass an existing Supplier<Rotation2d> as solver::get.

A returned Translation2d or Pose2d is a point, and a number (radians) or Rotation2d is a heading. A supplier can’t return an (x, y) tuple. It raises a TypeError during the run, so return Translation2d(x, y).

A point is a lambda returning a Translation2d or a std::optional of one, and a heading is a std::function<std::optional<double>()> in radians.

Turn rate

A last argument caps how fast one rotationTarget or aimTarget turns. It’s rad/s as a plain number, or a WPILib AngularVelocity in Java. Rates.degPerSec and deg_per_sec in the examples convert from degrees per second.

Java
import com.tempo.Rates;

// Face 90 deg by halfway, turning at most 180 deg/s.
route.to(7.5, 4.0)
    .rotationTarget(0.5, Angles.deg(90), Rates.degPerSec(180));
// Track the reef center, turning at most 270 deg/s.
route.to(7.5, 4.0)
    .aimTarget(REEF_CENTER, Rates.degPerSec(270));
Python
from tempo.rates import deg_per_sec

# Face 90 deg by halfway, turning at most 180 deg/s.
route.to(7.5, 4.0).rotation_target(0.5, deg(90), deg_per_sec(180))
# Track the reef center, turning at most 270 deg/s.
route.to(7.5, 4.0).aim_target(REEF_CENTER, turn_rate=deg_per_sec(270))
C++
#include <tempo/Rates.h>

// Face 90 deg by halfway, turning at most 180 deg/s.
route.to(7.5, 4.0)
    .rotation_target(0.5, tempo::angles::deg(90), tempo::rates::deg_per_sec(180));
// Track the reef center, turning at most 270 deg/s.
route.to(7.5, 4.0)
    .aim_target(REEF_CENTER, tempo::rates::deg_per_sec(270));

Python also accepts the cap as turn_rate=, as in the aim above.

The robot-wide caps are maxAngularVelocity (max_angular_velocity) and maxAngularAcceleration in LimitsConfigs (Swerve drive). A leg’s limits(...) can lower both. When a target has its own cap too, the smaller one applies.

The caps limit the planned turn. Heading feedback is added on top of it, so the commanded turn rate can pass a cap (Tune path following).

Differential drives

A differential drive (TankConfigs) faces along its path. It drives a leg backward when the path leaves more than 90 degrees from the way it faces. A rotationTarget or aimTarget on one of its legs throws when the route freezes. A waypoint heading throws unless the robot stops there, and even there the robot doesn’t turn to it (Differential drive). To control how the robot arrives, use an approach bias.

Facing travel on swerve and mecanum

facingTravel() (facing_travel()) makes a swerve or mecanum leg face along its path, for example on a long drive nose-first. A mecanum leg with no heading already faces the straight line from its start to its end (Waypoint heading). With facingTravel() its heading follows the path through each curve.

Java
// Drive nose-first along the path, then face -60 deg to score.
route.to(6.0, 2.0)
        .facingTravel()
    .to(3.85, 5.14, Angles.deg(-60));
Python
# Drive nose-first along the path, then face -60 deg to score.
(route.to(6.0, 2.0)
        .facing_travel()
    .to(3.85, 5.14, deg(-60)))
C++
// Drive nose-first along the path, then face -60 deg to score.
route.to(6.0, 2.0)
        .facing_travel()
    .to(3.85, 5.14, tempo::angles::deg(-60));

facingTravel() only applies to its own leg. A rotation target or waypoint heading on the leg takes priority. The leg faces along its path until it has to turn to reach the first one by its fraction. With neither, the leg ends facing along the path.

If it fails…

The robot reaches a heading late Above →

It can’t turn fast enough to reach the angle in time. The turn is capped by maxAngularVelocity and the leg’s angular limit.

A Lock holds to the end of the route Above → [Tempo] leg 2: a Rotation Lock is never released by a Rotation Key; the robot holds its heading to the end of the route.

Add a rotationKey(position) where the robot should turn again.

A Lock or Key position throws Composer → [Tempo] a Rotation Lock or Key position must be a fraction from 0 to 1; got {value}

Positions are fractions of the leg’s path distance.

A differential-drive route fails when it freezes Above →

A rotationTarget or aimTarget on a differential-drive leg fails when the route freezes. Use an approach bias.

An aimed leg won't plan through a gap Above →

A leg with an aim plans its clearance with the circle the footprint sweeps while turning. Hold the heading with a Rotation Lock instead.

esc

Loading search...