From 8898ad4d821da955aa9e8a4a493c1abd431d13db Mon Sep 17 00:00:00 2001 From: QuackitsQuinn Date: Tue, 23 Jan 2024 15:23:03 -0600 Subject: [PATCH 1/4] Add empty translation to create less instances of translation2d --- src/main/java/frc/robot/subsystems/Drive.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/subsystems/Drive.java b/src/main/java/frc/robot/subsystems/Drive.java index f1914cb5..cfbf9dcd 100644 --- a/src/main/java/frc/robot/subsystems/Drive.java +++ b/src/main/java/frc/robot/subsystems/Drive.java @@ -24,6 +24,9 @@ public class Drive extends SubsystemBase { SwerveDrive drive; + /** Empty translation to prevent creating 2 Translation2ds per periodic run */ + private static final Translation2d EMPTY_TRANSLATION = new Translation2d(); + /** Creates a new Drive. */ public Drive() { /* Try-catch because otherwise the compiler tries to anticipate runtime errors and throws a @@ -59,7 +62,7 @@ public void driveFieldOriented(double x, double y, double z) { } public void stop() { - drive.drive(new Translation2d(), 0, false, false, new Translation2d()); + drive.drive(EMPTY_TRANSLATION, 0, false, false, EMPTY_TRANSLATION); } public void enterXMode() { From 4cbd79d95c37f4ffb4b3d8c732e86d005f0953d7 Mon Sep 17 00:00:00 2001 From: QuackitsQuinn Date: Tue, 23 Jan 2024 15:45:57 -0600 Subject: [PATCH 2/4] move various drive constants to Constants --- src/main/java/frc/robot/Constants.java | 13 +++++++++++++ src/main/java/frc/robot/subsystems/Drive.java | 11 +++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 2337681c..ac27a01a 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -11,6 +11,8 @@ package frc.robot; +import edu.wpi.first.math.geometry.Translation2d; + /** * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean * constants. This class should not be used for any other purpose. All constants should be declared @@ -23,4 +25,15 @@ public final class Constants { public static class Controllers { public static final int DRIVER_CONTROLLER_PORT = 0; } + + public static class Drive { + /** Empty translation to prevent creating 2 Translation2ds every time the drive train stops. */ + public static Translation2d EMPTY_TRANSLATION = new Translation2d(); + + /** The max speed the robot can go */ + public static double MAX_SPEED = 1; + + /** The max speed the robot can rotate */ + public static double MAX_ANGULAR_SPEED = Math.PI / 2; + } } diff --git a/src/main/java/frc/robot/subsystems/Drive.java b/src/main/java/frc/robot/subsystems/Drive.java index cfbf9dcd..819ae20b 100644 --- a/src/main/java/frc/robot/subsystems/Drive.java +++ b/src/main/java/frc/robot/subsystems/Drive.java @@ -16,6 +16,7 @@ import edu.wpi.first.wpilibj.Filesystem; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.SubsystemBase; +import frc.robot.Constants; import java.io.File; import java.io.IOException; import swervelib.SwerveDrive; @@ -24,9 +25,6 @@ public class Drive extends SubsystemBase { SwerveDrive drive; - /** Empty translation to prevent creating 2 Translation2ds per periodic run */ - private static final Translation2d EMPTY_TRANSLATION = new Translation2d(); - /** Creates a new Drive. */ public Drive() { /* Try-catch because otherwise the compiler tries to anticipate runtime errors and throws a @@ -62,7 +60,8 @@ public void driveFieldOriented(double x, double y, double z) { } public void stop() { - drive.drive(EMPTY_TRANSLATION, 0, false, false, EMPTY_TRANSLATION); + drive.drive( + Constants.Drive.EMPTY_TRANSLATION, 0, false, false, Constants.Drive.EMPTY_TRANSLATION); } public void enterXMode() { @@ -70,11 +69,11 @@ public void enterXMode() { } private double getMaximumSpeed() { - return 1; // TODO: move this to constants + return Constants.Drive.MAX_SPEED; } private double getMaximumAngularSpeed() { - return Math.PI / 2; // TODO: move this to constants + return Constants.Drive.MAX_ANGULAR_SPEED; } @Override From bdb743f0139d50d966cce4835c77b476b407c8bd Mon Sep 17 00:00:00 2001 From: QuackitsQuinn Date: Tue, 23 Jan 2024 16:00:43 -0600 Subject: [PATCH 3/4] yeet hungarian notation again --- src/main/java/frc/robot/Robot.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 302be34a..4e67627a 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -16,13 +16,13 @@ import edu.wpi.first.wpilibj2.command.CommandScheduler; public class Robot extends TimedRobot { - private Command m_autonomousCommand; + private Command autonomousCommand; - private RobotContainer m_robotContainer; + private RobotContainer robotContainer; @Override public void robotInit() { - m_robotContainer = new RobotContainer(); + robotContainer = new RobotContainer(); } @Override @@ -41,10 +41,10 @@ public void disabledExit() {} @Override public void autonomousInit() { - m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + autonomousCommand = robotContainer.getAutonomousCommand(); - if (m_autonomousCommand != null) { - m_autonomousCommand.schedule(); + if (autonomousCommand != null) { + autonomousCommand.schedule(); } } @@ -56,8 +56,8 @@ public void autonomousExit() {} @Override public void teleopInit() { - if (m_autonomousCommand != null) { - m_autonomousCommand.cancel(); + if (autonomousCommand != null) { + autonomousCommand.cancel(); } } From 22287676744f970eb7ef992a73427c0d198b106d Mon Sep 17 00:00:00 2001 From: QuackitsQuinn Date: Tue, 23 Jan 2024 16:00:55 -0600 Subject: [PATCH 4/4] fix access modifier --- src/main/java/frc/robot/subsystems/Drive.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/subsystems/Drive.java b/src/main/java/frc/robot/subsystems/Drive.java index 819ae20b..4eb9ad0a 100644 --- a/src/main/java/frc/robot/subsystems/Drive.java +++ b/src/main/java/frc/robot/subsystems/Drive.java @@ -23,7 +23,7 @@ import swervelib.parser.SwerveParser; public class Drive extends SubsystemBase { - SwerveDrive drive; + private SwerveDrive drive; /** Creates a new Drive. */ public Drive() {