Package choreo.util
Class ChoreoAllianceFlipUtil
java.lang.Object
choreo.util.ChoreoAllianceFlipUtil
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe flipper to use for flipping coordinates. -
Method Summary
Modifier and TypeMethodDescriptionstatic DifferentialSampleflip(DifferentialSample sample) Flips the differential sample to the other alliance.static SwerveSampleflip(SwerveSample sample) Flips the swerve sample to the other alliance.static Pose2dFlips the pose to the other alliance.static Pose3dFlips the pose to the other alliance.static Rotation2dflip(Rotation2d rotation) Flips the rotation to the other alliance.static Rotation3dflip(Rotation3d rotation) Flips the rotation to the other alliance.static Translation2dflip(Translation2d translation) Flips the translation to the other alliance.static Translation3dflip(Translation3d translation) Flips the translation to the other alliance.static doubleflipHeading(double heading) Flips the heading to the other alliance.static doubleflipX(double x) Flips the X coordinate to the other alliance.static doubleflipY(double y) Flips the Y coordinate to the other alliance.Get the flipper that is currently active for alliance-based flipping.Get the flipper that is currently active for mirroring to the other alliance.Get the flipper that is currently active for mirroring left-to-right from the driver's perspective.Get the flipper that is currently active for rotating around the field center.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>static Supplier<Optional<Translation2d>>optionalFlippedTranslation2d(Optional<Translation2d> translationOpt, Supplier<Optional<DriverStation.Alliance>> allianceOpt, boolean doFlip) Creates a Supplier<Optional<Translation2d>> that is flipped based on a Supplier<Optional<Alliance>> and original Optional<Translation2d>static voidsetFlipper(ChoreoAllianceFlipUtil.Flipper flipper) Sets the flipper to use for alliance-based flipping.static booleanReturns if you are on red alliance.
-
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
Returns if you are on red alliance.- Returns:
- If you are on red alliance.
-
setFlipper
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
Flips the X coordinate to the other alliance.- Parameters:
x- The X coordinate to flip.- Returns:
- The flipped X coordinate.
-
flipY
Flips the Y coordinate to the other alliance.- Parameters:
y- The Y coordinate to flip.- Returns:
- The flipped Y coordinate.
-
flipHeading
Flips the heading to the other alliance.- Parameters:
heading- The heading to flip.- Returns:
- The flipped heading.
-
flip
Flips the translation to the other alliance.- Parameters:
translation- The translation to flip.- Returns:
- The flipped translation.
-
flip
Flips the rotation to the other alliance.- Parameters:
rotation- The rotation to flip.- Returns:
- The flipped rotation.
-
flip
Flips the pose to the other alliance.- Parameters:
pose- The pose to flip.- Returns:
- The flipped pose.
-
flip
Flips the translation to the other alliance.- Parameters:
translation- The translation to flip.- Returns:
- The flipped translation.
-
flip
Flips the rotation to the other alliance.- Parameters:
rotation- The rotation to flip.- Returns:
- The flipped rotation.
-
flip
Flips the pose to the other alliance.- Parameters:
pose- The pose to flip.- Returns:
- The flipped pose.
-
flip
Flips the swerve sample to the other alliance.- Parameters:
sample- The swerve sample to flip.- Returns:
- The flipped swerve sample.
-
flip
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 flipallianceOpt- The current alliancedoFlip- 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
public static Supplier<Optional<Translation2d>> optionalFlippedTranslation2d(Optional<Translation2d> translationOpt, Supplier<Optional<DriverStation.Alliance>> allianceOpt, boolean doFlip) Creates a Supplier<Optional<Translation2d>> that is flipped based on a Supplier<Optional<Alliance>> and original Optional<Translation2d>- Parameters:
translationOpt- The translation to flipallianceOpt- The current alliancedoFlip- 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
-