Package frc.lib.util

Class FieldUtil

java.lang.Object
frc.lib.util.FieldUtil

public class FieldUtil extends Object
Utility class for performing field geometry operations that automatically flip based on the current alliance color.
  • Field Details

    • FIELD_LENGTH

      public static final Distance FIELD_LENGTH
      Total length of the field.
    • FIELD_WIDTH

      public static final Distance FIELD_WIDTH
      Total width of the field.
  • Method Details

    • shouldFlip

      public static boolean shouldFlip()
      Checks if the robot needs to flip its coordinate system for the Red alliance.
      Returns:
      True if on the Red alliance, false if Blue or unknown.
    • flipAllianceIfNeeded

      public static Rectangle2d flipAllianceIfNeeded(Rectangle2d rectangle)
      Flips a Rectangle2d to the opposite side of the field if on the Red alliance.
      Parameters:
      rectangle - The rectangle to flip.
      Returns:
      The flipped rectangle, or the original if not needed.
    • flipAllianceIfNeeded

      public static Pose2d flipAllianceIfNeeded(Pose2d pose)
      Flips a Pose2d to the opposite side of the field if on the Red alliance.
      Parameters:
      pose - The pose to flip.
      Returns:
      The flipped pose, or the original if not needed.
    • flipAllianceIfNeeded

      public static Translation2d flipAllianceIfNeeded(Translation2d translation)
      Flips a Translation2d to the opposite side of the field if on the Red alliance.
      Parameters:
      translation - The translation to flip.
      Returns:
      The flipped translation, or the original if not needed.
    • flipAllianceIfNeeded

      public static Rotation2d flipAllianceIfNeeded(Rotation2d rotation)
      Flips a Rotation2d to the opposite side of the field if on the Red alliance.
      Parameters:
      rotation - The rotation to flip.
      Returns:
      The flipped rotation, or the original if not needed.
    • flipAlliance

      public static Rectangle2d flipAlliance(Rectangle2d rectangle)
      Forces a flip of a Rectangle2d to the opposite side of the field.
      Parameters:
      rectangle - The rectangle to flip.
      Returns:
      The flipped rectangle.
    • flipAlliance

      public static Pose2d flipAlliance(Pose2d pose)
      Forces a flip of a Pose2d to the opposite side of the field.
      Parameters:
      pose - The pose to flip.
      Returns:
      The flipped pose.
    • flipAlliance

      public static Translation2d flipAlliance(Translation2d translation)
      Forces a flip of a Translation2d to the opposite side of the field.
      Parameters:
      translation - The translation to flip.
      Returns:
      The flipped translation.
    • flipAlliance

      public static Rotation2d flipAlliance(Rotation2d rotation)
      Forces a flip of a Rotation2d to the opposite side of the field.
      Parameters:
      rotation - The rotation to flip.
      Returns:
      The flipped rotation.