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

3.21 Tune path following

Control.standard() is the default, so a route doesn’t need a control(...) call. This example sets it anyway, with the poses from Routes & waypoints:

Java
import com.tempo.Composer;
import com.tempo.Control;

var route = Composer.startAt(START_LEFT)
    .control(Control.standard())
    .to(REEF_IR)
    .to(STATION_LEFT);
Python
from tempo import Composer, Control

route = (Composer.start_at(START_LEFT)
    .control(Control.standard())
    .to(REEF_IR)
    .to(STATION_LEFT))
C++
#include <tempo/Composer.h>

auto route = tempo::Composer::start_at(START_LEFT)
    .control(tempo::Control::standard())
    .to(REEF_IR)
    .to(STATION_LEFT);

control(...) after a to(...) applies to that leg and every later leg until it’s set again. Before the first to(...), as here, it applies from the first leg. On swerve and mecanum, standard control is the trajectory’s velocity feedforward plus position and heading feedback. On a differential drive it’s RAMSETE (see Differential drive).

A leg’s limits bound the plan. The command is the plan plus feedback, so while the robot catches up after a push or a slow start it can ask for more acceleration than the leg’s limits. Tempo limits those commands to what the drivetrain can do, which is the wheel free speed, the motor force at the drive current limit, and wheel grip. If the config gives Tempo no drive motor and mass to work those out from, the commands stay inside the leg’s limits. The commanded speed stays inside the leg’s velocity limit.

On swerve, a leg that already plans at the drivetrain’s limits may change its command 10 percent faster than its own acceleration and centripetal limits.

Send the speeds to the drivetrain as Tempo gives them, and don’t pass them through ChassisSpeeds.discretize (ChassisVelocities.discretize on WPILib 2027). The command already allows for the loop it’s held over.

Tuning against a repeatable route

Use the same route, config and starting pose for every run you compare. If you pass the gains as suppliers (Live tuning), a new value is used on the running route within 200 ms.

The Tempo/... keys in the steps are the ones TempoLogging.everything("Tempo", sink) writes (Log Tempo state).

  1. Check the wiring first.
  2. Set the limits. Drive the route at Speed.FULL and compare Tempo/PlannedSpeeds/Vx with the robot-relative speed your drivetrain measures. If the robot never reaches a planned speed, the limits are too high for the hardware, so fix them before changing gains.
  3. Tune translation kP. Start from the default, 8.0 on every drivetrain. Lower it if the robot oscillates across the path, and raise it if Tempo/Error/X and Tempo/Error/Y don’t stay small through the corners.
  4. Tune rotation kP the same way, watching Tempo/Error/Rotation. Start from the default, 6.0.
  5. On swerve and mecanum, leave I and D at zero, and add I only if a steady offset remains. A differential drive ignores I and D.
  6. Run the route again on the red alliance, and again after any change to mass, gearing or bumpers.

Also watch Tempo/Replans/Count. Each replan starts a new trajectory from the current pose, so a route that replans every few loops shows small Tempo/Error/ values even when it tracks poorly.

Standard control leads the feedforward by the follower latency, the sensor and actuation delay of the drivetrain. It comes from withLag on the config, from calibration, or from an estimate (Follower latency).

Custom controllers and output filters

A custom controller or thenFilter (then_filter in Python and C++) is called on the robot loop every tick the leg drives, so keep it non-blocking. Tempo doesn’t apply any speed, acceleration, centripetal, angular or wheel limits to what it returns, so limit the output yourself.

Replacing the controller

A PathFollower gets a ControlContext and returns robot-relative WPILib ChassisSpeeds. The context fields are listed on that page, and suggested is the command standard control would have sent.

The samples below use the 2026 WPILib type ChassisSpeeds.

On WPILib 2027 the type is ChassisVelocities, and the Java fields the samples read are vx, vy and omega in place of vxMetersPerSecond, vyMetersPerSecond and omegaRadiansPerSecond. See 2026 vs 2027.

In Python the context fields are snake_case attributes such as ctx.robot_pose and ctx.setpoint_vx_mps.

This controller adds position feedback to the setpoint velocity, rotates the result into the robot frame, and keeps Tempo’s rotation output. It doesn’t limit the speeds it returns.

Java
import com.tempo.Composer;
import com.tempo.Control;
import edu.wpi.first.math.kinematics.ChassisSpeeds;

var route = Composer.startAt(START_LEFT)
    .control(Control.custom(ctx -> {
        double kx = 4.0, ky = 4.0;
        double vx = ctx.setpointVxMps() + kx * (ctx.setpointPose().getX() - ctx.robotPose().getX());
        double vy = ctx.setpointVyMps() + ky * (ctx.setpointPose().getY() - ctx.robotPose().getY());
        double c = Math.cos(-ctx.robotPose().getRotation().getRadians());
        double s = Math.sin(-ctx.robotPose().getRotation().getRadians());
        return new ChassisSpeeds(vx * c - vy * s, vx * s + vy * c,
            ctx.suggested().omegaRadiansPerSecond);
    }))
    .to(REEF_IR);
Python
import math
from tempo import Composer, Control
from wpimath.kinematics import ChassisSpeeds

def hold_setpoint(ctx):
    kx = ky = 4.0
    vx = ctx.setpoint_vx_mps + kx * (ctx.setpoint_pose.X() - ctx.robot_pose.X())
    vy = ctx.setpoint_vy_mps + ky * (ctx.setpoint_pose.Y() - ctx.robot_pose.Y())
    heading = ctx.robot_pose.rotation().radians()
    c, s = math.cos(-heading), math.sin(-heading)
    return ChassisSpeeds(vx * c - vy * s, vx * s + vy * c, ctx.suggested.omega)

route = (Composer.start_at(START_LEFT)
    .control(Control.custom(hold_setpoint))
    .to(REEF_IR))
C++
#include <cmath>
#include <frc/kinematics/ChassisSpeeds.h>
#include <tempo/Composer.h>
#include <tempo/Control.h>
#include <tempo/wpi/Geometry.h>

auto route = tempo::Composer::start_at(START_LEFT)
    .control(tempo::Control::custom([](const tempo::ControlContext& ctx) {
        constexpr double kx = 4.0, ky = 4.0;
        const frc::Pose2d robot = tempo::wpi::robot_pose(ctx);
        const frc::Pose2d setpoint = tempo::wpi::setpoint_pose(ctx);
        double vx = ctx.setpoint_vx_mps + kx * (setpoint.X() - robot.X()).value();
        double vy = ctx.setpoint_vy_mps + ky * (setpoint.Y() - robot.Y()).value();
        double c = std::cos(-robot.Rotation().Radians().value());
        double s = std::sin(-robot.Rotation().Radians().value());
        return frc::ChassisSpeeds{units::meters_per_second_t{vx * c - vy * s},
                                  units::meters_per_second_t{vx * s + vy * c},
                                  tempo::wpi::suggested(ctx).omega};
    }))
    .to(REEF_IR);

If your controller keeps state, pass a factory, and it builds one controller for each driving leg on each run. PathFollower covers reset, end and the C++ form.

In Java the factory is a constructor reference, Control.custom(MyFollower::new).

In Python pass it as Control.custom(factory=MyFollower). The factory= keyword is required because a positional argument is treated as the controller itself.

Filtering the output

thenFilter changes the output of the controller, standard or custom. This filter limits how fast each translation component can change to 3 m/s^2 and passes rotation through:

Java
import com.tempo.Composer;
import com.tempo.Control;
import edu.wpi.first.math.filter.SlewRateLimiter;
import edu.wpi.first.math.kinematics.ChassisSpeeds;

SlewRateLimiter vxLimiter = new SlewRateLimiter(3.0);   // m/s^2
SlewRateLimiter vyLimiter = new SlewRateLimiter(3.0);

var route = Composer.startAt(START_LEFT)
    .control(Control.standard().thenFilter(s -> new ChassisSpeeds(
        vxLimiter.calculate(s.vxMetersPerSecond), vyLimiter.calculate(s.vyMetersPerSecond),
        s.omegaRadiansPerSecond)))
    .limits(3.5, 3.0, 6.0)   // m/s, m/s^2, m/s^2 centripetal
    .to(REEF_IR);
Python
from tempo import Composer, Control
from wpimath.filter import SlewRateLimiter
from wpimath.kinematics import ChassisSpeeds

vx_limiter = SlewRateLimiter(3.0)   # m/s^2
vy_limiter = SlewRateLimiter(3.0)

route = (Composer.start_at(START_LEFT)
    .control(Control.standard().then_filter(lambda s: ChassisSpeeds(
        vx_limiter.calculate(s.vx), vy_limiter.calculate(s.vy), s.omega)))
    .limits(3.5, 3.0, 6.0)   # m/s, m/s^2, m/s^2 centripetal
    .to(REEF_IR))
C++
#include <frc/filter/SlewRateLimiter.h>
#include <frc/kinematics/ChassisSpeeds.h>
#include <tempo/Composer.h>
#include <tempo/Control.h>
#include <units/acceleration.h>
#include <units/velocity.h>

// Members of the class that builds the route. The filter below reaches them through this.
frc::SlewRateLimiter<units::meters_per_second> vxLimiter{3.0_mps_sq};   // m/s^2
frc::SlewRateLimiter<units::meters_per_second> vyLimiter{3.0_mps_sq};

auto route = tempo::Composer::start_at(START_LEFT)
    .control(tempo::Control::standard().then_filter([this](frc::ChassisSpeeds s) {
        s.vx = vxLimiter.Calculate(s.vx);
        s.vy = vyLimiter.Calculate(s.vy);
        return s;
    }))
    .limits(3.5, 3.0, 6.0)   // m/s, m/s^2, m/s^2 centripetal
    .to(REEF_IR);

Tempo doesn’t reset limiters the filter captures, so reset them yourself before another run, for example with vxLimiter.reset(0) (Reset(0_mps) in C++).

The 3.0_mps_sq literal needs no using line.

If the limits are higher than the robot can drive, lower them before adding an output filter.

A leg with a custom controller or filter that ends at rest arrives when the robot is inside the arrival tolerance and could stop inside it. If the robot stays inside the tolerance for 1 second without slowing enough, for example while it pushes against a wall, the leg arrives anyway. Outside the tolerance, the leg ends as missed and failed once the robot stalls.

Diagnosing tracking problems

  • If the robot lags a lot and the output is saturated, compare the requested speed and acceleration with what the drivetrain delivers.
  • If the robot oscillates, the cause can be pose noise, loop timing, the gains or the follower latency.
  • When the path shape is right but hooks at a position start late, the robot is behind the plan. Look for an output filter or limits the robot can’t reach. A matchTime hook isn’t delayed, because it fires by the clock.
  • A controller factory that returns nothing ends that route when its leg starts to drive.
esc

Loading search...