Activity 6.4: Simulate an Auto Routine
🎯 Goal
By the end of this activity you will have:
- Launched your team’s robot code in WPILib simulation
- Selected and run a PathPlanner autonomous routine in the simulator
- Observed the robot’s path on the 2D field view in Glass or AdvantageScope
- Identified at least one thing to adjust and iterated on the routine
Step 1: Verify Your Project Supports Simulation
Before launching, check that your project is set up for simulation:
- Open
RobotContainer.java and verify that PathPlanner’sAutoBuilderis configured - Check that your auto chooser is set up — look for
AutoBuilder.buildAutoChooser()or similar - Verify your drivetrain has simulation support — look for a
simulationPeriodic()method inCommandSwerveDrivetrain.java
If your drivetrain doesn’t have simulation support, you may need to add it. CTRE’s swerve template includes simulation support out of the box. Check the CTRE Phoenix 6 documentation for details.
Step 2: Launch the Simulator
- Open a terminal in your project directory
- Run:
./gradlew simulateJava - When prompted, select Sim GUI
- Wait for the simulation window to appear
You should see the Sim GUI with panels for Robot State, Joysticks, and System devices.
Step 3: Set Up the Field View
You need a 2D field view to watch the robot follow the path:
Option A: Using Glass
- In the Sim GUI, the field view may already be available
- Look for “Field” in the NetworkTables tree
- Drag it to create a 2D field visualization
- You should see a small rectangle representing the robot on the field
Option B: Using AdvantageScope
- Open AdvantageScope
- Connect to the simulation via NetworkTables (it auto-discovers on localhost)
- Create an Odometry view and add the robot pose
- You’ll see the robot on the field in real time
Visualization tool I’m using: _______________
Step 4: Select an Auto Routine
- In the Sim GUI, find the auto chooser in the NetworkTables panel
- It should show a dropdown of available auto routines from PathPlanner
- Select one of your team’s auto routines
If you don’t see the auto chooser:
- Make sure your code publishes it:
SmartDashboard.putData("Auto Chooser", autoChooser) - Check that
AutoBuilderis configured in RobotContainer
Auto routine selected: _______________
Step 5: Run the Auto
- In the Sim GUI Robot State panel, click Autonomous to switch to auto mode
- Click Enable to start the robot
- Watch the 2D field view — the robot should start moving along the path
What to Observe
As the auto runs, pay attention to:
| What to Watch | What It Tells You |
|---|---|
| Path shape | Does the robot follow the expected route? |
| Starting position | Is the robot starting where you expect on the field? |
| Named Command timing | Do mechanism actions trigger at the right moments? |
| End position | Does the robot end up where you planned? |
| Total time | How long does the auto take? Is there time for more? |
If the robot doesn’t move or behaves strangely:
- Robot doesn’t move at all — Check that AutoBuilder is configured and the auto routine loaded correctly. Look for errors in the console output.
- Robot moves but doesn’t follow the path — The starting pose might not match the path’s starting pose. PathPlanner autos often set the initial pose automatically.
- Robot spins in circles — The gyro simulation might not be configured. Check that the simulated gyro is providing heading data.
- Path is mirrored — Check the alliance color setting. PathPlanner flips paths for red vs blue alliance.
- Named Commands don’t fire — Verify they’re registered with
NamedCommands.registerCommand()before the auto is built.
Step 6: Record Your Observations
After running the auto, document what you saw:
| Observation | Value / Description |
|---|---|
| Auto routine name | |
| Starting position (x, y, heading) | |
| Ending position (x, y, heading) | |
| Total time (seconds) | |
| Number of paths in the routine | |
| Named Commands that fired | |
| Did the robot follow the expected path? | Yes / No / Partially |
| Any unexpected behavior? |
Step 7: Iterate on the Routine
Based on your observations, make one adjustment and re-test:
Possible Adjustments
- Change a path waypoint — open PathPlanner GUI, adjust a waypoint, save, re-run simulation
- Adjust path constraints — increase or decrease max velocity/acceleration
- Change Named Command timing — move an event marker earlier or later along the path
- Add a new Named Command — register a new command and add it to the auto
After making your change:
- Stop the simulation (
Ctrl+Cin terminal or close the Sim GUI) - Re-launch:
./gradlew simulateJava - Run the auto again and compare
Change I made: _______________ Result: _______________
Step 8: Compare Before and After
Strong answers include:
-
Specific observations — e.g., “I ran our 2-piece auto. The robot followed the first path correctly but overshot the second pickup point by about 20cm. The total time was 12.3 seconds.”
-
A specific change and result — e.g., “I reduced the max velocity on the second path from 4.0 m/s to 3.5 m/s and added a deceleration zone near the pickup. The overshoot was reduced and the robot stopped closer to the target.”
-
A realistic limitation — e.g., “Simulation doesn’t model carpet friction or wheel slip, so the actual path following on the real field will be different. The PID gains that work in sim may need adjustment on the real robot. Also, game piece interactions aren’t simulated, so I can’t verify that the intake actually picks up the piece.”
Bonus: Run Multiple Autos
If your team has several auto routines, run each one in simulation:
- Which one is fastest?
- Which one is most reliable (follows the path most accurately)?
- Are there any that fail or behave unexpectedly?
Document your findings and share them with your drive team — this information helps with match strategy.
What’s Next?
You’ve now used simulation to test and iterate on autonomous routines without a physical robot. In Lesson 6.5: Control Theory — PID, Feedforward, and Motion Profiling, you’ll dive into the math behind how your robot controls mechanisms precisely — the PID loops, feedforward calculations, and motion profiles that make accurate autonomous movement possible.