From 91bbb34355888a9d477ee8e9108eb8478e95623b Mon Sep 17 00:00:00 2001 From: aarav18 Date: Sun, 15 Jan 2023 16:32:41 -0700 Subject: [PATCH] high and low speed gears --- src/main/java/frc4388/robot/Constants.java | 4 +++- .../java/frc4388/robot/subsystems/SwerveDrive.java | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/frc4388/robot/Constants.java b/src/main/java/frc4388/robot/Constants.java index a7dc11e..9b39fd4 100644 --- a/src/main/java/frc4388/robot/Constants.java +++ b/src/main/java/frc4388/robot/Constants.java @@ -59,7 +59,9 @@ public final class Constants { public static final class Conversions { public static final int CANCODER_TICKS_PER_ROTATION = 4096; - public static final double JOYSTICK_TO_METERS_PER_SECOND = 5.0; // 2022's robot: 11 m/s for fast, 2 m/s for slow + + public static final double JOYSTICK_TO_METERS_PER_SECOND_FAST = 11.0; // TODO: find the actual value + public static final double JOYSTICK_TO_METERS_PER_SECOND_SLOW = 2.0; // TODO: find the actual value public static final double MOTOR_REV_PER_WHEEL_REV = -1; // TODO: find the actual value public static final double TICKS_PER_MOTOR_REV = 2048; diff --git a/src/main/java/frc4388/robot/subsystems/SwerveDrive.java b/src/main/java/frc4388/robot/subsystems/SwerveDrive.java index 69d5e31..5a7c8cd 100644 --- a/src/main/java/frc4388/robot/subsystems/SwerveDrive.java +++ b/src/main/java/frc4388/robot/subsystems/SwerveDrive.java @@ -31,6 +31,8 @@ public class SwerveDrive extends SubsystemBase { private RobotGyro gyro; + public double speedAdjust = SwerveDriveConstants.Conversions.JOYSTICK_TO_METERS_PER_SECOND_SLOW; // * slow by default + /** Creates a new SwerveDrive. */ public SwerveDrive(SwerveModule leftFront, SwerveModule rightFront, SwerveModule leftBack, SwerveModule rightBack, RobotGyro gyro) { this.leftFront = leftFront; @@ -44,8 +46,8 @@ public class SwerveDrive extends SubsystemBase { } public void driveWithInput(double xSpeed, double ySpeed, double rot, boolean fieldRelative) { - double xSpeedMetersPerSecond = xSpeed * SwerveDriveConstants.Conversions.JOYSTICK_TO_METERS_PER_SECOND; - double ySpeedMetersPerSecond = ySpeed * SwerveDriveConstants.Conversions.JOYSTICK_TO_METERS_PER_SECOND; + double xSpeedMetersPerSecond = xSpeed * SwerveDriveConstants.Conversions.JOYSTICK_TO_METERS_PER_SECOND_FAST; + double ySpeedMetersPerSecond = ySpeed * SwerveDriveConstants.Conversions.JOYSTICK_TO_METERS_PER_SECOND_FAST; SwerveModuleState[] states = kinematics.toSwerveModuleStates( fieldRelative ? ChassisSpeeds.fromFieldRelativeSpeeds(xSpeedMetersPerSecond, ySpeedMetersPerSecond, rot, gyro.getRotation2d()) @@ -72,4 +74,9 @@ public class SwerveDrive extends SubsystemBase { public void periodic() { // This method will be called once per scheduler run } + + public void highSpeed(boolean shift) { + this.speedAdjust = shift ? SwerveDriveConstants.Conversions.JOYSTICK_TO_METERS_PER_SECOND_FAST : SwerveDriveConstants.Conversions.JOYSTICK_TO_METERS_PER_SECOND_SLOW; + } + }