Class SimulatedArena

java.lang.Object
org.ironmaple.simulation.SimulatedArena
Direct Known Subclasses:
Arena2024Crescendo

public abstract class SimulatedArena extends Object

Abstract Simulation World

Check Online Documentation

The heart of the simulator.

This class cannot be instantiated directly; it must be created as a specific season's arena.

The default instance can be obtained using the getInstance() method.

Simulates all interactions within the arena field.

The following objects can be added to the simulation world and will interact with each other:

  • Field Details

  • Constructor Details

    • SimulatedArena

      protected SimulatedArena(SimulatedArena.FieldMap obstaclesMap)

      Constructs a new simulation arena with the specified field map of obstacles.

      This constructor initializes a physics world with zero gravity and adds the provided obstacles to the world.

      It also sets up the collections for drivetrain simulations, game pieces, projectiles, and intake simulations.

      Parameters:
      obstaclesMap - the season-specific field map containing the layout of obstacles for the simulation
  • Method Details

    • getInstance

      public static SimulatedArena getInstance()

      Gets/Creates the Default Simulation World

      Multiple instances of SimulatedArena can exist elsewhere.

      Returns:
      the main simulation arena instance
      Throws:
      IllegalStateException - if the method is call when running on a real robot
    • overrideInstance

      public static void overrideInstance(SimulatedArena newInstance)

      Overrides the Default Simulation World

      Overrides the return value of getInstance()

      This method allows simulating an arena from a different year or a custom field.

      Currently, only the 2024 arena is supported, so avoid calling this method for now.

      Parameters:
      newInstance - the new simulation arena instance to override the current one
    • getSimulationSubTicksIn1Period

      public static int getSimulationSubTicksIn1Period()
    • getSimulationDt

      public static edu.wpi.first.units.measure.Time getSimulationDt()
    • overrideSimulationTimings

      public static void overrideSimulationTimings(edu.wpi.first.units.measure.Time robotPeriod, int simulationSubTicksPerPeriod)

      Overrides the Timing Configurations of the Simulations.

      If Using Advantage-Kit: DO NOT CHANGE THE DEFAULT TIMINGS

      Changes apply to every instance of SimulatedArena.

      The new configuration will take effect the next time simulationPeriodic() is called on an instance.

      It is recommended to call this method before the first call to simulationPeriodic() of any instance.

      It is also recommended to keep the simulation frequency above 200 Hz for accurate simulation results.

      Parameters:
      robotPeriod - the time between two calls of simulationPeriodic(), usually obtained from IterativeRobotBase.getPeriod()
      simulationSubTicksPerPeriod - the number of Iterations, or simulationSubTick(int) that the simulation runs per each call to simulationPeriodic()
    • addCustomSimulation

      public void addCustomSimulation(SimulatedArena.Simulatable simulatable)

      Registers a custom simulation.

      Parameters:
      simulatable - the custom simulation to register
    • addIntakeSimulation

      protected void addIntakeSimulation(IntakeSimulation intakeSimulation)

      Registers an IntakeSimulation.

      NOTE: This method is automatically called in the constructor of IntakeSimulation, so you don't need to call it manually.

      The intake simulation should be bound to an AbstractDriveTrainSimulation and becomes part of its collision space.

      This method immediately starts the IntakeSimulation.GamePieceContactListener, which listens for contact between the intake and any game piece.

      Parameters:
      intakeSimulation - the intake simulation to be registered
    • addDriveTrainSimulation

      public void addDriveTrainSimulation(AbstractDriveTrainSimulation driveTrainSimulation)

      Registers an AbstractDriveTrainSimulation.

      The collision space of the drive train is immediately added to the simulation world.

      Starting from the next call to simulationPeriodic(), the AbstractDriveTrainSimulation.simulationSubTick() method will be called during each sub-tick of the simulator.

      Parameters:
      driveTrainSimulation - the drivetrain simulation to be registered
    • addGamePiece

      public void addGamePiece(GamePieceOnFieldSimulation gamePiece)

      Registers a GamePieceOnFieldSimulation to the Simulation.

      The collision space of the game piece is immediately added to the simulation world.

      IntakeSimulations will be able to interact with this game piece during the next call to simulationPeriodic().

      Parameters:
      gamePiece - the game piece to be registered in the simulation
    • addGamePieceProjectile

      public void addGamePieceProjectile(GamePieceProjectile gamePieceProjectile)

      Registers a GamePieceProjectile to the Simulation and Launches It.

      Calls to GamePieceProjectile.launch(), which will launch the game piece immediately.

      Parameters:
      gamePieceProjectile - the projectile to be registered and launched in the simulation
    • removeGamePiece

      public void removeGamePiece(GamePieceOnFieldSimulation gamePiece)

      Removes a GamePieceOnFieldSimulation from the Simulation.

      Removes the game piece from the physics world and the simulation's game piece collection.

      Parameters:
      gamePiece - the game piece to be removed from the simulation
    • clearGamePieces

      public void clearGamePieces()

      Removes All GamePieceOnFieldSimulation Objects from the Simulation.

      This method clears all game pieces from the physics world and the simulation's game piece collection.

    • simulationPeriodic

      public void simulationPeriodic()

      Update the simulation world.

      This method should be called ONCE in IterativeRobotBase.simulationPeriodic() (or LoggedRobot.simulationPeriodic() if using Advantage-Kit)

      If not configured through overrideSimulationTimings(Time, int) , the simulator will iterate through 5 Sub-ticks by default.

      The amount of CPU Time that the Dyn4j engine uses in displayed in SmartDashboard/MapleArenaSimulation/Dyn4jEngineCPUTimeMS, usually performance is not a concern

    • getGamePiecesByType

      public List<Pose3d> getGamePiecesByType(String type)

      Obtains the 3D Poses of a Specific Type of Game Piece.

      This method is used to visualize the positions of game pieces

      Also, if you have a game-piece detection vision system (wow!), this is the how you can simulate it.

      Both GamePieceOnFieldSimulation and GamePieceProjectile of the specified type will be included.

      Parameters:
      type - the type of game piece, as determined by the constructor of GamePieceOnFieldSimulation
      Returns:
      a List of Pose3d objects representing the 3D positions of the game pieces
    • resetFieldForAuto

      public void resetFieldForAuto()

      Resets the Field for Autonomous Mode.

      This method clears all current game pieces from the field and places new game pieces in their starting positions for the autonomous mode.

    • placeGamePiecesOnField

      public abstract void placeGamePiecesOnField()

      Places Game Pieces on the Field for Autonomous Mode.

      This method sets up the game pieces on the field, typically in their starting positions for autonomous mode.

      It should be implemented differently for each season-specific subclass of SimulatedArena to reflect the unique game piece placements for that season's game.

    • competitionPeriodic

      public abstract void competitionPeriodic()

      Season-Specific Actions to Execute in simulationPeriodic().

      This method defines season-specific tasks to be executed during the simulationPeriodic() method.

      For example:

      • Updating the score counts.
      • Simulating human player activities.

      This method should be implemented in the season-specific subclass of SimulatedArena to reflect the unique aspects of that season's game.