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

3.16 Differential drive

Configure a differential drive with withTank(...) and connect the same four drivetrain methods as any other robot. Tempo slows the robot in curves to keep the outer wheel under its top speed. The robot faces along its path, driving forward or backward, and the speeds Tempo sends have vy = 0.

Configuring the drivetrain

Java
import com.tempo.Tempo;
import com.tempo.config.*;
import edu.wpi.first.math.system.plant.DCMotor;
import static edu.wpi.first.units.Units.*;

private static final TankSideConfigs SIDE = new TankSideConfigs()
    .motor(DCMotor.getKrakenX60Foc(1))  // One motor
    .ratio(8.45)                        // Gear reduction
    .motorCount(2)                      // Motors per side
    .wheelRadius(0.0762)                // Wheel radius in meters
    .statorCurrentLimit(60.0);          // Current limit per motor in amps

public static final TempoConfig CONFIG = new TempoConfig()
    .withTank(new TankConfigs()
        .left(SIDE)
        .right(SIDE)
        .topSpeed(5.2)                  // m/s
        .trackWidth(0.6))               // m
    .withMass(Kilograms.of(54.0))       // Includes battery and bumpers
    .withFrame(0.71, 0.71)
    .withBumpers(new BumperConfigs().thickness(0.09));

Tempo.configure(this::getPose, this::resetPose, this::getRobotRelativeSpeeds,
    this::runVelocity, CONFIG, this);
Python
from tempo import BumperConfigs, TankConfigs, TankSideConfigs, Tempo, TempoConfig
from wpimath.system.plant import DCMotor

SIDE = (TankSideConfigs()
    .motor(DCMotor.krakenX60FOC(1))  # One motor
    .ratio(8.45)                     # Gear reduction
    .motor_count(2)                  # Motors per side
    .wheel_radius(0.0762)            # Wheel radius in meters
    .stator_current_limit(60.0))     # Current limit per motor in amps

CONFIG = (TempoConfig()
    .with_tank(TankConfigs()
        .left(SIDE)
        .right(SIDE)
        .top_speed(5.2)              # m/s
        .track_width(0.6))           # m
    .with_mass(54.0)                 # Kilograms, including battery and bumpers
    .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)
C++
#include <tempo/Tempo.h>
#include <tempo/wpi/Setlist.h>

inline const tempo::TankSideConfigs kSide = tempo::TankSideConfigs{}
    .motor(tempo::DcMotor::kraken_x60_foc())  // One motor
    .ratio(8.45)                              // Gear reduction
    .motor_count(2)                           // Motors per side
    .wheel_radius(0.0762)                     // Wheel radius in meters
    .stator_current_limit(60.0);              // Current limit per motor in amps

inline const tempo::TempoConfig kConfig = tempo::TempoConfig{}
    .with_tank(tempo::TankConfigs{}
        .left(kSide)
        .right(kSide)
        .top_speed(5.2)                       // m/s
        .track_width(0.6))                    // m
    .with_mass(54.0)                          // Kilograms, including battery and bumpers
    .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});

motorCount (motor_count) is the number of motors on one side, and the two sides together can have at most four. A config with withTank(...) also needs withMass(...).

topSpeed (top_speed) is the measured speed at 12 V. If you want routes to drive slower, use withLimits(...) and leave topSpeed at the measured speed. Tempo works out acceleration from the motors, the mass and cof, the same way it does on swerve (Limits Tempo derives). TankConfigs lists every setting.

Tempo counts the gap between topSpeed and the motor’s free speed through ratio and wheelRadius as drivetrain loss. When the loss takes 70% of the current limit, the console prints a [Tempo] WARNING: left gearbox: line for each side, and when it takes the whole limit, building the config throws. A topSpeed at or above the free speed prints a warning too.

Standard control

On a differential drive, Control.standard() is RAMSETE. The translation and rotation kP of the follower gains scale its feedback, and zero turns that axis’s feedback off. The defaults are listed under withPID with how they map to WPILib’s b and zeta. Live gains work the same way they do on swerve.

Converting the output

The velocity method, runVelocity in the config example, gets a WPILib ChassisSpeeds with vy = 0. This example converts it to left and right wheel speeds:

Java
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.kinematics.DifferentialDriveKinematics;

private final DifferentialDriveKinematics kinematics = new DifferentialDriveKinematics(0.6);

void runVelocity(ChassisSpeeds speeds) {
    var wheels = kinematics.toWheelSpeeds(speeds);
    setLeftVelocity(wheels.leftMetersPerSecond);
    setRightVelocity(wheels.rightMetersPerSecond);
}
Python
from wpimath.kinematics import ChassisSpeeds, DifferentialDriveKinematics

kinematics = DifferentialDriveKinematics(0.6)

def run_velocity(speeds: ChassisSpeeds):
    wheels = kinematics.toWheelSpeeds(speeds)
    set_left_velocity(wheels.left)
    set_right_velocity(wheels.right)
C++
#include <frc/kinematics/ChassisSpeeds.h>
#include <frc/kinematics/DifferentialDriveKinematics.h>
#include <units/length.h>

frc::DifferentialDriveKinematics kinematics{units::meter_t{0.6}};

void RunVelocity(const frc::ChassisSpeeds& speeds) {
    auto wheels = kinematics.ToWheelSpeeds(speeds);
    SetLeftVelocity(wheels.left);
    SetRightVelocity(wheels.right);
}

The two setters stand for your own closed-loop wheel-speed methods, in m/s. The measured speeds go the other way, through the same kinematics’ toChassisSpeeds(...).

Use the same track width in the kinematics and in TankConfigs. If they differ, the robot turns more or less than planned.

The samples use the 2026 WPILib types: edu.wpi.first.math.system.plant.DCMotor and edu.wpi.first.math.kinematics.ChassisSpeeds.

The samples use the RobotPy 2026 imports: wpimath.system.plant.DCMotor and wpimath.kinematics.ChassisSpeeds.

The samples use the 2026 WPILib type frc::ChassisSpeeds.

DCMotor moves to org.wpilib.math.system.DCMotor, and ChassisSpeeds is renamed to org.wpilib.math.kinematics.ChassisVelocities. toWheelSpeeds becomes toWheelVelocities, which returns a DifferentialDriveWheelVelocities with fields left and right, and toChassisSpeeds becomes toChassisVelocities. See 2026 vs 2027.

RobotPy 2027 imports both types from one module: from wpimath import DCMotor and from wpimath import ChassisVelocities (it replaces ChassisSpeeds). toWheelSpeeds becomes toWheelVelocities on alpha-6 and to_wheel_velocities on alpha-7 and beyond, where DCMotor.krakenX60FOC is DCMotor.kraken_x60_foc. See 2026 vs 2027.

On 2027, frc::ChassisSpeeds becomes wpi::math::ChassisVelocities, and ToWheelSpeeds and ToChassisSpeeds become ToWheelVelocities and ToChassisVelocities. See 2026 vs 2027.

Headings on a differential drive

A differential drive faces along its path and doesn’t turn in place during a route. A waypoint heading, from to(x, y, heading) or a pose target, throws unless the robot stops at that waypoint:

  • the last waypoint
  • a waypoint with Arrival.STOP or a pause
  • a leg that ends in arriveWith

Where the robot stops, a heading doesn’t throw, but the robot doesn’t turn to it and arrives facing along its path. At a waypoint the robot drives through, use to(x, y).

A rotationTarget(...), an aimTarget(...) or a start bias that doesn’t point along the start heading or straight back from it also throws, when the route freezes on its first use. Rotation Locks and Keys are ignored. The messages are listed under Rotation targeting errors and Bias.

If you want the robot to be traveling in a particular direction as it arrives, put a Bias on the last waypoint (Approach direction).

Driving backward

Each leg starts in the direction that needs the smaller turn. When the path leaves more than 90 degrees from the way the robot faces, the robot drives the whole leg backward. The direction is picked again for the next leg from the heading the robot has when it starts, and a leg that flows on from a backward leg keeps going backward.

A start bias straight back from the start heading backs the robot out of the start. On a leg the robot drives backward, a bias on the last waypoint sets the direction the robot is traveling as it backs in, and the robot arrives facing the opposite way.

Tempo plans a backward leg with the footprint turned around, so a robot extension on the front trails and one on the back leads.

Checking motion before tuning

Before tuning gains, check these:

  • A low forward command at several headings should drive both wheels forward and hold the heading. If it doesn’t, look for an inverted wheel, wrong units or a stray field-relative conversion.
  • A low positive turn command should turn the pose counterclockwise. If it doesn’t, check the left/right order, the gyro sign and the track width.
  • Canceling the auto should set both wheel outputs to zero. If it doesn’t, check the velocity method.

If it fails…

A differential-drive route throws when it freezes Above → [Tempo] leg 2: a differential drivetrain accepts a waypoint heading only where it stops, since it faces along its path while it moves; stop at that waypoint or remove the heading

A leg has a heading, rotation target or aim a differential drive can’t follow. Remove it, or set the arrival direction with a Bias on the last waypoint.

Building the config throws Above → Drive current budget cannot overcome calibrated drivetrain losses at 12 V

topSpeed is so far below the free speed that the losses use the whole current limit. This is usually a speed cap entered as topSpeed. Give topSpeed the measured wheel speed at 12 V and slow routes with withLimits(...).

Startup warns that the drive speed is above free speed Above → [Tempo] WARNING: left gearbox: the supplied 12 V drive speed {value} m/s is at or above the motor model's free speed ...

The derived acceleration is too high. Check the motor type, ratio and wheelRadius.

The robot turns more or less than planned Above →

The track width in the kinematics differs from the one in TankConfigs. Use the same value in both.

The robot drives in the wrong direction Above →

Check for an inverted wheel, the left/right order, the gyro sign and a stray field-relative conversion before tuning gains.

esc

Loading search...