From 31d860d56c41700875bec8f4a221bdc226f760d2 Mon Sep 17 00:00:00 2001 From: Hayden Heroux Date: Sun, 28 Apr 2024 15:12:07 -0400 Subject: [PATCH] refactor: Move alliance flip logic to robot. --- src/main/java/frc/lib/AllianceFlipHelper.java | 26 ------------------- src/main/java/frc/robot/Robot.java | 17 +++++++++++- src/main/java/frc/robot/auto/Auto.java | 4 +-- .../java/frc/robot/odometry/Odometry.java | 5 ---- 4 files changed, 18 insertions(+), 34 deletions(-) delete mode 100644 src/main/java/frc/lib/AllianceFlipHelper.java diff --git a/src/main/java/frc/lib/AllianceFlipHelper.java b/src/main/java/frc/lib/AllianceFlipHelper.java deleted file mode 100644 index cdaa33c..0000000 --- a/src/main/java/frc/lib/AllianceFlipHelper.java +++ /dev/null @@ -1,26 +0,0 @@ -package frc.lib; - -import edu.wpi.first.wpilibj.DriverStation; -import edu.wpi.first.wpilibj.DriverStation.Alliance; - -/** Helper class to assist with flipping positions behind on alliance. */ -public class AllianceFlipHelper { - /** - * Determines whether a path should be flipped. - * - * @return whether the path should be flipped. - */ - public static boolean shouldFlip() { - return isRedAlliance(); - } - - /** - * Returns true if on red alliance. - * - * @return true if on red alliance. - */ - public static boolean isRedAlliance() { - return DriverStation.getAlliance().isPresent() - && DriverStation.getAlliance().get() == Alliance.Red; - } -} diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 3347995..34b34fc 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -1,14 +1,29 @@ package frc.robot; +import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj.DriverStation.Alliance; import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.CommandScheduler; public class Robot extends TimedRobot { - private Command autonomousCommand; + /** Robot container. */ private RobotContainer robotContainer; + /** Command to run during autonomous. */ + private Command autonomousCommand; + + /** + * Returns true if on red alliance. + * + * @return true if on red alliance. + */ + public static boolean isRedAlliance() { + return DriverStation.getAlliance().isPresent() + && DriverStation.getAlliance().get() == Alliance.Red; + } + @Override public void robotInit() { robotContainer = RobotContainer.getInstance(); diff --git a/src/main/java/frc/robot/auto/Auto.java b/src/main/java/frc/robot/auto/Auto.java index b11235a..ac83584 100644 --- a/src/main/java/frc/robot/auto/Auto.java +++ b/src/main/java/frc/robot/auto/Auto.java @@ -8,9 +8,9 @@ import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj2.command.Command; -import frc.lib.AllianceFlipHelper; import frc.lib.Subsystem; import frc.lib.Telemetry; +import frc.robot.Robot; import frc.robot.odometry.Odometry; import frc.robot.superstructure.Superstructure; import frc.robot.swerve.Swerve; @@ -50,7 +50,7 @@ private Auto() { swerve.maximumTranslationVelocity(), swerve.driveRadius(), new ReplanningConfig()), - AllianceFlipHelper::shouldFlip, + Robot::isRedAlliance, swerve); NamedCommands.registerCommand("stow", superstructure.stow()); diff --git a/src/main/java/frc/robot/odometry/Odometry.java b/src/main/java/frc/robot/odometry/Odometry.java index af44103..eadcebc 100644 --- a/src/main/java/frc/robot/odometry/Odometry.java +++ b/src/main/java/frc/robot/odometry/Odometry.java @@ -12,7 +12,6 @@ import edu.wpi.first.wpilibj.smartdashboard.Field2d; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; -import frc.lib.AllianceFlipHelper; import frc.lib.Subsystem; import frc.lib.Telemetry; import frc.lib.sensor.GyroscopeIO; @@ -91,10 +90,6 @@ public void periodic() { @Override public void addToShuffleboard(ShuffleboardTab tab) { - ShuffleboardLayout shouldFlip = Telemetry.addColumn(tab, "Should Flip?"); - - shouldFlip.addBoolean("Should Flip?", () -> AllianceFlipHelper.shouldFlip()); - ShuffleboardLayout position = Telemetry.addColumn(tab, "Position"); position.addDouble("X (m)", () -> getPosition().getX());