Package choreo.util

Class ChoreoAllianceFlipUtil

java.lang.Object
choreo.util.ChoreoAllianceFlipUtil

public class ChoreoAllianceFlipUtil extends Object
A utility to standardize flipping of coordinate data based on the current alliance across different years.

If every vendor used this, the user would be able to specify the year and no matter the year the vendor's code is from, the user would be able to flip as expected.

This API still allows vendors and users to match case against the flipping variant as a way to specially handle cases or throw errors if a variant is explicitly not supported.

  • Method Details

    • getFlipper

      Get the flipper that is currently active for alliance-based flipping. It's recommended not to store this locally as the flipper may change.
      Returns:
      The active flipper.
    • getMirrorX

      Get the flipper that is currently active for mirroring to the other alliance. It's recommended not to store this locally as the flipper may change.
      Returns:
      The active alliance-mirroring flipper.
    • getMirrorY

      Get the flipper that is currently active for mirroring left-to-right from the driver's perspective. It's recommended not to store this locally as the flipper may change.
      Returns:
      The active left-right mirror flipper.
    • getRotateAround

      Get the flipper that is currently active for rotating around the field center. It's recommended not to store this locally as the flipper may change.
      Returns:
      The active rotate-around flipper.
    • shouldFlip

      public static boolean shouldFlip()
      Returns if you are on red alliance.
      Returns:
      If you are on red alliance.
    • setFlipper

      public static void setFlipper(ChoreoAllianceFlipUtil.Flipper flipper)
      Sets the flipper to use for alliance-based flipping. This will also set the mirror flippers based on the new flipper. You should only need to do this if you want to change the flipping behavior from the default, which is set based on the field dimensions and symmetry for the current FRC year. It's recommended to call this in a static block in Robot or equivalent so that it's set before any flipping is done.
      Parameters:
      flipper - The new flipper to use for alliance-based flipping.
    • flipX

      public static double flipX(double x)
      Flips the X coordinate to the other alliance.
      Parameters:
      x - The X coordinate to flip.
      Returns:
      The flipped X coordinate.
    • flipY

      public static double flipY(double y)
      Flips the Y coordinate to the other alliance.
      Parameters:
      y - The Y coordinate to flip.
      Returns:
      The flipped Y coordinate.
    • flipHeading

      public static double flipHeading(double heading)
      Flips the heading to the other alliance.
      Parameters:
      heading - The heading to flip.
      Returns:
      The flipped heading.
    • flip

      public static Translation2d flip(Translation2d translation)
      Flips the translation to the other alliance.
      Parameters:
      translation - The translation to flip.
      Returns:
      The flipped translation.
    • flip

      public static Rotation2d flip(Rotation2d rotation)
      Flips the rotation to the other alliance.
      Parameters:
      rotation - The rotation to flip.
      Returns:
      The flipped rotation.
    • flip

      public static Pose2d flip(Pose2d pose)
      Flips the pose to the other alliance.
      Parameters:
      pose - The pose to flip.
      Returns:
      The flipped pose.
    • flip

      public static Translation3d flip(Translation3d translation)
      Flips the translation to the other alliance.
      Parameters:
      translation - The translation to flip.
      Returns:
      The flipped translation.
    • flip

      public static Rotation3d flip(Rotation3d rotation)
      Flips the rotation to the other alliance.
      Parameters:
      rotation - The rotation to flip.
      Returns:
      The flipped rotation.
    • flip

      public static Pose3d flip(Pose3d pose)
      Flips the pose to the other alliance.
      Parameters:
      pose - The pose to flip.
      Returns:
      The flipped pose.
    • flip

      public static SwerveSample flip(SwerveSample sample)
      Flips the swerve sample to the other alliance.
      Parameters:
      sample - The swerve sample to flip.
      Returns:
      The flipped swerve sample.
    • flip

      public static DifferentialSample flip(DifferentialSample sample)
      Flips the differential sample to the other alliance.
      Parameters:
      sample - The differential sample to flip.
      Returns:
      The flipped differential sample.
    • optionalFlippedPose2d

      public static Supplier<Optional<Pose2d>> optionalFlippedPose2d(Optional<Pose2d> poseOpt, Supplier<Optional<DriverStation.Alliance>> allianceOpt, boolean doFlip)
      Creates a Supplier<Optional<Pose2d>> based on a Supplier<Optional<Alliance>> and original Optional<Pose2d>
      Parameters:
      poseOpt - The pose to flip
      allianceOpt - The current alliance
      doFlip - Returns true if flipping based on the alliance should be done
      Returns:
      empty if the alliance is empty; the original pose optional if the alliance is blue or doFlip is false; the flipped pose optional if the alliance is red and doFlip is true
    • optionalFlippedTranslation2d

      Creates a Supplier<Optional<Translation2d>> that is flipped based on a Supplier<Optional<Alliance>> and original Optional<Translation2d>
      Parameters:
      translationOpt - The translation to flip
      allianceOpt - The current alliance
      doFlip - Returns true if flipping based on the alliance should be done
      Returns:
      empty if the alliance is empty; the original translation optional if the alliance is blue or doFlip is false; the flipped translation optional if the alliance is red and doFlip is true