TalonFX Swerve Tuning
Here, you will find many tutorials on how to tune aspects of the swerve template.
Feedforward Characterization
The project includes default feedforward gains. Provided are three SysID tests. You will change m_sysIdRoutineToApply inside of Drive.java to change the type of test.
Translation and Steer are needed. A Rotation test is also needed to find MOI.
Running FeedForward Test
Place the robot in an open space.
Connect robot and controller to driver station.
Enable the robot.
Hold down
select, and holdyfor 4 seconds or longer.Hold down
select, and holdxfor 4 seconds or longer.Hold down
start, and holdyfor 4 seconds or longer.Hold down
start, and holdxfor 4 seconds or longer.Disable the robot.
Saving The Test
Go to
File>Download Logs...Select the log that is most recent.
Go to
File>Export Data...Set the format to
WPILOGand the timestamps toAdvantageKit Cycles. For large log files, enter the prefixes for only the fields and tables necessary for SysId analysis (see the export options: documentation for details).Click the save icon and choose a location to save the log.
Running SysID
Open SysID in the "2025 WPILib Tools" folder on your desktop.
Open your log
Drag
RealOutputs/SysIdRotation_Stateto the Data SelectorDrag
Module0/DrivePosition,Module0/DriveVelocity,Module0/DriveAppliedVoltsto their respective locationsChange the Mechanism type to Simple
Change the Units to Radians
Load
Values to Use
For Drive FeedForward - Use
kV- LogkAfor MOIFor Steer FeedForward - Use
kSandkVFor Rotation FeedForward - Log
kA
We have found that these FeedForward values are accurate, but the PID is not always.
Drive/Turn PID Tuning
The project includes default gain, which can be found in the steerGains and driveGains configs in TunerConstants.java. These gains should be tuned for each robot.
PID Tuning Tips
For Drive PID - Only use
kPFor Steer PID - Use
kPandkD
TorqueCurrent Control
Congrats! You should have a fully tuned robot. For Phoenix Pro you can also attempt to use TorqueCurrent control, as described in the Phoenix documentation. You can configure by changing the values of kSteerClosedLoopOutput and/or kDriveClosedLoopOutput in TunerConstants.java to ClosedLoopOutputType.TorqueCurrentFOC.
Wheel Radius Characterization
The effective wheel radius of a robot tends to change over time as wheels are worn down, swapped, or compressed into the carpet. Having the wrong wheel size can have significant impacts on odometry accuracy. We recommend regularly recharacterizing wheel radius to combat these issues.
The project includes an automated wheel radius characterization routine, which only requires enough space for the robot to rotate in place.
Place the robot on the carpet. Characterizing on a hard floor may produce errors in the measurement, as the robot's effective wheel radius is affected by carpet compression.
Select the "Drive Wheel Radius Characterization" auto routine.
Enable the robot in autonomous mode. The robot will slowly rotate in place.
Disable the robot after at least one full rotation.
Check the console output for the measured wheel radius, and copy the value to
kWheelRadiusinTunerConstants.java.
Max Speed Measurement
The effective maximum speed of a robot is typically slightly less than the theoretical max speed based on motor free speed and gearing. To ensure that the robot remains controllable at high speeds, we recommend measuring the effective maximum speed of the robot.
Set
kSpeedAt12VoltsinTunerConstants.javato the theoretical max speed of the robot based on motor free speed and gearing. This value can typically be found on the product page for your chosen swerve modules.Place the robot in an open space.
Plot the measured robot speed in AdvantageScope using the
/RealOutputs/SwerveChassisSpeeds/Measuredfield.In teleop mode, drive forwards at full speed until the robot velocity is no longer increasing.
Record the maximum velocity achieved and update the value of
kSpeedAt12Volts.
Slip Current Measurement
The value of kSlipCurrent can be tuned to avoid slipping the wheels.
Place the robot against a solid wall.
Using AdvantageScope, plot the current of a drive motor from the
/Drive/Module.../DriveCurrentAmpskey, and the velocity of the motor from the/Drive/Module.../DriveVelocityRadPerSeckey.Accelerate forwards until the drive velocity increases (the wheel slips). Note the current at this time.
Update the value of
kSlipCurrentto this value.
PathPlanner Configuration
The project includes a built-in robot configuration for PathPlanner, located in the constructor of Drive.java. You will want to update all values:
Robot mass, MOI, and wheel coefficient as configured in
Constants.javaDrive PID constants as configured in
AutoBuilderTurn PID constants as configured in
AutoBuilder
Swerve Setpoint Generator
This project include skid and slip prevention using PathPlanners Swerve Setpoint Generator
Once you set the PathPlanner Configurations, you can test this drive mode by pressing X button. Once you feel comfortable, replacing the default drive with this is recommended.