Running C++ Examples
C++ examples are located in thewpilibcExamples project and can be run using Gradle.
Basic Command
<ExampleName> with the name of the example’s folder (in PascalCase). For example:
Available C++ Examples
Some popular simulation-ready examples include:- ElevatorSimulation: Simulated elevator mechanism with physics
- ArmSimulation: Simulated arm mechanism with state-space control
- StateSpaceArm: Advanced arm control using state-space methods
- StateSpaceElevator: Advanced elevator control
- StateSpaceFlywheel: Flywheel simulation with state-space control
- SimpleDifferentialDriveSimulation: Basic differential drive simulation
- SwerveBot: Swerve drive kinematics example
- RamseteCommand: Path following with RAMSETE controller
- MecanumControllerCommand: Mecanum drive trajectory following
Running Java Examples
Java examples are located in thewpilibjExamples project with a similar command structure.
Basic Command
What Happens When You Run
Load Extensions
The simulation framework loads configured HALSIM extensions (GUI, Driver Station socket, etc.).
Open GUI
If
halsim_gui is enabled, the simulation GUI window opens showing:- Hardware devices (motors, encoders, gyros, etc.)
- Driver Station controls
- Robot state information
Interacting with Simulated Robots
Using the Simulation GUI
When the GUI opens, you can:- Enable the robot: Click “TeleOp” or “Autonomous” in the Driver Station widget
- Control inputs:
- Use keyboard for joystick simulation
- Click on sensors to change values
- Drag sliders for analog inputs
- Monitor outputs:
- See motor speeds and directions
- View encoder counts
- Check digital I/O states
Using the Real Driver Station
Ifhalsim_ds_socket is loaded, you can connect the actual FRC Driver Station:
Building Without Running
To compile examples without running them:C++ Examples
Java Examples
Running Tests
Many examples include unit tests that run in simulation:C++ Tests
Java Tests
Run All Tests
Example-Specific Tests
Some examples have their own test suites:Build Performance Tips
Use Build Cache
Speed up builds by using the shared build cache:Build Only What You Need
The full./gradlew build command builds for all platforms (desktop + cross-compilers). For faster development:
- Use
testDesktopCpportestDesktopJavafor specific tests - Use
buildDesktopCpporbuildDesktopJavato compile without running - Target specific projects with
:projectName:task
Troubleshooting
Example Won’t Start
- Ensure you have JDK 17 installed (not just JRE)
- Run
./gradlew compileJavato generate dependencies - Check that no other instance is using the same ports
GUI Doesn’t Appear
- Verify
halsim_guiextension is enabled - Check console output for initialization errors
- Ensure graphics drivers are up to date
Driver Station Won’t Connect
- Confirm
halsim_ds_socketextension is loaded - Check firewall settings allow local connections
- Verify Driver Station is set to practice mode
Next Steps
Simulation Overview
Learn about the simulation framework architecture
GUI Tools
Explore the simulation GUI features in detail