3.15 Mecanum drive
Tempo plans for a mecanum robot the same way it plans for swerve, except that it accounts for roller slip when strafing and for the four wheels sharing their speed between driving and turning.
Configure the drivetrain
import com.tempo.Tempo;
import com.tempo.config.*;
import edu.wpi.first.math.geometry.Translation2d;
import static edu.wpi.first.units.Units.*;
// Shared with the kinematics.
static final Translation2d FL = new Translation2d(0.28, 0.27);
static final Translation2d FR = new Translation2d(0.28, -0.27);
static final Translation2d BL = new Translation2d(-0.28, 0.27);
static final Translation2d BR = new Translation2d(-0.28, -0.27);
static final double MAX_SPEED_MPS = 3.8; // measured forward speed
public static final TempoConfig CONFIG = new TempoConfig()
.withMecanum(new MecanumConfigs()
.strafeEfficiency(0.75) // measured; default 0.8
.wheelOffsets(FL, FR, BL, BR)) // front left, front right, back left, back right
.withLimits(new LimitsConfigs()
.maxVelocity(MetersPerSecond.of(MAX_SPEED_MPS))
.maxAcceleration(MetersPerSecondPerSecond.of(3.0)))
.withFrame(0.71, 0.71)
.withBumpers(new BumperConfigs().thickness(0.09));
Tempo.configure(this::getPose, this::resetPose, this::getRobotRelativeSpeeds,
this::runVelocity, CONFIG, this);from tempo import BumperConfigs, LimitsConfigs, MecanumConfigs, Tempo, TempoConfig
from wpimath.geometry import Translation2d
# Constants shared with the kinematics.
FL = Translation2d(0.28, 0.27)
FR = Translation2d(0.28, -0.27)
BL = Translation2d(-0.28, 0.27)
BR = Translation2d(-0.28, -0.27)
MAX_SPEED_MPS = 3.8 # measured forward speed
CONFIG = (TempoConfig()
.with_mecanum(MecanumConfigs()
.strafe_efficiency(0.75) # measured; default 0.8
.wheel_offsets(FL, FR, BL, BR)) # front left, front right, back left, back right
.with_limits(LimitsConfigs()
.max_velocity(MAX_SPEED_MPS) # m/s
.max_acceleration(3.0)) # m/s^2
.with_frame(0.71, 0.71)
.with_bumpers(BumperConfigs().thickness(0.09)))
Tempo.configure(self.get_pose, self.reset_pose, self.get_robot_relative_speeds,
self.run_velocity, CONFIG, self)#include <tempo/Tempo.h>
#include <tempo/wpi/Setlist.h>
inline const tempo::TempoConfig kConfig = tempo::TempoConfig{}
.with_mecanum(tempo::MecanumConfigs{}
.strafe_efficiency(0.75) // measured; default 0.8
.wheel_offsets({{0.28, 0.27}, {0.28, -0.27}, {-0.28, 0.27}, {-0.28, -0.27}})) // FL, FR, BL, BR
.with_limits(tempo::LimitsConfigs{}
.max_velocity(3.8) // m/s, measured forward speed
.max_acceleration(3.0)) // m/s^2
.with_frame(0.71, 0.71)
.with_bumpers(tempo::BumperConfigs{}.thickness(0.09));
tempo::wpi::configure(
[this] { return GetPose(); },
[this](const frc::Pose2d& pose) { ResetPose(pose); },
[this] { return GetRobotRelativeSpeeds(); },
[this](const frc::ChassisSpeeds& speeds) { RunVelocity(speeds); },
kConfig,
{this});A mecanum config needs withMecanum(...), withLimits(...) with both maxVelocity and
maxAcceleration, and withFrame(...) or withFootprint(...). Tempo.configure(...) throws
without them, because MecanumConfigs has no motor model to work the limits out from and the
wheel offsets are only used for turning.
MecanumConfigs has three settings, and their ranges and error messages are in
MecanumConfigs:
strafeEfficiency(e)is the fraction of the commanded sideways speed the wheels deliver. The default is 0.8, and you measure it as described below.wheelOffsets(fl, fr, bl, br)are the wheel positions in meters, robot frame, +x forward and +y left. In Python they can beTranslation2dvalues or(x, y)tuples.In C++ they’re four{x, y}pairs.margin(m)is the fraction of wheel speed and acceleration the plan leaves unused, and the default is 0.
maxVelocity is the robot’s speed driving straight forward, and Tempo uses it as the speed limit
for each wheel. A strafe or a leg that turns tops out lower.
If wheelOffsets isn’t set, Tempo uses the footprint’s corners for turning. Those are outside
the wheels, so turns are planned slower than they need to be.
Converting the output
The velocity method (runVelocity in the example above) gets robot-relative WPILib
ChassisSpeeds. This example converts them to wheel speeds with WPILib’s
MecanumDriveKinematics, built from the same four offsets. The four set...Velocity methods
stand for your own closed-loop wheel setters, in m/s.
getRobotRelativeSpeeds goes the other way and returns the same kinematics’
toChassisSpeeds(...) of the measured wheel speeds.
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.kinematics.MecanumDriveKinematics;
import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds;
private final MecanumDriveKinematics kinematics = new MecanumDriveKinematics(FL, FR, BL, BR);
public void runVelocity(ChassisSpeeds speeds) {
MecanumDriveWheelSpeeds wheels = kinematics.toWheelSpeeds(speeds);
wheels.desaturate(MAX_SPEED_MPS); // scales all four together if one is over
setFrontLeftVelocity(wheels.frontLeftMetersPerSecond);
setFrontRightVelocity(wheels.frontRightMetersPerSecond);
setBackLeftVelocity(wheels.rearLeftMetersPerSecond);
setBackRightVelocity(wheels.rearRightMetersPerSecond);
}from wpimath.kinematics import ChassisSpeeds, MecanumDriveKinematics
self.kinematics = MecanumDriveKinematics(FL, FR, BL, BR)
def run_velocity(self, speeds: ChassisSpeeds):
wheels = self.kinematics.toWheelSpeeds(speeds)
wheels.desaturate(MAX_SPEED_MPS) # scales all four together if one is over
# The team's closed-loop wheel setters, in m/s.
self.set_front_left_velocity(wheels.frontLeft)
self.set_front_right_velocity(wheels.frontRight)
self.set_back_left_velocity(wheels.rearLeft)
self.set_back_right_velocity(wheels.rearRight)#include <frc/kinematics/ChassisSpeeds.h>
#include <frc/kinematics/MecanumDriveKinematics.h>
frc::MecanumDriveKinematics kinematics{
frc::Translation2d{0.28_m, 0.27_m}, frc::Translation2d{0.28_m, -0.27_m},
frc::Translation2d{-0.28_m, 0.27_m}, frc::Translation2d{-0.28_m, -0.27_m}};
void RunVelocity(const frc::ChassisSpeeds& speeds) {
auto wheels = kinematics.ToWheelSpeeds(speeds);
wheels.Desaturate(3.8_mps); // scales all four together if one is over
SetFrontLeftVelocity(wheels.frontLeft);
SetFrontRightVelocity(wheels.frontRight);
SetBackLeftVelocity(wheels.rearLeft);
SetBackRightVelocity(wheels.rearRight);
}The samples use the 2026 names: ChassisSpeeds, toWheelSpeeds and
MecanumDriveWheelSpeeds, whose desaturate changes the speeds in place. The C++ _m and
_mps literals need no using line.
In Java, ChassisSpeeds becomes org.wpilib.math.kinematics.ChassisVelocities, and
toWheelVelocities returns a MecanumDriveWheelVelocities with fields frontLeft,
frontRight, rearLeft and rearRight. Its desaturate returns a new value:
wheels = wheels.desaturate(MAX_SPEED_MPS). toChassisSpeeds becomes
toChassisVelocities. See
2026 vs 2027.
On RobotPy 2027 run_velocity gets a ChassisVelocities, imported with
from wpimath import ChassisVelocities, and desaturate returns a new value:
wheels = wheels.desaturate(MAX_SPEED_MPS). On alpha-6, toWheelSpeeds and toChassisSpeeds
become toWheelVelocities and toChassisVelocities. Alpha-7 and beyond spell them
to_wheel_velocities and to_chassis_velocities, and the wheel fields front_left,
front_right, rear_left and rear_right. See
2026 vs 2027.
On 2027, frc::ChassisSpeeds becomes wpi::math::ChassisVelocities, and ToWheelSpeeds and
ToChassisSpeeds become ToWheelVelocities and ToChassisVelocities. Desaturate returns a
new value:
wheels = wheels.Desaturate(3.8_mps). See
2026 vs 2027.
Driving a route
Routes are written the same way as on swerve, and rotation targets,
Locks and Keys and aims all work. This route uses the
REEFSCAPE 2025 pack and the poses START_LEFT, REEF_IR and STATION_LEFT from
Routes & waypoints.
import com.tempo.Alliance;
import com.tempo.Composer;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj2.command.Command;
Composer route = Composer.startAt(new Pose2d(7.58, 5.85, Rotation2d.k180deg))
.originAlliance(Alliance.BLUE)
.resetOdometry(true)
.to(5.13, 5.14, Rotation2d.fromDegrees(-120)) // REEF_IR: turns 60 deg on the way
.to(2.5, 6.2) // no heading: turns to face along the leg
.to(1.13, 7.00, Rotation2d.fromDegrees(126)); // STATION_LEFT
Command auto = route.command();import math
from tempo import Alliance, Composer
from wpimath.geometry import Pose2d
route = (Composer.start_at(Pose2d(7.58, 5.85, math.pi))
.origin_alliance(Alliance.BLUE)
.reset_odometry(True)
.to(5.13, 5.14, math.radians(-120)) # REEF_IR: turns 60 deg on the way
.to(2.5, 6.2) # no heading: turns to face along the leg
.to(1.13, 7.00, math.radians(126))) # STATION_LEFT
auto = route.command()#include <numbers>
#include <tempo/Composer.h>
#include <tempo/wpi/Setlist.h>
constexpr double kDeg = std::numbers::pi / 180.0;
auto route = tempo::Composer::start_at(7.58, 5.85, 180 * kDeg)
.origin_alliance(tempo::Alliance::Blue)
.reset_odometry(true)
.to(5.13, 5.14, -120 * kDeg) // REEF_IR: turns 60 deg on the way
.to(2.5, 6.2) // no heading: turns to face along the leg
.to(1.13, 7.00, 126 * kDeg); // STATION_LEFT
frc2::CommandPtr autoCommand = tempo::wpi::command(route);What differs from swerve
The plan keeps the fastest wheel at or under maxVelocity times 1 - margin. The formula is in
the reference. On the robot that looks like this:
- With no margin, forward runs at
maxVelocity, a pure strafe at the strafe efficiency times that (2.85 m/s for the example robot), and a diagonal slower than both. A pure strafe also gets the strafe efficiency times the forward acceleration. - A leg that turns while it drives is slower than one that holds its heading. To lower the turn
rate, set
LimitsConfigs.maxAngularVelocity(...). - On a waypoint with no heading,
to(x, y), 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. Swerve keeps its heading there, or starts turning toward a heading that a later waypoint asks for (Waypoint heading). - An aim at a fixed point is planned with the path, and the path slows down where the turn needs wheel speed.
- A live aim, from a supplier or gated by a
Condition, isn’t planned ahead. When a live turn needs more than the wheels have, Tempo scales translation and rotation down together, and the robot falls behind the plan until feedback brings it back.
margin(0.1) plans every leg at 90 percent of the wheel speed and acceleration and leaves the
other 10 percent for when the battery sags or the rollers slip more than measured.
Measuring strafe efficiency
- Mark a 3 m straight line on competition carpet.
- Command a robot-relative forward speed below top speed, such as
vx = 1.5m/s, and time the drive over the 3 m. - Command the same speed sideways,
vy = 1.5m/s, and time the strafe over the same 3 m. - Divide the forward time by the strafe time. 3 m forward in 2.1 s and sideways in 2.8 s gives
2.1 / 2.8 = 0.75.
Use a stopwatch or a camera for the times. Don’t take the speed from wheel odometry, because the wheel encoders count roller slip as motion and report the commanded strafe speed even when the robot is going slower. The same slip makes a mecanum pose estimate drift sideways during a strafe, and vision fused into the pose estimate reduces the drift.
Measure again after a carpet or roller change, because strafe efficiency depends on the rollers, the carpet and the robot’s weight. If the value is too high, strafes are planned faster than the wheels can drive them, and if it’s too low strafes are slower than they need to be.
In Tempo’s GUI
Choose Mecanum as the drivetrain type on the GUI’s Robot screen. The
Strafe efficiency, Planning margin and Wheel positions fields export as the three
mecanum settings, and the path limits export as the LimitsConfigs. The motor, reduction and
wheel radius on the Drive hardware card aren’t exported. Until wheel positions are set, the card
shows From bumper footprint.
If it fails…
The wheel order given to MecanumDriveKinematics doesn’t match the order of the motor setters. Both go front left, front right, back left, back right.
The rollers slip more than the strafe efficiency allows for, so measure it and set strafeEfficiency.
Pass the measured fraction, forward time divided by strafe time.