Currently the Swerve API doesn't have an easy way to set additional configs to the steer/drive motors or CANcoders.
This will be addressed in a future update, but in the meantime adding this snippet inside CommandSwerveDrivetrain.java's constructor is sufficient as a workaround:
/* Do this for every module */
for(int i = 0; i < 4; ++i) {
var swerveModule = this.getModule(i);
var steerMotor = swerveModule.getSteerMotor(); // Get the steer motor in this instance
var steerMotorConfig = new TalonFXConfiguration();
StatusCode status = StatusCode.StatusCodeNotInitialized;
int maxRetries = 10;
do {
status = steerMotor.getConfigurator().refresh(steerMotorConfig);
} while (!status.isOK() && maxRetries-- > 0);
if(!status.isOK()) {
System.out.println("Could not retrieve configs: " + status.toString());
continue; // Move to next module, don't modify configs
}
/* Set a stator current limit on the steer motors */
steerMotorConfig.CurrentLimits.StatorCurrentLimit = 50;
steerMotorConfig.CurrentLimits.StatorCurrentLimitEnable = true;
steerMotorConfig.TorqueCurrent.PeakForwardTorqueCurrent = 50;
steerMotorConfig.TorqueCurrent.PeakReverseTorqueCurrent = -50;
status = StatusCode.StatusCodeNotInitialized;
maxRetries = 10;
do{
status = steerMotor.getConfigurator().apply(steerMotorConfig);
} while (!status.isOK() && maxRetries-- > 0);
if (!status.isOK()) {
System.out.println("Could not apply configs: " + status.toString());
}
}
Currently the Swerve API doesn't have an easy way to set additional configs to the steer/drive motors or CANcoders. This will be addressed in a future update, but in the meantime adding this snippet inside
CommandSwerveDrivetrain.java
's constructor is sufficient as a workaround: