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 Classes
    Modifier and Type
    Class
    Description
    static final class 
    Builder for SimulatedField that allows customizing robot body dimensions, mass, and intake geometry.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SimulatedField(String fieldResource, Supplier<edu.wpi.first.math.kinematics.ChassisSpeeds> speedsSupplier, Supplier<edu.wpi.first.math.geometry.Pose2d> poseSupplier)
    Create a SimulatedField with default robot body dimensions (24"×24", 54 kg).
  • Method Summary

    Modifier and Type
    Method
    Description
    edu.wpi.first.wpilibj2.command.Command
    Eject the held game piece forward in the robot's heading direction with an upward loft.
    Returns the underlying FieldSimulator for advanced use — spawning additional game pieces, custom force generators, sensors, etc.
    edu.wpi.first.wpilibj2.command.Command
    Grab the closest free game piece within intake range.
    of(String fieldResource)
    Entry point for the builder API when non-default robot or intake geometry is needed.
    void
     

    Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase

    addChild, getName, getSubsystem, initSendable, setName, setSubsystem

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods 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 a SimulatedField with default robot body dimensions (24"×24", 54 kg).

      The robot body is positioned at the pose returned by poseSupplier at 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 odometry
      poseSupplier - 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 Command suitable 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 Command suitable for binding to a trigger
    • getFieldSimulator

      public FieldSimulator getFieldSimulator()
      Returns the underlying FieldSimulator for advanced use — spawning additional game pieces, custom force generators, sensors, etc.
      Returns:
      the underlying field simulator
    • simulationPeriodic

      public void simulationPeriodic()
    • of

      public static SimulatedField.Builder of(String fieldResource)
      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