Class SimulatedArena
- Direct Known Subclasses:
Arena2024Crescendo
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:
AbstractDriveTrainSimulation
: Represents abstract drivetrain simulations with collision detection.GamePieceOnFieldSimulation
: Represents abstract game pieces with collision detection.IntakeSimulation
: Represents an intake simulation that responds to contact withGamePieceOnFieldSimulation
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Represents an Abstract Field Mapstatic interface
Represents a custom simulation to be updated during each simulation sub-tick. -
Field Summary
Modifier and TypeFieldDescriptionprotected final List<SimulatedArena.Simulatable>
protected final Set<AbstractDriveTrainSimulation>
protected final Set<GamePieceProjectile>
protected final Set<GamePieceOnFieldSimulation>
protected final org.dyn4j.world.World<org.dyn4j.dynamics.Body>
-
Constructor Summary
ModifierConstructorDescriptionprotected
SimulatedArena
(SimulatedArena.FieldMap obstaclesMap) Constructs a new simulation arena with the specified field map of obstacles. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCustomSimulation
(SimulatedArena.Simulatable simulatable) Registers a custom simulation.void
addDriveTrainSimulation
(AbstractDriveTrainSimulation driveTrainSimulation) Registers anAbstractDriveTrainSimulation
.void
addGamePiece
(GamePieceOnFieldSimulation gamePiece) Registers aGamePieceOnFieldSimulation
to the Simulation.void
addGamePieceProjectile
(GamePieceProjectile gamePieceProjectile) Registers aGamePieceProjectile
to the Simulation and Launches It.protected void
addIntakeSimulation
(IntakeSimulation intakeSimulation) Registers anIntakeSimulation
.void
Removes AllGamePieceOnFieldSimulation
Objects from the Simulation.abstract void
Season-Specific Actions to Execute insimulationPeriodic()
.getGamePiecesByType
(String type) Obtains the 3D Poses of a Specific Type of Game Piece.static SimulatedArena
Gets/Creates the Default Simulation Worldstatic edu.wpi.first.units.measure.Time
static int
static void
overrideInstance
(SimulatedArena newInstance) Overrides the Default Simulation Worldstatic void
overrideSimulationTimings
(edu.wpi.first.units.measure.Time robotPeriod, int simulationSubTicksPerPeriod) Overrides the Timing Configurations of the Simulations.abstract void
Places Game Pieces on the Field for Autonomous Mode.void
removeGamePiece
(GamePieceOnFieldSimulation gamePiece) Removes aGamePieceOnFieldSimulation
from the Simulation.void
Resets the Field for Autonomous Mode.void
Update the simulation world.
-
Field Details
-
physicsWorld
protected final org.dyn4j.world.World<org.dyn4j.dynamics.Body> physicsWorld -
driveTrainSimulations
-
gamePieces
-
gamePieceProjectile
-
customSimulations
-
-
Constructor Details
-
SimulatedArena
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
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
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 ofsimulationPeriodic()
, usually obtained fromIterativeRobotBase.getPeriod()
simulationSubTicksPerPeriod
- the number of Iterations, orsimulationSubTick(int)
that the simulation runs per each call tosimulationPeriodic()
-
addCustomSimulation
Registers a custom simulation.
- Parameters:
simulatable
- the custom simulation to register
-
addIntakeSimulation
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
Registers an
AbstractDriveTrainSimulation
.The collision space of the drive train is immediately added to the simulation world.
Starting from the next call to
simulationPeriodic()
, theAbstractDriveTrainSimulation.simulationSubTick()
method will be called during each sub-tick of the simulator.- Parameters:
driveTrainSimulation
- the drivetrain simulation to be registered
-
addGamePiece
Registers a
GamePieceOnFieldSimulation
to the Simulation.The collision space of the game piece is immediately added to the simulation world.
IntakeSimulation
s will be able to interact with this game piece during the next call tosimulationPeriodic()
.- Parameters:
gamePiece
- the game piece to be registered in the simulation
-
addGamePieceProjectile
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
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()
(orLoggedRobot.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
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
andGamePieceProjectile
of the specified type will be included.- The type is determined in the constructor of
GamePieceOnFieldSimulation
. - For example,
CrescendoNoteOnField
has the type "Note".
- Parameters:
type
- the type of game piece, as determined by the constructor ofGamePieceOnFieldSimulation
- Returns:
- a
List
ofPose3d
objects representing the 3D positions of the game pieces
- The type is determined in the constructor of
-
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.
-