Simulation: Test Without a Robot
Why simulate
Section titled “Why simulate”Robot time is scarce — the robot is often being built, repaired, or shared. Simulation runs your robot code on your laptop with no hardware, so you can test logic, command flow, autonomous routines, and odometry math any time. It catches whole classes of bugs (null references, wrong command wiring, bad math) before they ever reach the field.
Launching the Simulation GUI
Section titled “Launching the Simulation GUI”From VS Code’s WPILib command palette, choose “Simulate Robot Code.” When prompted, select the “Sim GUI” extension (selected by default) and click OK. The Simulation GUI opens, showing your robot’s state.
What the GUI shows
Section titled “What the GUI shows”The Sim GUI lets you visualize and control the robot:
- Robot State — switch between Disabled / Autonomous / Teleop / Test, just like the Driver Station.
- System Joysticks & Joysticks — drag a controller from “System Joysticks” into the active “Joysticks” panel to feed it to your code. You can also drag a Keyboard entry to drive with WASD-style keys, configurable via DS → Keyboard Settings.
- Map gamepad toggle — makes a real gamepad map the way the Driver Station would (otherwise the sim doesn’t remap by default).
- Other Devices / NetworkTables — inspect and edit values your code publishes.
Viewing the field
Section titled “Viewing the field”Publish your pose to a Field2d widget and the Sim GUI (or Glass/AdvantageScope) draws your robot on a field image:
private final Field2d m_field = new Field2d();// in constructor:SmartDashboard.putData("Field", m_field);// in periodic:m_field.setRobotPose(m_odometry.getPoseMeters());This is invaluable for debugging autonomous: you can watch the simulated robot follow a PathPlanner/Choreo trajectory and confirm your odometry and path logic are correct before risking the real robot.
Physics simulation
Section titled “Physics simulation”For more realism, WPILib provides physics simulation classes — e.g., DifferentialDrivetrainSim, FlywheelSim, ElevatorSim, SingleJointedArmSim — that model how a mechanism responds to voltage. Wired into your subsystem’s simulationPeriodic(), they make encoders and sensors return realistic values, so PID/feedforward tuning and motion profiles can be validated virtually.
Vendor sim support
Section titled “Vendor sim support”CTRE Phoenix 6 and REVLib include simulation support, so motor controllers report plausible positions/velocities in the sim. This means a command-based robot using vendor motors can often be driven entirely in simulation with little extra code.
A healthy workflow
Section titled “A healthy workflow”- Write or change code.
- Simulate it: drive with the keyboard, run your auto, watch the Field2d.
- Fix logic bugs in the fast feedback loop of simulation.
- Only then deploy to the real robot for final tuning.
Teams that simulate aggressively show up to practice with code that already mostly works , turning limited robot time into tuning time instead of debugging time.
Key takeaways
Section titled “Key takeaways”- Simulation runs your code on a laptop — test logic, autos, and odometry without a robot.
- Launch via ‘Simulate Robot Code’ and the Sim GUI; control modes and drag in joysticks/keyboard.
- Publish a Field2d to watch the simulated robot follow trajectories on a field image.
- Physics sim classes (DifferentialDrivetrainSim, ElevatorSim, etc.) model realistic mechanism response.
- Phoenix 6 and REVLib support simulation, so vendor-motor robots run in the sim with little extra code.
This lesson was adapted from learnfrc.com.
