Simulation
Robot Simulation
Simulation in WPILib allows for code and logic to be tested onboard your computer, rather than physical hardware. It's exceptionally useful for when mechanical hasn't finished the robot, but you have code to run!
There are a few different facets of simulation to take note of before you can start, including:
- The Simulation GUI
- WPILib's simulation classes
- Physics simulators
- Mechanism2d
- Field2d
- Logging & Dashboards
Logging & Dashboards
In testing, it is common to want to directly observe current or past robot measurements and values in order to tune your systems or debug. This is also incredibly important when working with simulation, as you otherwise have no reference to what is going on without a physical robot.
For more details, visit our doc.
Simulation Classes
This section will heavily reference the WPILib docs here.
Before doing anything with simulation, make sure desktop support is turned on. Follow these instructions. Use the next doc as reference for the GUI when working with it (same as above).
WPILib contains generic simulation classes for different mechanisms (like ElevatorSim
) based on physical details and constraints about your system. You can see a full list of them and examples on using them here.
Widgets
There's also the widget classes Field2d
and Mechanism2d
, which respectively allow for pixel representations of the field and parts of mechanisms.
Physical objects, like game pieces, wheels, the drivetrain, etc., can be added to a Field2d object, allowing for digital representations of a real-life field. Here's more on how you can use it.
Mechanism2ds allow for block representations of mechanisms. This is most commonly used for simulating arms and elevators. See the docs for usage details and further clarifications.