-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abcfae3
commit 209efa6
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2025 FRC 6328 | ||
// http://github.com/Mechanical-Advantage | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file at | ||
// the root directory of this project. | ||
|
||
package frc.robot.utils; | ||
|
||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.geometry.Translation2d; | ||
import edu.wpi.first.math.util.Units; | ||
import edu.wpi.first.wpilibj.DriverStation; | ||
|
||
public class AllianceFlipUtil { | ||
public static double fieldWidth = Units.feetToMeters(26.0) + Units.inchesToMeters(5.0); | ||
public static double fieldLength = Units.feetToMeters(57.0) + Units.inchesToMeters(6.875); | ||
|
||
public static double applyX(double x) { | ||
return shouldFlip() ? fieldLength - x : x; | ||
} | ||
|
||
public static double applyY(double y) { | ||
return shouldFlip() ? fieldWidth - y : y; | ||
} | ||
|
||
public static Translation2d apply(Translation2d translation) { | ||
return new Translation2d(applyX(translation.getX()), applyY(translation.getY())); | ||
} | ||
|
||
public static Rotation2d apply(Rotation2d rotation) { | ||
return shouldFlip() ? rotation.rotateBy(Rotation2d.kPi) : rotation; | ||
} | ||
|
||
public static Pose2d apply(Pose2d pose) { | ||
return shouldFlip() | ||
? new Pose2d(apply(pose.getTranslation()), apply(pose.getRotation())) | ||
: pose; | ||
} | ||
|
||
public static boolean shouldFlip() { | ||
return DriverStation.getAlliance().isPresent() | ||
&& DriverStation.getAlliance().get() == DriverStation.Alliance.Red; | ||
} | ||
} |