Can’t access your robot? You can still practice for the the Infinite Recharge at Home AutoNav challenges using WPILib’s drivetrain simulator that was introduced this year. I’ll walk through the process I used as well as some of the issues I had to work around.
Here’s an example with the Slalom challenge.
Install 2021 WPILib software
I started by installing the 2021 WPILib Software. Instructions here: WPILib Installation Guide — FIRST Robotics Competition documentation
An overview of the simulation capability is available here: Introduction to Robot Simulation — FIRST Robotics Competition documentation
Create Drivetrain simulation project
I created a new project from the State Space Drive Simulation example project. It would probably be possible to do the same thing with the Simple Differential Drive Simulation example project as well. There’s more information here: Drivetrain Simulation Tutorial — FIRST Robotics Competition documentation
Generate Waypoints using Pathweaver
I used Pathweaver to generate the waypoints. Make sure to set the export unit to Always Meters to match with WPILib’s trajectory classes. The version of Pathweaver in WPILib 2021.1.2 (the current release) doesn’t have field images for the Infinite Recharge at Home challenges. However @jdaming created a pull request to add them: Added the 5 IR @ Home Autonomous Challenges by jasondaming · Pull Request #200 · wpilibsuite/PathWeaver · GitHub Until there’s a new release, you can add them following the instructions here: Adding field images to PathWeaver — FIRST Robotics Competition documentation.
Here’s what my path looked like:
I found that the exported coordinates weren’t right. I had chosen project units of feet to match the lengths in the manual, but to export in meters, to match WPILib Trajectories. If you use meters for both, it should be fine, or this PR should be in the next release.
Incorporating Pathweaver Trajectory into Drivetrain Simulation Project
I followed the directions to read the Pathweaver trajectory here: Importing a PathWeaver JSON — FIRST Robotics Competition documentation replacing the voltage constraint, trajectory config and trajectory with the code to read the Pathweaver trajectory.
Pathweaver was supposed to generate the trajectory in my project’s deploy directory. I think I set up the project wrong, but it was easy enough to copy the file into the deploy directory.
Running in Simulation
Next I ran the code in simulation. Introduction to Robot Simulation — FIRST Robotics Competition documentation
From the NetworkTables menu in the simgui, I added the field from the smartdashboard namespace. Then you can right click on the title, expand the field item, and select choose image. From there, change the file type to Pathweaver JSON and point it to the json file from pathweaver earlier. You can now enable autonomous.
At this point it looked like this.
I’ll follow-up with how I improved the trajectory following using frc-characterization