Skip to content

Commit

Permalink
khsdufudsufhsdjk
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenTomato5 committed Oct 14, 2024
1 parent c41ce6f commit 81d3361
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/main/java/frc/robot/subsystems/drive/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Drive extends Subsystem<DriveStates> {
private double lastHeadingRadians;
private PIDController headingCorrectionController;
private boolean headingCorrectionEnabled;
private boolean fieldRelativeEnabled = true;

private SwerveDriveKinematics kinematics = new SwerveDriveKinematics(getModuleTranslations());
private Rotation2d rawGyroRotation = new Rotation2d();
Expand Down Expand Up @@ -123,18 +124,25 @@ public void runState() {
if (DriverStation.isTeleop() && getState() != DriveStates.AUTO_ALIGN) {
drive(
this,
() -> -Constants.controller.getLeftY(),
() -> -Constants.controller.getLeftX(),
() -> Constants.controller.getLeftY(),
() -> Constants.controller.getLeftX(),
() -> Constants.controller.getRightX(),
getState().getRotationModifier(),
getState().getTranslationModifier(),
headingCorrectionEnabled
headingCorrectionEnabled,
fieldRelativeEnabled
);
}

if (Constants.controller.getStartButtonPressed()) {
zeroGryo();
}

if (Constants.controller.getBackButtonPressed()) {
fieldRelativeEnabled = !fieldRelativeEnabled;
Logger.recordOutput("Drive", fieldRelativeEnabled);
}

}

// L code??? (taken from AA) good enough
Expand Down Expand Up @@ -164,7 +172,8 @@ public void drive(
DoubleSupplier omegaSupplier,
double rotationMultiplier,
double translationMultiplier,
boolean headingCorrection
boolean headingCorrection,
boolean fieldRelative
) {
// Apply deadband
double linearMagnitude = MathUtil.applyDeadband(
Expand Down Expand Up @@ -222,6 +231,7 @@ public void drive(
DriverStation.getAlliance().isPresent() &&
DriverStation.getAlliance().get() == Alliance.Red;
drive.runVelocity(
fieldRelative ?
ChassisSpeeds.fromFieldRelativeSpeeds(
linearVelocity.getX() *
drive.getMaxLinearSpeedMetersPerSec() *
Expand All @@ -233,6 +243,15 @@ public void drive(
(isFlipped
? drive.getRotation().plus(new Rotation2d(Math.PI))
: drive.getRotation()).times(-1)
) :
new ChassisSpeeds(
linearVelocity.getX() *
drive.getMaxLinearSpeedMetersPerSec() *
translationMultiplier,
linearVelocity.getY() *
drive.getMaxLinearSpeedMetersPerSec() *
translationMultiplier,
omega * drive.getMaxAngularSpeedRadPerSec() * rotationMultiplier
)
);
}
Expand Down Expand Up @@ -263,6 +282,7 @@ public void periodic() {
module.stop();
}
}

// Log empty setpoint states when disabled
if (DriverStation.isDisabled()) {
Logger.recordOutput("SwerveStates/Setpoints", new SwerveModuleState[] {});
Expand Down

0 comments on commit 81d3361

Please sign in to comment.