4.4 Drivetrain
A config takes one drivetrain: withModule(...), withTank(...) or withMecanum(...).
Swerve
| Java | Python / C++ | Unit | Default |
|---|---|---|---|
withModule(ModuleConfigs) | with_module(module) | Required. One module is used for all four | |
withMass(kg), withMass(Mass) | with_mass(kg) | kg, bumpers and battery included | Required to derive limits |
withModuleOffsets(frontLeft, frontRight, backLeft, backRight), withModuleOffsets(Translation2d[]) | with_module_offsets(...) | m, robot frame | Required to derive limits |
withLag(s), withLag(Time) | with_lag(s) | s | The calibrated lag, else an estimate (Follower latency) |
Speed and acceleration are derived from the module, mass and offsets
(Swerve drive). A swerve config without mass or offsets needs
withLimits with both maxVelocity and maxAcceleration, and without offsets it also needs
withFrame or withFootprint. Turn rate and turn acceleration are set in
LimitsConfigs. withLag takes zero (no lead) or more, or a plain SI
supplier, and a negative or non-finite value throws.
Follower latency
The follower leads its feedforward by the latency. Tempo uses the first of these that exists:
- A
withLagthat is set. It leads speed and direction by the same value, up to the follower’s cap of 100 ms. - The lag from calibration. The direction is then led by the calibrated steering lag.
- An estimate, 40 percent of the drive’s time constant and at most 50 ms:
time constant = (mass / modules) * wheel radius * topSpeed / (motor stall torque * ratio * motors per module)A drive motor that gets a voltage for each speed and has no velocity loop trails a speed
ramp by the whole time constant. A CTRE swerve request with the default OpenLoopVoltage
drive request type drives that way.
While a route drives, it measures how far the drivetrain trails its commands. A set or calibrated latency keeps its feedforward lead.
| Measurement | Rule |
|---|---|
| Braking | When the measured lag is more than half a loop longer than the latency, the route uses the measured lag when it brakes for a stop |
| Drive lag | Measured once the commands have changed by 2 m/s, which takes 0.2 s at 10 m/s^2. A route on the estimate then leads its feedforward by the measured lag, when that is more than half a loop longer than the estimate |
| Later routes | They start on the measured lag until Tempo.configure(...) runs again. A route that starts on it keeps it until the robot has slowed down as well as sped up, because a lag measured only while speeding up comes out too long |
| Steering lag | How far the direction of travel trails the direction commanded. It is measured once the commanded direction has turned through 2 m/s of velocity, counted as the speed times the angle turned in radians. That is a quarter turn at 1.3 m/s or 25 degrees at 4.5 m/s. From then on the route leads the direction by the steering lag and the speed by the drive lag. Before that, and on a straight route, it leads both by the drive lag |
| Cap | The measured lead is at most 60 ms. While the measured drive lag is longer than that, the direction is led by 60 ms as well |
| Robot can’t reach the planned acceleration | The route keeps the estimate |
| Pose jump from a vision update or a reset | Not counted as motion |
ModuleConfigs
A module starts from a preset, SDS.MK5n(gear, motor, statorLimit) or
SDS.MK5n(gear, motor, statorLimit, supplyLimit), or from new ModuleConfigs(). Each
value is a plain SI number or a WPILib unit.
import com.tempo.config.*;
import com.tempo.config.SwerveModules.SdsMk5Gear;
import edu.wpi.first.math.system.plant.DCMotor;
import static edu.wpi.first.units.Units.*;
ModuleConfigs preset = SwerveModules.SDS.MK5n(
SdsMk5Gear.R2, DCMotor.getKrakenX60Foc(1), Amps.of(80), Amps.of(60))
.wheelRadius(Inches.of(1.95))
.topSpeed(4.62);
ModuleConfigs custom = new ModuleConfigs()
.wheelRadius(0.0495)
.motor(DCMotor.getKrakenX60Foc(1))
.ratio(6.03)
.statorCurrentLimit(80);from tempo import ModuleConfigs, SwerveModules
from wpimath.system.plant import DCMotor
preset = (SwerveModules.SDS.MK5n(
SwerveModules.SdsMk5Gear.R2, DCMotor.krakenX60FOC(1), 80, 60)
.wheel_radius(0.0495)
.top_speed(4.62))
custom = (ModuleConfigs()
.wheel_radius(0.0495)
.motor(DCMotor.krakenX60FOC(1))
.ratio(6.03)
.stator_current_limit(80))#include <tempo/ModuleConfigs.h>
#include <tempo/SwerveModules.h>
auto preset = tempo::SwerveModules::SDS::MK5n(
tempo::SwerveModules::SdsMk5Gear::R2, tempo::DcMotor::kraken_x60_foc(), 80_A, 60_A)
.wheel_radius(1.95_in)
.top_speed(4.62);
auto custom = tempo::ModuleConfigs{}
.wheel_radius(0.0495)
.motor(tempo::DcMotor::kraken_x60_foc())
.ratio(6.03)
.stator_current_limit(80.0);| Java | Python / C++ | Unit | Default |
|---|---|---|---|
wheelRadius(m) | wheel_radius(m) | m | The preset’s wheel. Required on new ModuleConfigs() |
cof(value) | cof(value) | The preset’s wheel, else an assumed 1.0 | |
tread(WheelTread) | tread(tread) | Sets cof to the tread’s starting value | |
topSpeed(mps) | top_speed(mps) | m/s, the real top speed at 12 V | Estimated from the motor’s free speed, the ratio and the wheel radius |
motor(DCMotor) | motor(motor) | One motor before its reduction | The preset’s motor. Required on new ModuleConfigs() |
motorCount(count) | motor_count(count) | Drive motors per module | 1 |
ratio(ratio) | ratio(ratio) | :1 | The preset’s gear. Required on new ModuleConfigs() |
statorCurrentLimit(amps) | stator_current_limit(amps) | A | The preset’s third argument. Required on new ModuleConfigs() |
supplyCurrentLimit(amps) | supply_current_limit(amps) | A | The preset’s optional fourth argument. No limit without it |
A topSpeed you set stays the same when you change the motor, ratio or wheel radius. At
startup Tempo warns when the losses it estimates from topSpeed are 70 percent or more of
the drive current limit (Swerve drive).
cof, topSpeed, statorCurrentLimit and supplyCurrentLimit also take a plain SI supplier
(Live tuning). Preset arguments stay numbers or units.
MecanumConfigs
import com.tempo.config.*;
import edu.wpi.first.math.geometry.Translation2d;
import static edu.wpi.first.units.Units.*;
public static final TempoConfig CONFIG = new TempoConfig()
.withMecanum(new MecanumConfigs()
.strafeEfficiency(0.8)
.margin(0.1)
.wheelOffsets(
new Translation2d(0.28, 0.27), new Translation2d(0.28, -0.27), // FL, FR
new Translation2d(-0.28, 0.27), new Translation2d(-0.28, -0.27))) // BL, BR
.withLimits(new LimitsConfigs()
.maxVelocity(MetersPerSecond.of(4.0))
.maxAcceleration(MetersPerSecondPerSecond.of(3.0)))
.withFrame(0.66, 0.71)
.withBumpers(new BumperConfigs().thickness(0.09));from tempo import BumperConfigs, LimitsConfigs, MecanumConfigs, TempoConfig
CONFIG = (TempoConfig()
.with_mecanum(MecanumConfigs()
.strafe_efficiency(0.8)
.margin(0.1)
.wheel_offsets((0.28, 0.27), (0.28, -0.27), # FL, FR
(-0.28, 0.27), (-0.28, -0.27))) # BL, BR
.with_limits(LimitsConfigs().max_velocity(4.0).max_acceleration(3.0))
.with_frame(0.66, 0.71)
.with_bumpers(BumperConfigs().thickness(0.09)))#include <tempo/Tempo.h>
inline const tempo::TempoConfig kConfig = tempo::TempoConfig{}
.with_mecanum(tempo::MecanumConfigs{}
.strafe_efficiency(0.8)
.margin(0.1)
.wheel_offsets({{0.28, 0.27}, {0.28, -0.27}, // FL, FR
{-0.28, 0.27}, {-0.28, -0.27}})) // BL, BR
.with_limits(tempo::LimitsConfigs{}.max_velocity(4.0).max_acceleration(3.0))
.with_frame(0.66, 0.71)
.with_bumpers(tempo::BumperConfigs{}.thickness(0.09));| Java | Python / C++ | Range | Default |
|---|---|---|---|
strafeEfficiency(e) | strafe_efficiency(e) | finite, (0, 1] | 0.8 |
margin(f) | margin(f) | finite, [0, 1) | 0 |
wheelOffsets(fl, fr, bl, br) | wheel_offsets(...) | four finite points, m | Radius from the footprint |
- Strafe efficiency is the sideways speed a pure strafe reaches over the speed
commanded, so a sideways speed
vycostsvy / eof wheel speed. - The margin scales the trajectory’s velocity and acceleration by
1 - margin, for battery sag and roller slip. - Wheel offsets are in the robot frame with +x forward and +y left, and they go in the
order front left, front right, back left, back right. Java takes four
Translation2d, Python takes four(x, y)pairs orTranslation2d, and C++ takesstd::vector<std::array<double, 2>>. - The turn radius is the largest
abs(x) + abs(y)over the wheels, in meters. A built Java config returns it frommecanum().turnRadiusM(), which is null without offsets. Without offsets the planner uses the largestabs(x) + abs(y)over the footprint’s corners. The corners are farther out than the wheels, so turns are then planned slower than the real wheels need. maxVelocityis the speed driving straight forward. The fastest wheel runs atabs(vx) + abs(vy) / e + radius * abs(omega), whereradiusis the turn radius. The plan keeps that wheel speed withinmaxVelocity, so strafing, diagonals and turning while driving run slower. Acceleration is shared the same way.- The default rotation cap is
maxVelocity / radius, and you can set another withLimitsConfigs.maxAngularVelocity(...).
Each setter checks its value when called:
| Message | Cause |
|---|---|
[Tempo] mecanum strafe efficiency must be above 0 and at most 1; got 1.5 | Efficiency outside (0, 1] or not finite |
[Tempo] mecanum margin must be finite, at least 0 and below 1 | Margin outside [0, 1) |
[Tempo] mecanum wheel offsets are four, FL, FR, BL, BR; got 3 | Python and C++: not four offsets. Java’s wheelOffsets takes four parameters |
[Tempo] mecanum wheel offsets need all four wheels; the back-right offset is missing | Java and Python: a null or None offset |
[Tempo] mecanum wheel offsets must be finite; the front-left offset is not | NaN or infinite coordinate |
[Tempo] a mecanum wheel offset is an (x, y) pair or a Translation2d; got str | Python: another type |
A mecanum config also needs a withLimits with both maxVelocity and maxAcceleration,
and withFrame or withFootprint. It throws when it’s resolved without them. Setup and
measuring strafe efficiency are on Mecanum drive.
TankConfigs
import com.tempo.config.*;
import edu.wpi.first.math.system.plant.DCMotor;
import static edu.wpi.first.units.Units.Kilograms;
private static final TankSideConfigs SIDE = new TankSideConfigs()
.motor(DCMotor.getKrakenX60Foc(1))
.motorCount(2)
.ratio(8.45)
.wheelRadius(0.0762)
.statorCurrentLimit(60);
public static final TempoConfig CONFIG = new TempoConfig()
.withTank(new TankConfigs().left(SIDE).right(SIDE).topSpeed(5.2).trackWidth(0.6))
.withMass(Kilograms.of(50))
.withFrame(0.71, 0.71);from tempo import TankConfigs, TankSideConfigs, TempoConfig
from wpimath.system.plant import DCMotor
SIDE = (TankSideConfigs()
.motor(DCMotor.krakenX60FOC(1))
.motor_count(2)
.ratio(8.45)
.wheel_radius(0.0762)
.stator_current_limit(60))
CONFIG = (TempoConfig()
.with_tank(TankConfigs().left(SIDE).right(SIDE).top_speed(5.2).track_width(0.6))
.with_mass(50.0) # kg
.with_frame(0.71, 0.71))#include <tempo/Tempo.h>
inline const tempo::TankSideConfigs kSide = tempo::TankSideConfigs{}
.motor(tempo::DcMotor::kraken_x60_foc())
.motor_count(2)
.ratio(8.45)
.wheel_radius(0.0762)
.stator_current_limit(60.0);
inline const tempo::TempoConfig kConfig = tempo::TempoConfig{}
.with_tank(tempo::TankConfigs{}.left(kSide).right(kSide).top_speed(5.2).track_width(0.6))
.with_mass(50.0) // kg
.with_frame(0.71, 0.71);TankConfigs Java | Python / C++ | Unit | Default |
|---|---|---|---|
left(side) | left(side) | A TankSideConfigs | Required |
right(side) | right(side) | A TankSideConfigs | Required |
topSpeed(mps) | top_speed(mps) | m/s, the real top speed at 12 V | Required |
trackWidth(m) | track_width(m) | m, between the left and right wheels | Required |
cof(value) | cof(value) | 1.1 |
TankSideConfigs Java | Python / C++ | Unit | Default |
|---|---|---|---|
motor(DCMotor) | motor(motor) | One motor before its reduction | Required |
motorCount(count) | motor_count(count) | Motors on this side | 1 |
ratio(ratio) | ratio(ratio) | :1 | Required |
wheelRadius(m) | wheel_radius(m) | m | Required |
statorCurrentLimit(amps) | stator_current_limit(amps) | A, per motor | Required |
A tank config also needs withMass(...). The two sides together can have at most four
motors. Acceleration is the smaller of the net motor force over the mass and cof * 9.81,
and centripetal acceleration is capped at cof * 9.81.
Differential drive has the setup and the freeze rules.