Skip to content

Commit

Permalink
Characterization fix (#54)
Browse files Browse the repository at this point in the history
* fix #53; don't use drive method or driveMode
* update constants after characterization
* update ramp rate based on length of carpet
  • Loading branch information
gcschmit authored Oct 7, 2023
1 parent e342de8 commit b07d9e1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 38 deletions.
3 changes: 1 addition & 2 deletions src/main/java/frc/lib/team3061/RobotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ public double getSwerveAngleKD() {
return 0.0;
}


/*
* Returns the voltage needed to overcome the swerve module's static friction. Defaults to 0.
*
*
* @return the voltage needed to overcome the swerve module's static friction
*/
public double getSwerveAngleKS() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@java.lang.SuppressWarnings({"java:S106", "java:S107"})
public class FeedForwardCharacterization extends CommandBase {
private static final double START_DELAY_SECS = 2.0;
private static final double RAMP_RATE_VOLTS_PER_SECOND = 1.75;
private static final double RAMP_RATE_VOLTS_PER_SECOND = 2.0;

private final boolean forwards;
private final boolean isDrive;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/frc/robot/configs/NovaRobotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ public class NovaRobotConfig extends RobotConfig {
private static final double ANGLE_KI = 0.0;
private static final double ANGLE_KD = 0.0;

private static final double ANGLE_KS = 0.17853;
private static final double ANGLE_KV = 0.43784;
private static final double ANGLE_KA = 0.0;
private static final double ANGLE_KS = 0.1891233333;
private static final double ANGLE_KV = 0.4399866667;
private static final double ANGLE_KA = 0.001663333333;

/* Drive Motor PID Values */
private static final double DRIVE_KP = 0.2402346041055719;
private static final double DRIVE_KI = 0.0;
private static final double DRIVE_KD = 0.013212903225806451;

private static final double DRIVE_KS = 0.37182;
private static final double DRIVE_KV = 2.72624;
private static final double DRIVE_KA = 0.0;
private static final double DRIVE_KS = 0.4004375;
private static final double DRIVE_KV = 2.7637325;
private static final double DRIVE_KA = 0.0139575;

private static final SwerveType SWERVE_TYPE = SwerveType.MK4I;

Expand Down
36 changes: 7 additions & 29 deletions src/main/java/frc/robot/subsystems/drivetrain/Drivetrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public class Drivetrain extends SubsystemBase {
private static final double BREAK_MODE_DELAY_SEC = 10.0;

private DriveMode driveMode = DriveMode.NORMAL;
private double characterizationVoltage = 0.0;

private boolean isTurbo;

Expand Down Expand Up @@ -449,21 +448,6 @@ public void drive(
setSwerveModuleStates(newSwerveModuleStates, isOpenLoop, false);
break;

case SWERVE_DRIVE_CHARACTERIZATION:
// In this characterization mode, drive at the specified voltage (and turn to zero degrees)
for (SwerveModule swerveModule : swerveModules) {
swerveModule.setVoltageForDriveCharacterization(characterizationVoltage);
}
break;

case SWERVE_ROTATE_CHARACTERIZATION:
// In this characterization mode, rotate the swerve modules at the specified voltage (and
// don't drive)
for (SwerveModule swerveModule : swerveModules) {
swerveModule.setVoltageForRotateCharacterization(characterizationVoltage);
}
break;

case X:
this.setXStance();
break;
Expand Down Expand Up @@ -762,11 +746,9 @@ public PIDController getAutoThetaController() {
* @param volts the commanded voltage
*/
public void runDriveCharacterizationVolts(double volts) {
driveMode = DriveMode.SWERVE_DRIVE_CHARACTERIZATION;
characterizationVoltage = volts;

// invoke drive which will set the characterization voltage to each module
drive(0, 0, 0, true, false);
for (SwerveModule swerveModule : swerveModules) {
swerveModule.setVoltageForDriveCharacterization(volts);
}
}

/**
Expand Down Expand Up @@ -799,11 +781,9 @@ public double getDriveCharacterizationAcceleration() {
* @param volts the commanded voltage
*/
public void runRotateCharacterizationVolts(double volts) {
driveMode = DriveMode.SWERVE_ROTATE_CHARACTERIZATION;
characterizationVoltage = volts;

// invoke drive which will set the characterization voltage to each module
drive(0, 0, 0, true, false);
for (SwerveModule swerveModule : swerveModules) {
swerveModule.setVoltageForRotateCharacterization(volts);
}
}

/**
Expand Down Expand Up @@ -919,8 +899,6 @@ private static ChassisSpeeds convertFromDiscreteChassisSpeedsToContinuous(

private enum DriveMode {
NORMAL,
X,
SWERVE_DRIVE_CHARACTERIZATION,
SWERVE_ROTATE_CHARACTERIZATION
X
}
}

0 comments on commit b07d9e1

Please sign in to comment.