Gray Matter LogoGray Matter Workshop

Swerve Calibration

KEY CONCEPT

Swerve Calibration

Accurate autonomous starts with calibration: tuning swerve motor gains, configuring drive request types, preventing wheel slip, finding effective wheel radius, configuring camera positions, and tuning PID controllers for path following.

↳ TAKEAWAY

Calibration transforms theoretical parameters into real-world accuracy.

Calibration is how your robot knows where it is on the field, which is what autonomous movement and vision integration depend on. Here is the order we follow when setting up a robot.

Before the Season

Can be done now with any robot

1
Drive/Steer Motor Tuning
2
Wheel Radius Calibration
3
Drivetrain Odometry
4
Camera Calibration
5
AprilTag Tuning
6
Robot Localization Fusion
7
Drive to Point
Season Kickoff

After the Season Begins

Requires game-specific knowledge

Autonomous Programming

Field layout dependent

Mechanism Programming

Game piece dependent

Motor Calibration & Tuning

Work through these steps in order; each builds on the one before it.

1

Tune steerGains (TunerConstants.java)

First, make sure the hardware itself is ready. Follow the Official CTRE Swerve Setup Guide for the initial configuration using Phoenix Tuner X.

Then tune the steering motors' PID gains so each module tracks its commanded angle.

Tuning Procedure:

A steering motor is a rotational mechanism, like a turret, so it needs position-based PID tuning. Use the Turret tuning instructions from the PID Control page to tune your steer gains.

Reference: Turret PID Tuning

The Turret section on the PID Control page has worked examples if you get stuck.

2

Tune driveGains (TunerConstants.java)

Tune velocity PID gains for your drive motors so they hold commanded speeds.

Two-Phase Tuning Approach:

Phase 1: Initial Tuning (Wheels Off Ground)

Use the Flywheel tuning instructions from the PID Control page. Start with the robot's wheels off the ground to tune velocity control without friction interference.

  • Set up velocity control using VelocityVoltage control request
  • Tune kP, kI, and kD values to achieve smooth velocity tracking
  • Configure feedforward gains (kV for velocity, kS for static friction)
Phase 2: Fine-Tuning kP (On the Ground)

Once basic velocity control works, place the robot on the ground and fine-tune kP to account for real-world friction and load:

  • Test velocity tracking while driving on carpet/competition surface
  • Adjust kP if you observe steady-state velocity errors
  • Verify smooth acceleration and deceleration without oscillation

Reference: Flywheel PID Tuning

The Flywheel section on the PID Control page has worked examples of velocity-based PID tuning with VelocityVoltage control requests.

3

Update DriveRequestType (Teleop OpMode)

Configure the drive system to use velocity-based control for more precise speed tracking.

Configuration Changes (already done if you used our example code on the last page):

  1. 1. Change drive request type: Modify .withDriveRequestType() to use DriveRequestType.Velocity
  2. 2. Remove deadband: Drop the CTRE deadband. It zeroes out small input values, which gets in the way of precise low-speed control.

Example code change:

// Before
.withDriveRequestType(DriveRequestType.OpenLoopVoltage)
.withDeadband(MaxSpeed * 0.1)

// After
.withDriveRequestType(DriveRequestType.Velocity)
// Deadband removed for precise control
4

Find kSlipCurrent (TunerConstants.java)

Determine the stator current limit that prevents wheel slip while maximizing traction and power transfer.

How Stator Current Limits Prevent Wheel Slip:

Stator current is the output current of the motor and is directly proportional to torque. By restricting stator current, you cap the torque output, which prevents wheels from spinning faster than the friction between tire and floor can support. This maximizes traction and power transfer to the ground.

Step-by-Step Procedure:

  1. 1
    Position the robot: Place your robot up against a wall on carpet (to simulate match conditions)
  2. 2
    Open Phoenix Tuner X: Begin plotting both velocity and stator current in real-time
  3. 3
    Gradually increase voltage: Slowly increase voltage output until velocity becomes non-zero (wheels start slipping) and stator current drops noticeably
  4. 4
    Record the slip threshold: The stator current value where wheels begin slipping (velocity spikes) represents your threshold
  5. 5
    Set the limit: Configure your stator current limit to a value slightly below this observed value for a safety margin

Important Considerations

Stator limits also cap acceleration, so setting them too low makes the robot sluggish. Stay slightly below the observed slip point for a safety margin, but no lower than you need.

CTRE: Preventing Wheel Slip Documentation
5

Tune kWheelRadius (TunerConstants.java)

Find the effective wheel radius by comparing actual distance traveled vs. what the robot reports.

Quick Calibration Procedure:

  1. 1. Drive slowly forward: Command the robot to drive straight at low speed (to minimize slip)
  2. 2. Measure actual distance: Use a tape measure to record how far the robot actually moved
  3. 3. Read reported distance: Check the distance the robot thinks it traveled from odometry
  4. 4. Calculate new radius: Use the formula: kWheelRadius = (actualDistance / reportedDistance) * currentRadius
6

Find kSpeedAt12Volts (TunerConstants.java)

Measure your robot's maximum velocity to configure accurate feedforward gains.

Measurement Procedure:

  1. 1. Drive at maximum speed: Command the robot to drive straight at full throttle
  2. 2. Record peak velocity: Log the maximum velocity achieved from odometry (in meters/second)
  3. 3. Update TunerConstants: Set kSpeedAt12Volts to this measured value

Testing Conditions

  • Preferred: Test on the ground (carpet or competition surface) for most accurate results
  • Alternative: Testing in the air (wheels off ground) is acceptable for initial testing, but may yield slightly different results
  • Use the on-ground measurement for final competition

Zeroing Procedure

If your modules aren't zeroed well, the robot won't drive straight. Press a straight edge (a long piece of metal or a 2x4) against the wheel modules to physically align them before saving the zero positions in Tuner X.

Encoder Security

Glue your drive encoders in place so they can't shift during impacts or aggressive movements. Even a small encoder shift causes significant odometry drift.

CHECKPOINT · 4 ITEMS

What's Next?

Up Next: Logging Options

Next up is data logging: comparing frameworks, deciding what to log, and using logs for debugging and performance analysis.