Skip to content

Commit

Permalink
Removed alliance checking code from flipper
Browse files Browse the repository at this point in the history
  • Loading branch information
oh-yes-0-fps committed Sep 24, 2024
1 parent f5afe29 commit 8adcf63
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import edu.wpi.first.hal.DriverStationJNI;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.MatchInfoData;
import edu.wpi.first.math.geometry.AllianceFlipper;
import edu.wpi.first.networktables.BooleanPublisher;
import edu.wpi.first.networktables.IntegerPublisher;
import edu.wpi.first.networktables.NetworkTableInstance;
Expand All @@ -30,13 +29,6 @@

/** Provide access to the network communication data to / from the Driver Station. */
public final class DriverStation {
static {
// i don't like this, 110% open to suggestions
AllianceFlipper.setOnRed(
() -> getAlliance().orElse(Alliance.Blue) == Alliance.Red
);
}

/** Number of Joystick ports. */
public static final int kJoystickPorts = 6;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.wpi.first.math.geometry;

import java.util.HashMap;
import java.util.function.BooleanSupplier;

/**
* A utility to standardize flipping of coordinate data based on the current alliance across
Expand Down Expand Up @@ -89,14 +88,6 @@ public static interface Flippable<Self extends Flippable<Self>> {
public default Self flip() {
return flip(getFlipper());
}

/**
* Flips the object if on the red alliance, otherwise returns the object unchanged.
*/
@SuppressWarnings("unchecked")
public default Self flipIfRed() {
return onRed() ? flip() : (Self) this;
}
}

private static record YearInfo(Flipper flipper, double fieldLength, double fieldWidth) {}
Expand All @@ -111,7 +102,6 @@ private static record YearInfo(Flipper flipper, double fieldLength, double field
};

private static YearInfo activeYear = flipperMap.get(2024);
private static BooleanSupplier onRed = () -> false;

/**
* Get the flipper that is currently active for flipping coordinates. It's reccomended not to
Expand All @@ -123,24 +113,6 @@ public static Flipper getFlipper() {
return activeYear.flipper;
}

/**
* Returns if you are on red alliance, if the alliance is unknown it will return false.
*
* @return If you are on red alliance.
*/
public static boolean onRed() {
return onRed.getAsBoolean();
}

/**
* Returns if you are on blue alliance, if the alliance is unknown it will return true.
*
* @return If you are on blue alliance.
*/
public static boolean onBlue() {
return !onRed.getAsBoolean();
}

/**
* Set the year to determine the Alliance Coordinate Flipper to use.
*
Expand All @@ -156,16 +128,6 @@ public static void setYear(int year) {
activeYear = flipperMap.get(year);
}

/**
* Set the `onRed` resolver to determine if the robot is on the red alliance.
*
* @param onRedResolver The resolver to determine if the robot is on the red alliance.
*/
public static void setOnRed(BooleanSupplier onRedResolver) {
// cannot access driverstation in wpimath
onRed = onRedResolver;
}

/**
* Flips the X coordinate.
*
Expand Down Expand Up @@ -206,18 +168,4 @@ public static double flipHeading(double heading) {
public static <T extends Flippable<T>> T flip(Flippable<T> flippable) {
return flippable.flip();
}

/**
* Flips the {@link Flippable} object if on the red alliance.
*
* @param <T> The type of the object to flip.
* @param flippable The object to flip.
* @return The flipped object.
*
* @see #onRed() A way of determining if you are on the red alliance.
* @see Flippable#flipIfRed() An instance method that does the same thing.
*/
public static <T extends Flippable<T>> T flipIfRed(Flippable<T> flippable) {
return flippable.flipIfRed();
}
}

0 comments on commit 8adcf63

Please sign in to comment.