Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/first/robot/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

421 changes: 421 additions & 0 deletions src/main/java/first/robot/FieldConstants.java

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions src/main/java/first/robot/util/AllianceFlipUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package first.robot.util;

import first.robot.FieldConstants;
import org.wpilib.driverstation.Alliance;
import org.wpilib.driverstation.MatchState;
import org.wpilib.math.geometry.Pose2d;
import org.wpilib.math.geometry.Rotation2d;
import org.wpilib.math.geometry.Translation2d;

public class AllianceFlipUtil {
public static double fieldWidth = FieldConstants.fieldWidth;
public static double fieldLength = FieldConstants.fieldLength;

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 new Pose2d(apply(pose.getTranslation()), apply(pose.getRotation()));
}

public static double overrideApplyX(double x) {
return fieldLength - x;
}

public static double overrideApplyY(double y) {
return fieldWidth - y;
}

public static Translation2d overrideApply(Translation2d translation) {
return new Translation2d(
overrideApplyX(translation.getX()), overrideApplyY(translation.getY()));
}

public static Rotation2d overrideApply(Rotation2d rotation) {
return rotation.rotateBy(Rotation2d.kPi);
}

public static Pose2d overrideApply(Pose2d pose) {
return new Pose2d(overrideApply(pose.getTranslation()), overrideApply(pose.getRotation()));
}

public static boolean shouldFlip() {
return MatchState.getAlliance().isPresent() && MatchState.getAlliance().get() == Alliance.RED;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading