Class Goal

java.lang.Object
org.ironmaple.simulation.Goal
All Implemented Interfaces:
SimulatedArena.Simulatable
Direct Known Subclasses:
CrescendoAmp, CrescendoSpeaker, RebuiltHub, RebuiltOutpost, ReefscapeBargeSimulation, ReefscapeProcessorSimulation, ReefscapeReefBranch

public abstract class Goal extends Object implements SimulatedArena.Simulatable

An Abstract Class to Handle Scoring Elements in Simulation.

  • Field Details

    • xyBox

      protected org.dyn4j.geometry.Rectangle xyBox
    • height

      protected final Distance height
    • elevation

      protected final Distance elevation
    • gamePieceType

      protected final String gamePieceType
    • position

      protected final Translation3d position
    • arena

      protected final SimulatedArena arena
    • max

      protected final int max
    • isBlue

      public final boolean isBlue
    • gamePieceCount

      protected int gamePieceCount
    • allowGrounded

      protected final boolean allowGrounded
    • rotationChecker

      protected Goal.RotationChecker rotationChecker
    • positionChecker

      protected Goal.PositionChecker positionChecker
    • velocityValidator

      protected Predicate<GamePiece> velocityValidator
  • Constructor Details

    • Goal

      public Goal(SimulatedArena arena, Distance xDimension, Distance yDimension, Distance height, String gamePieceType, Translation3d position, boolean isBlue, int max, boolean allowGrounded)

      Creates a Goal Object

      Parameters:
      arena - The host arena of this goal
      xDimension - The x dimension of the default box collider.
      yDimension - The y dimension of the default box collider.
      height - The height or z dimension of the default box collider.
      gamePieceType - the string game piece type to be handled by this goal.
      position - The position of this goal.
      isBlue - Whether this is a blue goal or a red one.
      max - How many pieces can be scored in this goal.
      allowsGrounded - Wether or not grounded pieces can be scored in this goal
    • Goal

      public Goal(SimulatedArena arena, Distance xDimension, Distance yDimension, Distance height, String gamePieceType, Translation3d position, boolean isBlue, boolean allowsGrounded)

      Creates a Goal Object with No Scoring Maximum

      Parameters:
      arena - The host arena of this goal.
      xDimension - The x dimension of the default box collider.
      yDimension - The y dimension of the default box collider.
      height - The height or z dimension of the default box collider.
      gamePieceType - the string game piece type to be handled by this goal.
      position - The position of this goal.
      isBlue - Wether this is a blue goal or a red one.
      allowsGrounded - Wether or not grounded pieces can be scored in this goal
  • Method Details

    • flipRotation

      public static Rotation3d flipRotation(Rotation3d toFlip)

      Reverses a Rotation 180 Degrees Around the Z-Axis

      Used internally for checking game pieces that can score in either orientation.

      Parameters:
      toFlip - the rotation to flip
      Returns:
      the flipped rotation
    • box

      public static Goal.PositionChecker box(org.dyn4j.geometry.Rectangle xyBox, double minZMeters, double maxZMeters)

      Creates a Box-Shaped Position Checker

      Validates that a position is within an axis-aligned 3D box.

      Parameters:
      xyBox - the 2D box in XY plane
      minZMeters - minimum Z coordinate in meters
      maxZMeters - maximum Z coordinate in meters
      Returns:
      position checker for box-shaped bounds
    • absoluteAngle

      public static Goal.RotationChecker absoluteAngle(Rotation3d expectedAngle, Angle tolerance)

      Creates an Absolute Angle Rotation Checker

      Validates that a game piece's rotation matches an expected angle within tolerance, checking both pitch and yaw. Considers both normal and flipped (180-degree rotated) orientations.

      Parameters:
      expectedAngle - the expected 3D rotation
      tolerance - the allowed angular difference
      Returns:
      rotation checker for absolute angle matching
    • pitchOnly

      public static Goal.RotationChecker pitchOnly(double expectedPitchRadians, Angle tolerance)

      Creates a Pitch-Only Rotation Checker

      Validates only the pitch (Y-axis rotation) of a game piece, ignoring yaw and roll. Useful for ring-shaped game pieces where orientation around the vertical axis doesn't matter.

      Parameters:
      expectedPitchRadians - the expected pitch in radians
      tolerance - the allowed angular difference
      Returns:
      rotation checker for pitch-only validation
    • anyRotation

      public static Goal.RotationChecker anyRotation()

      Creates an Always-Valid Rotation Checker

      Returns:
      rotation checker that always returns true
    • simulationSubTick

      public void simulationSubTick(int subTickNum)

      Handles the update triggers for the goal object.

      Specified by:
      simulationSubTick in interface SimulatedArena.Simulatable
      Parameters:
      subTickNum - the number of this sub-tick (counting from 0 in each robot period)
    • setNeededAngle

      public void setNeededAngle(Rotation3d angle, Angle angleTolerance)

      Sets the Angle to be Used When Checking Game Piece Rotation

      Parameters:
      angle - The angle that pieces should have when interacting with this goal
      angleTolerance - The tolerance to be used in checking said angle.
    • setNeededAngle

      public void setNeededAngle(Rotation3d angle)

      Sets the Angle to be Used When Checking Game Piece Rotation

      Parameters:
      angle - The angle that pieces should have when interacting with this goal
    • withCustomRotationChecker

      public Goal withCustomRotationChecker(Goal.RotationChecker checker)

      Sets a Custom Rotation Checker for This Goal

      Replaces the default rotation validation logic with a custom checker. This allows for complex rotation checks beyond simple pitch/yaw tolerance, such as validating only specific axes or implementing custom logic.

      Parameters:
      checker - rotation checker that validates game piece rotation
      Returns:
      this Goal instance for method chaining
    • checkValidity

      protected boolean checkValidity(GamePiece gamePiece)

      Sets a Custom Rotation Validator for This Goal

      Convenience method that accepts a Predicate for backward compatibility.

      Parameters:
      validator - predicate that accepts GamePiece and returns true if rotation is valid
      Returns:
      this Goal instance for method chaining
    • checkGrounded

      protected boolean checkGrounded(GamePiece gamePiece)

      Checks whether the submitted game piece is grounded and if this is acceptable

      Parameters:
      gamePiece - The game piece to have its groundedness checked.
      Returns:
      Whether the piece is acceptable for this goal.
    • withCustomRotationValidator

      public Goal withCustomRotationValidator(Predicate<GamePiece> validator)
    • withRotationTolerance

      @Deprecated public Goal withRotationTolerance(Angle tolerance)
      Deprecated.
      Use setNeededAngle(Rotation3d, Angle) instead to set both angle and tolerance

      Sets Rotation Tolerance for Pitch and Yaw

      Configures the tolerance used by the default rotation validation logic. This only works if you have previously set an expected angle using setNeededAngle(Rotation3d, Angle).

      Note: This method cannot update the tolerance without knowing the expected angle. If you need to change the tolerance, use setNeededAngle(Rotation3d, Angle) again with the new tolerance.

      Parameters:
      tolerance - maximum allowed difference in degrees
      Returns:
      this Goal instance for method chaining
    • checkCollision

      protected boolean checkCollision(GamePiece gamePiece)

      Sets a Custom Position Checker for This Goal

      Replaces the default box collision with a custom shape check. This allows for cylindrical, spherical, or other complex collision zones beyond axis-aligned boxes.

      Parameters:
      checker - position checker that validates 3D positions
      Returns:
      this Goal instance for method chaining
    • withCustomPositionChecker

      public Goal withCustomPositionChecker(Goal.PositionChecker checker)
    • withCustomCollisionPredicate

      public Goal withCustomCollisionPredicate(Predicate<Translation3d> predicate)

      Sets a Custom Collision Detection Predicate

      Convenience method that accepts a Predicate for backward compatibility.

      Parameters:
      predicate - function that accepts Translation3d and returns true if inside goal zone
      Returns:
      this Goal instance for method chaining
    • withCustomVelocityValidator

      public Goal withCustomVelocityValidator(Predicate<GamePiece> validator)
      Configures custom velocity requirements for scoring. This can be used to require pieces to be ascending, descending, or moving within certain speed ranges.

      The predicate receives the GamePiece and should return true if the velocity is acceptable for scoring.

      Parameters:
      validator - predicate that accepts GamePiece and returns true if velocity is valid
      Returns:
      this Goal instance for method chaining
    • clear

      public void clear()

      Removes All Game Pieces from This Goal

    • isFull

      public boolean isFull()

      Returns Whether This Goal is Full

      Returns:
      Whether or not the goal is full.
    • addPoints

      protected abstract void addPoints()

      Adds Points When a Piece Has Been Successfully Scored in This Goal

      Since this function is the only trigger called when a piece is scored it may handle other small things outside of adding points.

    • draw

      public abstract void draw(List<Pose3d> drawList)

      Displays Game Pieces to AdvantageScope if Applicable

      Parameters:
      drawList - a list of Pose3d objects used to visualize the positions of the game pieces on AdvantageScope
    • getGamePieceCount

      public int getGamePieceCount()

      Returns the Number of Game Pieces Currently Scored in This Goal

      Returns:
      This goals game piece count.