3.14 Swerve drive
A swerve TempoConfig takes the module, the robot’s mass and the four module positions. Tempo
works out the speed, acceleration and cornering limits from those. This example is a 55 kg
robot with SDS MK4i L2 modules and one Kraken X60 (FOC) per module at a 60 A stator limit.
Pick the module
import com.tempo.config.SwerveModules;
import com.tempo.config.SwerveModules.SdsMk4iGear;
import com.tempo.config.TempoConfig;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.system.plant.DCMotor;
import static edu.wpi.first.units.Units.*;
public static final TempoConfig CONFIG = new TempoConfig()
.withModule(SwerveModules.SDS.MK4i(SdsMk4iGear.L2, DCMotor.getKrakenX60Foc(1), Amps.of(60)))
.withMass(Kilograms.of(55)) // bumpers and battery included
.withModuleOffsets(new Translation2d(0.3, 0.3), new Translation2d(0.3, -0.3),
new Translation2d(-0.3, 0.3), new Translation2d(-0.3, -0.3));from tempo import SwerveModules, TempoConfig
from wpimath.system.plant import DCMotor
CONFIG = (TempoConfig()
.with_module(SwerveModules.SDS.MK4i(SwerveModules.SdsMk4iGear.L2, DCMotor.krakenX60FOC(1), 60.0))
.with_mass(55.0) # kg, bumpers and battery included
.with_module_offsets((0.3, 0.3), (0.3, -0.3), (-0.3, 0.3), (-0.3, -0.3)))#include <tempo/SwerveModules.h>
#include <tempo/Tempo.h>
inline const tempo::TempoConfig kConfig = tempo::TempoConfig{}
.with_module(tempo::SwerveModules::SDS::MK4i(
tempo::SwerveModules::SdsMk4iGear::L2, tempo::DcMotor::kraken_x60_foc(), 60.0))
.with_mass(55.0) // kg, bumpers and battery included
.with_module_offsets({{0.3, 0.3}, {0.3, -0.3}, {-0.3, 0.3}, {-0.3, -0.3}});Add the frame and bumpers and pass CONFIG to Tempo.configure(...) as in Configure the robot.
On RobotPy 2027 the import is from wpimath import DCMotor, and alpha-7 and beyond spell the
motors DCMotor.kraken_x60_foc(1) and DCMotor.kraken_x60(1). See 2026 vs 2027.
Every preset takes a gear, a motor model, the stator current limit per motor and an optional
supply current limit. The motor model is one drive motor with no gearing. It’s a WPILib DCMotor
in Java and Python and a tempo::DcMotor in C++. A current limit is a plain number of amps, or a
WPILib unit in Java and C++ (Amps.of(60), 60_A).
Pass the stator limit set on your drive motor controllers, which is kSlipCurrent in a Tuner X
TunerConstants file and smartCurrentLimit on a SPARK. A TalonFX with no stator limit set
uses Phoenix 6’s default of 120 A.
FOC needs a Phoenix Pro license. Without it, use the plain Kraken X60 model:
import edu.wpi.first.math.system.plant.DCMotor;
DCMotor kraken = DCMotor.getKrakenX60(1); // Kraken X60 without FOCfrom wpimath.system.plant import DCMotor
kraken = DCMotor.krakenX60(1) # Kraken X60 without FOC#include <tempo/ModuleConfigs.h>
auto kraken = tempo::DcMotor::kraken_x60(); // Kraken X60 without FOCEach preset has a default COF (the wheel-to-carpet coefficient of friction), which is how much grip the plan counts on.
| Product | Call | Gear enum | Wheel | Default COF |
|---|---|---|---|---|
| SDS MK4 | SDS.MK4(...) | SdsMk4Gear | 4 in | 0.899 (Colson) |
| SDS MK4i | SDS.MK4i(...) | SdsMk4iGear | 4 in | 0.899 (Colson) |
| SDS MK4c | SDS.MK4c(...) | SdsMk4cGear | 4 in | 0.899 (Colson) |
| SDS MK4n | SDS.MK4n(...) | SdsMk4nGear | 4 in | 0.899 (Colson) |
| SDS MK5i | SDS.MK5i(...) | SdsMk5Gear | 4 in | 1.6 (Spike Grip) |
| SDS MK5n | SDS.MK5n(...) | SdsMk5Gear | 4 in | 1.6 (Spike Grip) |
| WCP Swerve X | WCP.SwerveX(...) | WcpSwerveXGear | 4 in | 1.0, assumed |
| WCP Swerve X, flipped with gears | WCP.SwerveXFlipped(...) | WcpSwerveXFlippedGear | 4 in | 1.0, assumed |
| WCP Swerve X, flipped with belts | WCP.SwerveXFlippedBelt(...) | WcpSwerveXFlippedBeltGear | 4 in | 1.0, assumed |
| WCP Swerve X2 | WCP.SwerveX2(...) | WcpSwerveX2Gear | 4 in | 1.0, assumed |
| WCP Swerve X2S | WCP.SwerveX2s(...) | WcpSwerveX2sGear | 3.5 in | 1.0, assumed |
| WCP Swerve XS | WCP.SwerveXs(...) | WcpSwerveXsGear | 3 in | 1.0, assumed |
| REV MAXSwerve | REV.MaxSwerve(...) | RevMaxSwerveGear | 3 in | 1.0, assumed |
| Thrifty Swerve | TTB.ThriftySwerve(...) | ThriftySwerveGear | 4 in | 1.0, assumed |
The gear enums are nested in SwerveModules, and each ratio is the one the vendor publishes:
| Gear enum | Gears, with the ratio |
|---|---|
SdsMk4Gear | L1 8.14:1, L2 6.75:1, L3 6.12:1, L4 5.14:1 |
SdsMk4iGear | L1 8.14:1, L2 6.75:1, L3 6.12:1, L1_PLUS 7.13:1, L2_PLUS 5.90:1, L3_PLUS 5.36:1 |
SdsMk4cGear | L1_PLUS 7.13:1, L2_PLUS 5.90:1, L3_PLUS 5.36:1 |
SdsMk4nGear | L1_PLUS 7.13:1, L2_PLUS 5.90:1, L3_PLUS 5.36:1 |
SdsMk5Gear | R1 7.03:1, R2 6.03:1, R3 5.27:1 |
WcpSwerveXGear | X1_10T 7.85:1, X1_11T 7.13:1, X1_12T 6.54:1, X2_10T 6.56:1, X2_11T 5.96:1, X2_12T 5.46:1, X3_12T 5.14:1, X3_13T 4.75:1, X3_14T 4.41:1 |
WcpSwerveXFlippedGear | X1_10T 8.10:1, X1_11T 7.36:1, X1_12T 6.75:1, X2_10T 6.72:1, X2_11T 6.11:1, X2_12T 5.60:1, X3_10T 5.51:1, X3_11T 5.01:1, X3_12T 4.59:1 |
WcpSwerveXFlippedBeltGear | RATIO_7_80 7.80:1, RATIO_6_55 6.55:1, RATIO_5_50 5.50:1 |
WcpSwerveX2Gear | X1_10T 7.67:1, X1_11T 6.98:1, X1_12T 6.39:1, X2_10T 6.82:1, X2_11T 6.20:1, X2_12T 5.68:1, X3_10T 6.48:1, X3_11T 5.89:1, X3_12T 5.40:1, X4_10T 5.67:1, X4_11T 5.15:1, X4_12T 4.73:1 |
WcpSwerveX2sGear | X1_15T 6.00:1, X1_16T 5.63:1, X1_17T 5.29:1, X2_17T 4.94:1, X2_18T 4.67:1, X2_19T 4.42:1, X3_19T 4.11:1, X3_20T 3.90:1, X3_21T 3.71:1 |
WcpSwerveXsGear | X1_12T 6.00:1, X1_13T 5.54:1, X1_14T 5.14:1, X2_14T 4.71:1, X2_15T 4.40:1, X2_16T 4.13:1 |
RevMaxSwerveGear | LOW 5.50:1, MID 5.08:1, HIGH 4.71:1, EXTRA_HIGH_1 4.50:1, EXTRA_HIGH_2 4.29:1, EXTRA_HIGH_3 4.00:1, EXTRA_HIGH_4 3.75:1, EXTRA_HIGH_5 3.56:1 |
ThriftySwerveGear | T12_18 6.75:1, T13_18 6.23:1, T14_18 5.79:1, T12_16 6.00:1, T13_16 5.54:1, T14_16 5.14:1 |
The MK4i’s L1_PLUS to L3_PLUS are for a module with SDS’s 16T drive pinion adapter kit.
The WCP gears are named by ratio set and pinion, so X2_11T is the X2 set with the 11-tooth
pinion. WCP sells its flipped belt kits by ratio, and RATIO_6_55 is the 6.55:1 kit. The Thrifty
gears are named by pinion and second-stage gear, so T13_16 is the 13-tooth pinion with the
16-tooth gear. RevMaxSwerveGear uses REV’s names, except that REV calls MID “Medium”. The
extra-high ratios need REV’s Gear Ratio Upgrade Kit.
The SDS defaults are the tread SDS lists first for the module, Colson on the MK4 family and
Spike Grip on the MK5. For a different wheel, set tread(...) from the
tread table. WCP, REV and Thrifty wheels aren’t in that table and default
to an assumed 1.0, so set cof(...) to a value you measured.
In Python the gear enums are reached through the class, as in SwerveModules.SdsMk4iGear.L2.
C++ writes some gears in mixed case: L1_Plus, Low, Mid, High, ExtraHigh1 and Ratio_6_55.
Override a value
Each override changes the module and returns it, and when two calls set the same property the later one is used. This example sets four values on an MK5n with Colson wheels in place of Spike Grip.
import com.tempo.config.ModuleConfigs;
import com.tempo.config.WheelTread;
ModuleConfigs module = SwerveModules.SDS.MK5n(
SwerveModules.SdsMk5Gear.R2, DCMotor.getKrakenX60Foc(1), Amps.of(60))
.tread(WheelTread.COLSON)
.ratio(5.62) // a ratio not in SdsMk5Gear
.wheelRadius(Meters.of(0.0495)) // measured on a worn 4 in wheel
.topSpeed(MetersPerSecond.of(5.1)); // measured wheel speed at 12 Vfrom tempo import SwerveModules, WheelTread
from wpimath.system.plant import DCMotor
module = (SwerveModules.SDS.MK5n(
SwerveModules.SdsMk5Gear.R2, DCMotor.krakenX60FOC(1), 60.0)
.tread(WheelTread.COLSON)
.ratio(5.62) # a ratio not in SdsMk5Gear
.wheel_radius(0.0495) # measured on a worn 4 in wheel, m
.top_speed(5.1)) # measured wheel speed at 12 V, m/s#include <tempo/WheelTread.h>
auto module = tempo::SwerveModules::SDS::MK5n(
tempo::SwerveModules::SdsMk5Gear::R2, tempo::DcMotor::kraken_x60_foc(), 60.0)
.tread(tempo::WheelTread::Colson)
.ratio(5.62) // a ratio not in SdsMk5Gear
.wheel_radius(0.0495) // measured on a worn 4 in wheel, m
.top_speed(5.1); // measured wheel speed at 12 V, m/sEvery override is listed with its unit and default in ModuleConfigs.
Until you call topSpeed, a preset uses the motor’s free speed through the ratio and radius
as the top speed. A drive on carpet tops out below that, so measure it with
TempoCalibration.topSpeed() or set
topSpeed.
tread(...) takes one of these:
| Tread | Java, Python | C++ | Starting COF |
|---|---|---|---|
| SDS Spike Grip | SPIKE_GRIP | SpikeGrip | 1.6 |
| VEX Grip V2 | VEX_GRIP_V2 | VexGripV2 | 1.916 |
| Black nitrile | BLACK_NITRILE | BlackNitrile | 1.542 |
| Slick neoprene | SLICK_NEOPRENE | SlickNeoprene | 0.978 |
| Colson | COLSON | Colson | 0.899 |
These are typical starting values for fresh tread on carpet, and Spike Grip’s 1.6 is a planning
default. Worn tread grips less, so lower the value as the tread wears, or replace it with a
cof(...) you measured on competition carpet.
For a module that isn’t in the list, use new ModuleConfigs() (ModuleConfigs() in Python,
tempo::ModuleConfigs{} in C++) and set wheelRadius, motor, ratio and
statorCurrentLimit.
Limits Tempo derives
max velocity = topSpeed (the measured or estimated 12 V wheel speed)
max acceleration = min(net wheel force / mass, COF * 9.81)
max centripetal = COF * 9.81Net wheel force is worked out from the motor model at zero speed:
net wheel force = motors * ratio * (motor torque at the current limit - 0.15 * loss torque) / wheel radiusmotors counts every drive motor on the robot, and ratio is the gear ratio.
The loss comes from topSpeed. A motor that only reaches topSpeed at 12 V, below its free
speed, is drawing current at that speed, and Tempo counts that current as drivetrain loss. A
launch from rest pays 15 percent of it and the rest grows with speed.
Paths ask for less acceleration as they speed up, down to none at topSpeed. Braking keeps the
full limit.
To drive routes slower than the hardware allows, set withLimits(...) or a route’s
.limits(...). Don’t lower topSpeed for this, because a lower topSpeed means a larger loss
and less acceleration.
Supply current limit
Set supplyCurrentLimit if your drive motors are TalonFX with a supply current limit at or below
about 60 A and you haven’t run the calibration routines. Phoenix 6 turns
on a 70 A supply limit by default. A limit that high costs almost nothing, so if you never
changed it you can leave this out. SPARK smart current limits are stator limits and go in the
stator current limit.
ModuleConfigs limited = SwerveModules.SDS.MK4i(
SwerveModules.SdsMk4iGear.L3, DCMotor.getKrakenX60Foc(1), Amps.of(120), Amps.of(50));limited = SwerveModules.SDS.MK4i(
SwerveModules.SdsMk4iGear.L3, DCMotor.krakenX60FOC(1), 120.0, 50.0) # ampsauto limited = tempo::SwerveModules::SDS::MK4i(
tempo::SwerveModules::SdsMk4iGear::L3, tempo::DcMotor::kraken_x60_foc(), 120.0, 50.0); // ampsThe limit costs nothing when launching and takes more torque the faster the motor turns.
Tempo lowers the acceleration paths ask for at each speed. The limits from rest, and
Speed.FULL, don’t change.
If your robot code sets one supply limit for teleop and another for autonomous, enter the one the drivetrain runs in autonomous. A curve measured by the calibration routines already includes the supply limit and replaces this model.
Limits set above these
The derived limits are estimates. A value set in LimitsConfigs replaces the estimate and can be
higher than it, up to what the hardware allows with no loss at all:
top speed = motor free speed / gear ratio * wheel radius (or topSpeed, if higher)
acceleration = min(motors * ratio * motor torque at the current limit / wheel radius / mass, COF * 9.81)
centripetal = COF * 9.81
angular velocity = top speed / largest module offset
angular acceleration = that acceleration * average module offset / inertia per kilogramA value above one of these ceilings plans at the ceiling.
Measured limits take the place of these. On a config with no motors to model, such as mecanum, the values set are used as they are.
This prints the derived limits:
import com.tempo.TrajectoryConstraints;
TrajectoryConstraints limits = CONFIG.constraints();
System.out.println(limits.maxVelocityMps() + " m/s, " + limits.maxAccelerationMps2() + " m/s^2");limits = CONFIG.constraints
print(limits.max_velocity_mps, "m/s,", limits.max_acceleration_mps2, "m/s^2")#include <iostream>
// after tempo::wpi::configure(...)
auto limits = tempo::Tempo::config().constraints;
std::cout << limits.max_velocity_mps << " m/s, " << limits.max_acceleration_mps2 << " m/s^2\n";The velocity and centripetal limits are fixed numbers on each leg, and acceleration follows the motor curve above. Battery sag and per-module force aren’t modeled. Trajectory limits lists the ways to set your own.
From Tuner X constants
A CTRE Tuner X TunerConstants file for Phoenix 6 v26 has the wheel radius, gearing, 12 V speed,
slip current and the drive motors’ supply current limit. This example builds the module from it.
getModuleTranslations() stands in for a method in your robot code that returns the four module positions.It goes in the drivetrain subsystem, where Phoenix 6’s module_locations property has the four module positions.It goes in the drivetrain subsystem, where Phoenix 6’s GetModuleLocations() returns the four module positions.
import static edu.wpi.first.units.Units.*;
import com.tempo.config.ModuleConfigs;
import com.tempo.config.TempoConfig;
import edu.wpi.first.math.system.plant.DCMotor;
import frc.robot.generated.TunerConstants;
public static final TempoConfig CONFIG = new TempoConfig()
.withModule(new ModuleConfigs()
.wheelRadius(TunerConstants.FrontLeft.WheelRadius) // meters
.topSpeed(TunerConstants.kSpeedAt12Volts) // wheel speed at 12 V
.cof(1.1) // wheel COF; measure on the carpet
.motor(DCMotor.getKrakenX60Foc(1))
.ratio(TunerConstants.FrontLeft.DriveMotorGearRatio)
.statorCurrentLimit(TunerConstants.FrontLeft.SlipCurrent) // amps
.supplyCurrentLimit(TunerConstants.FrontLeft.DriveMotorInitialConfigs
.CurrentLimits.SupplyCurrentLimit)) // amps
.withMass(Kilograms.of(60.6))
.withModuleOffsets(getModuleTranslations()); // a Translation2d[]from generated.tuner_constants import TunerConstants
from tempo import ModuleConfigs, TempoConfig
from wpimath.system.plant import DCMotor
config = (TempoConfig()
.with_module(ModuleConfigs()
.wheel_radius(TunerConstants.front_left.wheel_radius) # meters
.top_speed(TunerConstants.speed_at_12_volts) # wheel speed at 12 V
.cof(1.1) # wheel COF; measure on the carpet
.motor(DCMotor.krakenX60FOC(1))
.ratio(TunerConstants.front_left.drive_motor_gear_ratio)
.stator_current_limit(TunerConstants.front_left.slip_current) # amps
.supply_current_limit(TunerConstants.front_left.drive_motor_initial_configs
.current_limits.supply_current_limit)) # amps
.with_mass(60.6) # kilograms
.with_module_offsets(self.module_locations))#include <tempo/Tempo.h>
#include "generated/TunerConstants.h"
auto const config = tempo::TempoConfig{}
.with_module(tempo::ModuleConfigs{}
.wheel_radius(TunerConstants::FrontLeft.WheelRadius) // meters
.top_speed(TunerConstants::kSpeedAt12Volts) // wheel speed at 12 V
.cof(1.1) // wheel COF; measure on the carpet
.motor(tempo::DcMotor::kraken_x60_foc())
.ratio(TunerConstants::FrontLeft.DriveMotorGearRatio)
.stator_current_limit(TunerConstants::FrontLeft.SlipCurrent) // amps
.supply_current_limit(TunerConstants::FrontLeft.DriveMotorInitialConfigs
.CurrentLimits.SupplyCurrentLimit)) // amps
.with_mass(60.6) // kilograms
.with_module_offsets(GetModuleLocations());If the file sets no supply limit for the drive motors, this reads the Phoenix 6 default of 70 A.
If SupplyCurrentLimitEnable is false in the file’s driveInitialConfigs, leave out
supplyCurrentLimit. In Python those are supply_current_limit_enable, _drive_initial_configs
and supply_current_limit.
With SwerveRequest.ApplyRobotSpeeds and its default drive request type, OpenLoopVoltage, the
drive trails its commands by more than the follower latency Tempo
estimates. A route on the estimate measures the lag while it drives and leads by it.
Angular limits and latency
import com.tempo.config.LimitsConfigs;
public static final TempoConfig CONFIG = new TempoConfig()
// ... the rest of the config
.withLimits(new LimitsConfigs()
.maxAngularVelocity(DegreesPerSecond.of(450))
.maxAngularAcceleration(RadiansPerSecondPerSecond.of(12)))
.withLag(Milliseconds.of(20));from tempo import LimitsConfigs, TempoConfig
from tempo.rates import deg_per_sec
CONFIG = (TempoConfig()
# ... the rest of the config
.with_limits(LimitsConfigs()
.max_angular_velocity(deg_per_sec(450))
.max_angular_acceleration(12.0)) # rad/s^2
.with_lag(0.020)) # s#include <tempo/Rates.h>
inline const tempo::TempoConfig kConfig = tempo::TempoConfig{}
// ... the rest of the config
.with_limits(tempo::LimitsConfigs{}
.max_angular_velocity(tempo::rates::deg_per_sec(450))
.max_angular_acceleration(12.0)) // rad/s^2
.with_lag(0.020); // smaxAngularVelocity caps the planned turn rate. If it isn’t set, the cap is the velocity of
Speed.FULL divided by the largest module offset. That
is the turn rate that runs the outer wheel at top speed.
maxAngularAcceleration caps how fast planned turns speed up and slow down. When a leg’s turn
needs more time than its drive, the leg is planned to take longer. If it isn’t set, Tempo
calculates the cap from the Speed.FULL acceleration, the module offsets and the bumper outline
from withFrame(...) and withBumpers(...). If the robot’s mass sits away from its center,
measure the cap on the robot and set it.
Heading feedback is added to the planned turn rate. While the robot catches up, a command can turn faster than the velocity cap and change its turn rate faster than the acceleration cap. The defaults and the ceiling for each value are in Trajectory limits.
withLag is the drivetrain’s sensor and actuation delay in seconds (or a Time in Java). The
follower sends the speeds the plan has that far ahead in time. Without one, Tempo uses the
lag from your calibration if you have one, and otherwise it
estimates the delay from the modules and mass.
A value lower than the real delay makes the robot trail the path and swing wide in corners. A value that’s too high makes it cut corners.
While a route drives, Tempo measures how far the drivetrain trails its commands. A route on the
estimated latency leads by the measured lag when that is more than half a loop longer than the
estimate. The routes after it start on that lag until Tempo.configure(...) runs again. A
withLag you set and a lag from calibration aren’t replaced by this measurement. To measure the
delay yourself, run the command lag routine. The estimate’s
formula and the rules for the measurement are in the
Drivetrain reference.
If it fails…
A speed cap was entered as topSpeed. Give topSpeed the measured wheel speed at 12 V and cap route speed with a trajectory limit.
The derived acceleration is too high. Check the motor type, gearing and wheel radius.
topSpeed is so low that the losses use the whole drive current limit. Measure the wheel speed at 12 V again.