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#
- 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.
the part worth keeping
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.
Programming, Controls & SensorsAutonomous: Odometry, Trajectories, and Simulationlesson 4 of 4
Keep going
Take the quiz+10 XP with an accountMore in Autonomous: Odometry, Trajectories, and Simulation
where this came from
Sources and corrections
This lesson is AI-assisted: drafted from primary sources, then reviewed and edited by hand. Errors still get through. When one is reported we fix it and write down what changed, in public, in the corrections log.
sources and further reading
- docs.wpilib.orgIntroduction to Robot Simulation
- docs.wpilib.orgSimulation GUI
- docs.wpilib.orgPhysics Simulation with WPILib
clipped to this lesson
Articles that go further on this
The lesson gets you through the topic. These go wider on it, and they read in one sitting.
- 7 min readPractice FRC Programming Without a Robot: WPILib SimulationPractice FRC programming without a robot using WPILib simulation: run real robot code on your laptop, drive a virtual robot, model physics, and test./blogread it
- 15 min readFRC Odometry and Pose Estimation: Field-Centric Control with WPILibHow an FRC robot tracks its field position with WPILib: wheel odometry vs pose estimation, gyro heading, fusing AprilTag vision, and field-centric driving./blogread it
- 13 min readFRC Code Structure Best Practices: Command-Based Project ArchitectureHow to structure an FRC command-based robot project the right way — subsystems, commands, RobotContainer, and Constants — verified against official WPILib docs./blogread it
answer sheet
Lesson quiz
All 3 right completes the lesson. Miss one and only that question comes back, anything you already answered correctly stays banked.
0 of 3 answered
01What is the main purpose of WPILib's robot simulation?
02How do you make the Sim GUI draw your robot's position on a field image?
03Which WPILib class is intended to model the physics of a differential (tank-style) drivetrain in simulation?
Answer every question to submit.
All 51 lessons in Programming, Controls & Sensorsopenclose
01 / prerequisites
02 / foundations-tools-and-first-program
03 / robot-program-and-command-based
04 / motors-and-control
05 / autonomous-trajectories-simulation
06 / sensing-fundamentals
07 / encoders
08 / gyros-imus-orientation
09 / closed-loop-control
10 / vision-pose-estimation
11 / worked-examples-mini-projects
- Not read yet:Mini-Project: A Closed-Loop Elevator with Motion Magic
- Not read yet:Mini-Project: A Velocity-Controlled Shooter on REVLib
- Not read yet:Mini-Project: A Teleop Swerve Drive Subsystem
- Not read yet:Mini-Project: An Autonomous Routine with PathPlanner
- Not read yet:Mini-Project: Vision-Aligned Scoring with Limelight
12 / common-mistakes-troubleshooting
13 / advanced-techniques-case-studies
- Not read yet:State-Space Control and Kalman Filtering
- Not read yet:Log Replay Architecture with AdvantageKit
- Not read yet:Advanced Pose Estimation: Multi-Tag Fusion and Standard Deviations
- Not read yet:Robot Coordination, Alerts, and Operator Feedback
- Not read yet:Case Study: Hardening Software Before an Event