Skip to content

Commit

Permalink
Update swerve PathPlanner example to use latest swerve generator
Browse files Browse the repository at this point in the history
  • Loading branch information
bhall-ctre authored Nov 22, 2023
1 parent c75d7f9 commit c13eeff
Showing 1 changed file with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,49 @@

public class TunerConstants {
static class CustomSlotGains extends Slot0Configs {
public CustomSlotGains(double kP, double kI, double kD, double kV, double kS) {
public CustomSlotGains(double kP, double kI, double kD, double kS, double kV, double kA) {
this.kP = kP;
this.kI = kI;
this.kD = kD;
this.kV = kV;
this.kS = kS;
this.kV = kV;
this.kA = kA;
}
}

private static final CustomSlotGains steerGains = new CustomSlotGains(100, 0, 0.05, 0, 0);
private static final CustomSlotGains driveGains = new CustomSlotGains(3, 0, 0, 0, 0);
// Both sets of gains need to be tuned to your individual robot
// The steer motor uses MotionMagicVoltage control
private static final CustomSlotGains steerGains = new CustomSlotGains(100, 0, 0.05, 0, 0, 0);
// When using closed-loop control, the drive motor uses:
// - VelocityVoltage, if DrivetrainConstants.SupportsPro is false (default)
// - VelocityTorqueCurrentFOC, if DrivetrainConstants.SupportsPro is true
private static final CustomSlotGains driveGains = new CustomSlotGains(3, 0, 0, 0, 0, 0);

// The stator current at which the wheels start to slip;
// This needs to be tuned to your individual robot
private static final double kSlipCurrentA = 300.0;

// Theoretical free speed (m/s) at 12v applied output;
// This needs to be tuned to your individual robot
private static final double kSpeedAt12VoltsMps = 6.0;

// Every 1 rotation of the azimuth results in kCoupleRatio drive motor turns;
// This may need to be tuned to your individual robot
private static final double kCoupleRatio = 3.5;

private static final double kDriveGearRatio = 7.363636364;
private static final double kSteerGearRatio = 15.42857143;
private static final double kWheelRadiusInches = 2.167; // Estimated at first, then fudge-factored to make odom match record
private static final int kPigeonId = 1;

private static final boolean kSteerMotorReversed = true;
private static final String kCANbusName = "rio";
private static final boolean kInvertLeftSide = false;
private static final boolean kInvertRightSide = true;

private static final String kCANbusName = "rio";
private static final int kPigeonId = 1;


// These are only used for simulation
private static double kSteerInertia = 0.00001;
private static double kDriveInertia = 0.001;

Expand All @@ -47,37 +66,45 @@ public CustomSlotGains(double kP, double kI, double kD, double kV, double kS) {
.withDriveMotorGearRatio(kDriveGearRatio)
.withSteerMotorGearRatio(kSteerGearRatio)
.withWheelRadius(kWheelRadiusInches)
.withSlipCurrent(30)
.withSlipCurrent(kSlipCurrentA)
.withSteerMotorGains(steerGains)
.withDriveMotorGains(driveGains)
.withSpeedAt12VoltsMps(6) // Theoretical free speed is 10 meters per second at 12v applied output
.withSpeedAt12VoltsMps(kSpeedAt12VoltsMps)
.withSteerInertia(kSteerInertia)
.withDriveInertia(kDriveInertia)
.withFeedbackSource(SwerveModuleSteerFeedbackType.FusedCANcoder)
.withCouplingGearRatio(kCoupleRatio) // Every 1 rotation of the azimuth results in couple ratio drive turns
.withCouplingGearRatio(kCoupleRatio)
.withSteerMotorInverted(kSteerMotorReversed);


// Front Left
private static final int kFrontLeftDriveMotorId = 5;
private static final int kFrontLeftSteerMotorId = 4;
private static final int kFrontLeftEncoderId = 2;
private static final double kFrontLeftEncoderOffset = -0.83544921875;

private static final double kFrontLeftXPosInches = 10.5;
private static final double kFrontLeftYPosInches = 10.5;

// Front Right
private static final int kFrontRightDriveMotorId = 7;
private static final int kFrontRightSteerMotorId = 6;
private static final int kFrontRightEncoderId = 3;
private static final double kFrontRightEncoderOffset = -0.15234375;

private static final double kFrontRightXPosInches = 10.5;
private static final double kFrontRightYPosInches = -10.5;

// Back Left
private static final int kBackLeftDriveMotorId = 1;
private static final int kBackLeftSteerMotorId = 0;
private static final int kBackLeftEncoderId = 0;
private static final double kBackLeftEncoderOffset = -0.4794921875;

private static final double kBackLeftXPosInches = -10.5;
private static final double kBackLeftYPosInches = 10.5;

// Back Right
private static final int kBackRightDriveMotorId = 3;
private static final int kBackRightSteerMotorId = 2;
private static final int kBackRightEncoderId = 1;
Expand Down

0 comments on commit c13eeff

Please sign in to comment.