Next hurdle. I have Characterized my SDS MK4 chassis byt locking the wheels and using the sysid tool.
I have code based on the SDS Swerve template. I have added some code to make the drivetrain consume SwerveModuleState][] so it will be useable by the SwerveControllerCommand which produces such an array.
So if I set my gains as indicated in the tool
public static final class TranslationGains {
public static final double kP = 2.2956;
public static final double kI = 0;
public static final double kD = 0;
public static final double kA = 0.12872;
public static final double kV = 2.3014;
public static final double kS = 0.55493;
}
Create a SimpleMotorFeedForward
private SimpleMotorFeedforward m_feedForward = new SimpleMotorFeedforward(TranslationGains.kS, TranslationGains.kV, TranslationGains.kA);
To apply the feed forward to my code
private void updateDriveStates(SwerveModuleState[] desiredStates) {
if (desiredStates != null){
SwerveModuleState frontLeftState = desiredStates[FrontLeftSwerveConstants.STATES_INDEX];
SwerveModuleState frontRightState = desiredStates[FrontRightSwerveConstants.STATES_INDEX];
SwerveModuleState backLeftState = desiredStates[BackLeftSwerveConstants.STATES_INDEX];
SwerveModuleState backRightState = desiredStates[BackRightSwerveConstants.STATES_INDEX];
SwerveDriveKinematics.normalizeWheelSpeeds(desiredStates, DrivetrainGeometry.MAX_VELOCITY_METERS_PER_SECOND);
m_frontLeftModule.set(velocityToDriveVolts(frontLeftState.speedMetersPerSecond),
frontLeftState.angle.getRadians());
m_frontRightModule.set(velocityToDriveVolts(frontRightState.speedMetersPerSecond),
frontRightState.angle.getRadians());
m_backLeftModule.set(velocityToDriveVolts(backLeftState.speedMetersPerSecond),
backLeftState.angle.getRadians());
m_backRightModule.set(velocityToDriveVolts(backRightState.speedMetersPerSecond),
backRightState.angle.getRadians());
}
}
private double velocityToDriveVolts(double speedMetersPerSecond){
return speedMetersPerSecond / DrivetrainGeometry.MAX_VELOCITY_METERS_PER_SECOND * MAX_VOLTAGE;
}
Do I just apply the m_feedForward.calculate to the speedMetersPerSecond in the velocityToDriveVolts or do I pass in the calculated volts first? Or am I completely off track?