Skip to content
learnFRC.org
programmingexample

Differential / Tank Drive Subsystem

Production differential drivetrain implementation with arcade drive, curvature drive, slew rate limiting, and odometry.

While swerve drivetrains dominate high-resource FRC competition, Differential Drive (also known as Tank or Skid-Steer Drive) remains reliable and mechanically forgiving. Teams frequently deploy it for rookie robots, dedicated defense machines, and low-cost preseason testbeds.

This production subsystem operates a 4-motor or 6-motor differential drivebase powered by CTRE Talon FX (Kraken X60 / Falcon 500) motors with heading integration via a Pigeon 2.0 IMU.


package frc.robot.subsystems;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.controls.Follower;
import com.ctre.phoenix6.controls.VoltageOut;
import com.ctre.phoenix6.hardware.Pigeon2;
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix6.signals.InvertedValue;
import com.ctre.phoenix6.signals.NeutralModeValue;
import edu.wpi.first.math.filter.SlewRateLimiter;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.kinematics.DifferentialDriveKinematics;
import edu.wpi.first.math.kinematics.DifferentialDriveOdometry;
import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds;
import edu.wpi.first.units.measure.Distance;
import edu.wpi.first.units.measure.LinearVelocity;
import edu.wpi.first.units.measure.Voltage;
import static edu.wpi.first.units.Units.*;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.smartdashboard.Field2d;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import java.util.function.DoubleSupplier;
public class DifferentialDriveSubsystem extends SubsystemBase {
// Hardware: Leader and Follower Talon FXs for each side
private final TalonFX m_leftLeader = new TalonFX(1, "rio");
private final TalonFX m_leftFollower = new TalonFX(2, "rio");
private final TalonFX m_rightLeader = new TalonFX(3, "rio");
private final TalonFX m_rightFollower = new TalonFX(4, "rio");
private final Pigeon2 m_pigeon2 = new Pigeon2(10, "rio");
// Kinematics & Physical Geometry
// Trackwidth: distance between left and right wheel contact centerlines (e.g. 0.65m)
private static final double TRACKWIDTH_METERS = 0.65;
private static final double WHEEL_RADIUS_METERS = 0.0762; // 6 inch wheel = 3 inch radius
private static final double GEAR_RATIO = 8.45; // 8.45:1 Toughbox Mini reduction
private static final double METERS_PER_MOTOR_ROTATION = (2.0 * Math.PI * WHEEL_RADIUS_METERS) / GEAR_RATIO;
private final DifferentialDriveKinematics m_kinematics = new DifferentialDriveKinematics(TRACKWIDTH_METERS);
private final DifferentialDriveOdometry m_odometry;
private final Field2d m_field = new Field2d();
// Slew rate limiters: rate-limit acceleration to prevent tipping and wheel spin
private final SlewRateLimiter m_speedLimiter = new SlewRateLimiter(3.0); // 3 units/sec max accel
private final SlewRateLimiter m_rotLimiter = new SlewRateLimiter(4.0);
// Control requests
private final VoltageOut m_leftVoltage = new VoltageOut(0);
private final VoltageOut m_rightVoltage = new VoltageOut(0);
public DifferentialDriveSubsystem() {
configureHardware();
m_odometry = new DifferentialDriveOdometry(
m_pigeon2.getRotation2d(),
getLeftDistanceMeters(),
getRightDistanceMeters(),
new Pose2d()
);
SmartDashboard.putData("Field", m_field);
}
private void configureHardware() {
TalonFXConfiguration driveConfig = new TalonFXConfiguration();
// 1. Inversions: Left side standard, Right side inverted
driveConfig.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive;
driveConfig.MotorOutput.NeutralMode = NeutralModeValue.Brake;
// 2. Active Current Limits (protect motors and avoid brownout on sudden reversals)
driveConfig.CurrentLimits.StatorCurrentLimitEnable = true;
driveConfig.CurrentLimits.StatorCurrentLimit = 60.0; // 60A stator limit per motor
driveConfig.CurrentLimits.SupplyCurrentLimitEnable = true;
driveConfig.CurrentLimits.SupplyCurrentLimit = 40.0; // 40A supply breaker limit
// Apply configuration to left leader
m_leftLeader.getConfigurator().apply(driveConfig);
// Invert right leader so positive voltage moves robot forward
driveConfig.MotorOutput.Inverted = InvertedValue.Clockwise_Positive;
m_rightLeader.getConfigurator().apply(driveConfig);
// 3. Set Followers (follower mirrors leader voltage commands)
m_leftFollower.setControl(new Follower(m_leftLeader.getDeviceID(), false));
m_rightFollower.setControl(new Follower(m_rightLeader.getDeviceID(), false));
// Reset encoders
m_leftLeader.setPosition(0);
m_rightLeader.setPosition(0);
m_pigeon2.reset();
}
@Override
public void periodic() {
// Update odometry every 20ms
m_odometry.update(
m_pigeon2.getRotation2d(),
getLeftDistanceMeters(),
getRightDistanceMeters()
);
Pose2d pose = m_odometry.getPoseMeters();
m_field.setRobotPose(pose);
SmartDashboard.putNumber("Drive/PoseX_m", pose.getX());
SmartDashboard.putNumber("Drive/PoseY_m", pose.getY());
SmartDashboard.putNumber("Drive/Heading_deg", pose.getRotation().getDegrees());
SmartDashboard.putNumber("Drive/LeftSpeed_mps", getLeftVelocityMps());
SmartDashboard.putNumber("Drive/RightSpeed_mps", getRightVelocityMps());
}
public double getLeftDistanceMeters() {
return m_leftLeader.getPosition().getValueAsDouble() * METERS_PER_MOTOR_ROTATION;
}
public double getRightDistanceMeters() {
return m_rightLeader.getPosition().getValueAsDouble() * METERS_PER_MOTOR_ROTATION;
}
public double getLeftVelocityMps() {
return m_leftLeader.getVelocity().getValueAsDouble() * METERS_PER_MOTOR_ROTATION;
}
public double getRightVelocityMps() {
return m_rightLeader.getVelocity().getValueAsDouble() * METERS_PER_MOTOR_ROTATION;
}
/**
* Standard Arcade Drive command factory with rate limiting and deadbanding.
*/
public Command arcadeDriveCommand(DoubleSupplier speedSupplier, DoubleSupplier rotationSupplier) {
return run(() -> {
double rawSpeed = speedSupplier.getAsDouble();
double rawRot = rotationSupplier.getAsDouble();
// Deadband
double deadbandSpeed = Math.abs(rawSpeed) > 0.08 ? rawSpeed : 0.0;
double deadbandRot = Math.abs(rawRot) > 0.08 ? rawRot : 0.0;
// Slew rate limiting to protect gearbox from shock loads
double limitedSpeed = m_speedLimiter.calculate(deadbandSpeed);
double limitedRot = m_rotLimiter.calculate(deadbandRot);
// Calculate left and right wheel speeds (-1.0 to +1.0)
DifferentialDrive.WheelSpeeds speeds = DifferentialDrive.arcadeDriveIK(limitedSpeed, limitedRot, true);
// Command voltages (12V nominal)
m_leftLeader.setControl(m_leftVoltage.withOutput(speeds.left * 12.0));
m_rightLeader.setControl(m_rightVoltage.withOutput(speeds.right * 12.0));
}).withName("ArcadeDrive");
}
/**
* Curvature Drive ("Cheesy Drive") command:
* High-speed steering commands constant turning radius rather than yaw rate.
*/
public Command curvatureDriveCommand(
DoubleSupplier speedSupplier, DoubleSupplier rotationSupplier, DoubleSupplier quickTurnSupplier) {
return run(() -> {
double speed = Math.abs(speedSupplier.getAsDouble()) > 0.08 ? speedSupplier.getAsDouble() : 0.0;
double rot = Math.abs(rotationSupplier.getAsDouble()) > 0.08 ? rotationSupplier.getAsDouble() : 0.0;
boolean isQuickTurn = quickTurnSupplier.getAsDouble() > 0.5;
DifferentialDrive.WheelSpeeds speeds = DifferentialDrive.curvatureDriveIK(
m_speedLimiter.calculate(speed),
m_rotLimiter.calculate(rot),
isQuickTurn
);
m_leftLeader.setControl(m_leftVoltage.withOutput(speeds.left * 12.0));
m_rightLeader.setControl(m_rightVoltage.withOutput(speeds.right * 12.0));
}).withName("CurvatureDrive");
}
/**
* Stop drivetrain command.
*/
public Command stopCommand() {
return runOnce(() -> {
m_leftLeader.setControl(m_leftVoltage.withOutput(0));
m_rightLeader.setControl(m_rightVoltage.withOutput(0));
}).withName("StopDrive");
}
}

Without slew rate limiters, slamming the joystick from full forward (+1.0) to full reverse (-1.0) draws over 200 Amps total from the battery, causing instantaneous roboRIO brownouts and severe gearbox backlash. Notice the SlewRateLimiter smoothly ramps the commanded acceleration over 330 ms.

  • Arcade Drive: At high speeds, tapping the turn stick can cause the robot to violently spin out.
  • Curvature Drive (“Cheesy Drive”): Scales turn sensitivity to forward speed for predictable high-speed arcs, while switching to a dedicated quick-turn mode for stationary spins.
Brake Mode on Tank Drivetrains

Always configure NeutralModeValue.Brake on differential drive motors. In coast mode, a full-weight competition tank robot (up to 135 lb per Rule R408) will coast 6 to 10 feet before friction stops it, making precise autonomous alignment nearly impossible.