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

Commit

Permalink
refactor: Move alliance flip logic to robot.
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenheroux committed Apr 28, 2024
1 parent 66d88f5 commit 31d860d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 34 deletions.
26 changes: 0 additions & 26 deletions src/main/java/frc/lib/AllianceFlipHelper.java

This file was deleted.

17 changes: 16 additions & 1 deletion src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/auto/Auto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,7 +50,7 @@ private Auto() {
swerve.maximumTranslationVelocity(),
swerve.driveRadius(),
new ReplanningConfig()),
AllianceFlipHelper::shouldFlip,
Robot::isRedAlliance,
swerve);

NamedCommands.registerCommand("stow", superstructure.stow());
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/frc/robot/odometry/Odometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 31d860d

Please sign in to comment.