Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Merge branch 'drive-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
carokhan committed Oct 16, 2024
2 parents 223c47c + cd5533e commit c0b5501
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
14 changes: 7 additions & 7 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public final class Constants {
public static final double loopPeriodSecs = 0.02;

public static final Mode currentMode = Mode.SIM;
public static final Mode currentMode = Mode.REAL;

public static enum Mode {
/** Running on a real robot. */
Expand All @@ -57,8 +57,8 @@ public static class Drive {
public static final int backRightDrive = 7;
public static final int backRightTurn = 8;

public static final boolean frontLeftDriveInvert = true;
public static final boolean frontRightDriveInvert = false;
public static final boolean frontLeftDriveInvert = false;
public static final boolean frontRightDriveInvert = true;
public static final boolean backLeftDriveInvert = false; // true?
public static final boolean backRightDriveInvert = true; // false?

Expand All @@ -72,7 +72,7 @@ public static class Drive {
public static final int backLeftEncoder = 1;
public static final int backRightEncoder = 0;

public static final double frontLeftOffset = -0.5107599496841431;
public static final double frontLeftOffset = 0.807;
public static final double frontRightOffset = -0.5107599496841431;
public static final double backLeftOffset = 1.8345500230789185;
public static final double backRightOffset = 2.437732458114624;
Expand Down Expand Up @@ -126,8 +126,8 @@ public static class DriveConstants {
public static final double odometeryFrequency = 250;
public static final double updateFrequency = 100;

// public static final double maxLinearVelocity = Units.feetToMeters(20.4);
public static final double maxLinearVelocity = Units.feetToMeters(1.4);
public static final double maxLinearVelocity = Units.feetToMeters(20.4);
// public static final double maxLinearVelocity = Units.feetToMeters(1.4);
public static final double maxLinearAccel = 8.0;

public static final double maxAngularVelocity = 10;
Expand All @@ -139,7 +139,7 @@ public static class DriveConstants {
public static double kVDriveReal = 1.93;
public static double kADriveReal = 0.25;

public static double kPTurnReal = 1.5; // 1.5?
public static double kPTurnReal = 3; // 1.5?
public static double kDTurnReal = 0.0;

public static double kPDriveSim = 0.3;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ private void configureButtonBindings() {
// right trigger -> climb up
m_driver.rightTrigger(0.1).onTrue(m_climber.setDutyCycle(1)).onFalse(m_climber.setDutyCycle(0));

m_driver.y().whileTrue(m_drive.zeroGyro());

// Operator Controller

// D-Pad Up for intake down, rollers forward, until note in feeder beambreak
Expand Down Expand Up @@ -251,7 +253,7 @@ private void configureButtonBindings() {
.a()
.whileTrue(
Commands.parallel(
m_pivot.setPivotTarget(() -> Units.degreesToRadians(34)),
m_pivot.setPivotTarget(() -> Units.degreesToRadians(40)),
m_shooter.setRPM(() -> -1500, 1.0),
m_feeder.setRPM(() -> -1500),
m_intake.setRollerRPM(() -> -1000))
Expand Down Expand Up @@ -282,7 +284,7 @@ public void robotPeriodic() {
}

private static double teleopAxisAdjustment(double x) {
return MathUtil.applyDeadband(Math.abs(Math.pow(x, 2)) * Math.signum(x), 0.02);
return MathUtil.applyDeadband(x, 0.02);
}

public Command getAutonomousCommand() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/frc/robot/subsystems/drive/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ public Rotation2d getRotation() {
return gyroIO.getYaw();
}

public Command zeroGyro() {
return this.run(
() -> {
gyroIO.setYaw(0);
});
}

@AutoLogOutput(key = "Odometry/Robot")
public Pose2d getPose() {
return poseEstimator.getEstimatedPosition();
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/frc/robot/subsystems/drive/ModuleIOReal.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class ModuleIOReal implements ModuleIO {
private final StatusSignal<Double> driveVelocity;
private final StatusSignal<Double> driveAppliedVolts;
private final StatusSignal<Double> driveCurrent;
// private int multiplier;
private int multiplier;

private final VelocityVoltage driveCurrentVelocity =
new VelocityVoltage(0.0).withEnableFOC(false);
Expand All @@ -93,7 +93,7 @@ public ModuleIOReal(int index) {
absoluteEncoderOffset =
new Rotation2d(RobotMap.Drive.frontLeftOffset); // MUST BE CALIBRATED
name = "FrontLeft";
// multiplier = -1;
multiplier = 1;
break;
case 1:
driveTalon = new TalonFX(RobotMap.Drive.frontRightDrive);
Expand All @@ -104,7 +104,7 @@ public ModuleIOReal(int index) {
absoluteEncoderOffset =
new Rotation2d(RobotMap.Drive.frontRightOffset); // MUST BE CALIBRATED
name = "FrontRight";
// multiplier = 1;
multiplier = 1;
break;
case 2:
driveTalon = new TalonFX(RobotMap.Drive.backLeftDrive);
Expand All @@ -114,7 +114,7 @@ public ModuleIOReal(int index) {
absoluteEncoder = new AnalogEncoder(RobotMap.Drive.backLeftEncoder);
absoluteEncoderOffset = new Rotation2d(RobotMap.Drive.backLeftOffset); // MUST BE CALIBRATED
name = "BackLeft";
// multiplier = 1;
multiplier = 1;
break;
case 3:
driveTalon = new TalonFX(RobotMap.Drive.backRightDrive);
Expand All @@ -125,7 +125,7 @@ public ModuleIOReal(int index) {
absoluteEncoderOffset =
new Rotation2d(RobotMap.Drive.backRightOffset); // MUST BE CALIBRATED
name = "BackRight";
// multiplier = 1;
multiplier = 1;
break;
default:
throw new RuntimeException("Invalid module index");
Expand Down Expand Up @@ -163,10 +163,7 @@ public ModuleIOReal(int index) {

turnRelativeEncoder = turnSparkMax.getEncoder();

turnRelativeEncoder.setPositionConversionFactor(DriveConstants.turnConversion);
absoluteEncoder.setDistancePerRotation(2 * Math.PI);

turnRelativeEncoder.setVelocityConversionFactor(DriveConstants.turnConversion * 60);
turnPID = turnSparkMax.getPIDController();

turnSparkMax.restoreFactoryDefaults();
Expand Down Expand Up @@ -292,10 +289,11 @@ public void runDriveVelocitySetpoint(
&& MathUtil.isNear(0.0, driveVelocity.getValueAsDouble(), 0.1)) {
runDriveVoltage(0.0);
} else {
driveTalon.setControl(
driveCurrentVelocity
.withVelocity(metersPerSecond)
.withFeedForward(metersPerSecondSquared * driveConfig.Slot0.kA));
runDriveVoltage(
Math.signum(metersPerSecond)
* Math.pow((metersPerSecond / DriveConstants.maxLinearVelocity), 2)
* 12.0
* multiplier);
}
}

Expand Down

0 comments on commit c0b5501

Please sign in to comment.