Swerve Calibration
Swerve Calibration
Proper calibration is the foundation of accurate autonomous performance. This includes 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.
Key Concept: Calibration transforms theoretical parameters into real-world accuracy.
Accurate calibration ensures your robot knows exactly where it is on the field, enabling precise autonomous movement and vision integration. Below is a graphic showing the order we follow when setting up a robot.
Before the Season
Can be done now with any robot
After the Season Begins
Requires game-specific knowledge
Field layout dependent
Game piece dependent
Motor Calibration & Tuning
Follow these steps in order to properly tune your swerve drive motors and configure optimal drive performance. Each step builds on the previous one to ensure accurate odometry and reliable autonomous operation.
Tune steerGains (TunerConstants.java)
Before diving into code, ensure your hardware is ready. We strongly recommend following the Official CTRE Swerve Setup Guide for the initial configuration using Phoenix Tuner X.
Configure PID gains for your swerve module steering motors to ensure accurate module angle control.
Tuning Procedure:
Use the Turret tuning instructions from the PID Control page to tune your steer gains. The steering motors behave like a rotational mechanism (similar to a turret) and require position-based PID tuning.
Reference: Turret PID Tuning
The Turret section on the PID Control page provides detailed examples of position-based PID tuning.
Tune driveGains (TunerConstants.java)
Configure velocity PID gains for your drive motors to ensure accurate speed control.
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 provides detailed examples of velocity-based PID tuning with VelocityVoltage control requests.
Update DriveRequestType (RobotContainer.java)
Configure the drive system to use velocity-based control for more precise speed tracking.
Configuration Changes (done if using our example code on last page):
- 1. Change drive request type: Modify
.withDriveRequestType()to useDriveRequestType.Velocity - 2. Remove deadband: Remove CTR deadband. The current implementation they have elements small input values, which hinders precise low-speed control.
Example code change:
// Before .withDriveRequestType(DriveRequestType.OpenLoopVoltage) .withDeadband(MaxSpeed * 0.1) // After .withDriveRequestType(DriveRequestType.Velocity) // Deadband removed for precise control
Find kSlipCurrent (RobotContainer.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:
- 1Position the robot: Place your robot up against a wall on carpet (to simulate match conditions)
- 2Open Phoenix Tuner X: Begin plotting both velocity and stator current in real-time
- 3Gradually increase voltage: Slowly increase voltage output until velocity becomes non-zero (wheels start slipping) and stator current drops noticeably
- 4Record the slip threshold: The stator current value where wheels begin slipping (velocity spikes) represents your threshold
- 5Set the limit: Configure your stator current limit to a value slightly below this observed value for a safety margin
Important Considerations
- Testing environment matters: Always test on carpet against a wall to accurately simulate match conditions
- Conservative tuning: Set limits below the slip point to maintain a safety margin
- Performance tradeoff: Stator limits restrict acceleration. Setting limits too low degrades responsiveness
- Monitor during testing: Watch for the characteristic velocity spike that indicates slip occurrence
Tune kWheelRadius (TunerConstants.java)
Find the effective wheel radius by comparing actual distance traveled vs. what the robot reports.
Quick Calibration Procedure:
- 1. Drive slowly forward: Command the robot to drive straight at low speed (to minimize slip)
- 2. Measure actual distance: Use a tape measure to record how far the robot actually moved
- 3. Read reported distance: Check the distance the robot thinks it traveled from odometry
- 4. Calculate new radius: Use the formula:
kWheelRadius = (actualDistance / reportedDistance) * currentRadius
Find kSpeedAt12Volts (TunerConstants.java)
Measure your robot's maximum velocity to configure accurate feedforward gains.
Measurement Procedure:
- 1. Drive at maximum speed: Command the robot to drive straight at full throttle
- 2. Record peak velocity: Log the maximum velocity achieved from odometry (in meters/second)
- 3. Update TunerConstants: Set
kSpeedAt12Voltsto 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
Zeroing your modules is critical for straight driving. We recommend using a straight edge (like a long piece of metal or 2x4) pressed against the wheel modules to physically align them perfectly straight before saving the zero positions in Tuner X.
Encoder Security
Highly Recommended: Glue your drive encoders in place to prevent them from shifting during impacts or aggressive movements. Even small encoder shifts can cause significant odometry drift.
What's Next?
Up Next: Logging Options
With your swerve drive fully calibrated, you're ready to explore data logging strategies. You'll learn about different logging frameworks, what data to log, and how to use logs for debugging and performance analysis.