Package jsim.wpilib
Class SimulatedField
java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
jsim.wpilib.SimulatedField
- All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable,edu.wpi.first.wpilibj2.command.Subsystem
public final class SimulatedField
extends edu.wpi.first.wpilibj2.command.SubsystemBase
A WPILib subsystem that runs a JSim
FieldSimulator automatically.
Construct one instance in RobotContainer, pass suppliers for
the robot's chassis speeds and pose, and the subsystem handles everything
else: physics stepping, gripper updates, and NT4 game-piece publishing for
AdvantageScope.
Minimal usage:
private final SimulatedField fieldSim = new SimulatedField(
"2025-reefscape",
drive::getRobotRelativeSpeeds,
drive::getPose);
For non-default robot dimensions or intake geometry use the builder:
private final SimulatedField fieldSim = SimulatedField.of("2025-reefscape")
.withRobotSize(0.38, 0.38, 0.1)
.withRobotMass(60)
.withIntake(0.4, 0.05, 0.5)
.build(drive::getRobotRelativeSpeeds, drive::getPose);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder forSimulatedFieldthat allows customizing robot body dimensions, mass, and intake geometry. -
Constructor Summary
ConstructorsConstructorDescriptionSimulatedField(String fieldResource, Supplier<edu.wpi.first.math.kinematics.ChassisSpeeds> speedsSupplier, Supplier<edu.wpi.first.math.geometry.Pose2d> poseSupplier) Create aSimulatedFieldwith default robot body dimensions (24"×24", 54 kg). -
Method Summary
Modifier and TypeMethodDescriptionedu.wpi.first.wpilibj2.command.CommandEject the held game piece forward in the robot's heading direction with an upward loft.Returns the underlyingFieldSimulatorfor advanced use — spawning additional game pieces, custom force generators, sensors, etc.edu.wpi.first.wpilibj2.command.CommandGrab the closest free game piece within intake range.static SimulatedField.BuilderEntry point for the builder API when non-default robot or intake geometry is needed.voidMethods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystemMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, idle, periodic, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, startEnd, startRun
-
Constructor Details
-
SimulatedField
public SimulatedField(String fieldResource, Supplier<edu.wpi.first.math.kinematics.ChassisSpeeds> speedsSupplier, Supplier<edu.wpi.first.math.geometry.Pose2d> poseSupplier) Create aSimulatedFieldwith default robot body dimensions (24"×24", 54 kg).The robot body is positioned at the pose returned by
poseSupplierat construction time, so it starts at the same location as the swerve odometry.- Parameters:
fieldResource- bundled field resource name (e.g."2025-reefscape")speedsSupplier- supplier of robot-relative chassis speeds from swerve odometryposeSupplier- supplier of the current robot pose from swerve odometry
-
-
Method Details
-
intakeNearest
public edu.wpi.first.wpilibj2.command.Command intakeNearest()Grab the closest free game piece within intake range. No-op if the gripper is already holding a piece.- Returns:
- a one-shot
Commandsuitable for binding to a trigger
-
ejectPiece
public edu.wpi.first.wpilibj2.command.Command ejectPiece()Eject the held game piece forward in the robot's heading direction with an upward loft. No-op if nothing is held.- Returns:
- a one-shot
Commandsuitable for binding to a trigger
-
getFieldSimulator
Returns the underlyingFieldSimulatorfor advanced use — spawning additional game pieces, custom force generators, sensors, etc.- Returns:
- the underlying field simulator
-
simulationPeriodic
public void simulationPeriodic() -
of
Entry point for the builder API when non-default robot or intake geometry is needed.- Parameters:
fieldResource- bundled field resource name (e.g."2025-reefscape")- Returns:
- a new
SimulatedField.Builder
-