Skip to content
Programming, Controls & Sensors·Lesson 20 of 51

Simulation: Test Without a Robot

Run robot code on your laptop with the WPILib Simulation GUI to debug logic, virtual joysticks, and field position before deploying.

Sign in to track progress, earn XP, and save lessons.

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

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

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

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

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

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

  1. Write or change code.
  2. Simulate it: drive with the keyboard, run your auto, watch the Field2d.
  3. Fix logic bugs in the fast feedback loop of simulation.
  4. 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

  • 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.

Lesson quiz

Required

Answer all 3 questions correctly to complete this lesson.

1.What is the main purpose of WPILib's robot simulation?

2.Before you can run desktop simulation, what must be enabled for the robot project?

3.Which WPILib class is intended to model the physics of a differential (tank-style) drivetrain in simulation?

Answer every question to submit.