-
Notifications
You must be signed in to change notification settings - Fork 0
Simulating Your Code At Home
This year, we're trying out Autodesk Synthesis for the first time. This 3D simulation program promises to allow us to test our code on a virtual robot (a CAD model, to be precise for the engineers), with very little configuration needed. Please see instructions below:
✅ When to use Synthesis | ❌ When not to use Synthesis |
---|---|
Testing code for a drivetrain (although for swerve drive you will need to configure a different robot model with a swerve drivetrain) | Testing sensors as currently only motors (called PWM controllers) and encoders are supported |
Testing autonomous driving based on encoders/time only | Testing autonomous based on any other sensor |
Testing the driver-controlled period on the engineers' CAD models |
Please follow the instructions on this linked page.
- Open Synthesis and click "Launch Simulator", "Singleplayer", then "Practice Mode". Select the "FRC Field 2022_v4".
Open Navigation Bar | Navigation Bar | MultiBot/Robot Switcher | Moving the Robot |
leftDrive RoboRIO configuration |
rightDrive RoboRIO configuration |
---|---|---|---|---|---|
-
From the navigation bar, open "MultiBot". Click "Add", then "Regular", then select "Team 2471 (2018)_v7" and click "Load". This is the robot with the most understandable configuration. In the "MultiBot" ("Robot Switcher") tab you can select the robot you are using so its circle is filled with orange, and also remove the robot and add others if you ever need to.
-
Move the robot that will appear in the centre by its central blue circle and arrows (you can do this whenever you want by navigating Navigation Bar > Configure > Move then click Back when you want to return to the navigation bar). Ensure it is on flat ground and not buried.
-
In the navigation bar click "Configure" then "RoboRIO". The ROBORio is basically the brain of our robot and is connected to all of the motors and sensors.
- To add...
- a motor: Click "Create Device", select "PWM", then select the necessary ports of the RoboRIO and output motors, name the device and click "Next". The current setup is port 0 is connected to all of the Left output motors in a device called "leftDrive" (type in the name at the top), and repeating this whole "Create Device" process, port 1 is connected to all of the Right output motors in a device called "rightDrive". Please see the images above.
- Save all of your configuration, click "Back" in the navigation bar, and you are now ready to test code.
When you close and re-open Synthesis, you will have to repeat steps 1 to 3 but the configuration in step 4 will be saved.
- In WPILib VS Code, ensure the last few lines of your
build.gradle
file are the ones shown below. If not, add them as Synthesis requires them to work.
// For Autodesk Synthesis
wpi.sim.envVar("HALSIMWS_HOST", "127.0.0.1")
wpi.sim.addWebsocketsClient().defaultEnabled = true
- With Synthesis open and set up as above, in WPILib VS Code use
Ctrl+Shift+P
to open the Command Palette and type "Simulate Robot Code". Ensure all of "Sim Websockets Client", "Use Real DriverStation", and "Sim GUI" are ticked, then click "OK".
3. If you are using a joystick in your code (i.e. it is teleoperated, meaning driver-controlled), click here.
Ensure the FRC Driver Station is closed, then open the Simulation Window and click and drag the "Keyboard 0" system joystick onto the
Joystick[0]
label in the "Joysticks" section. To see the controls, right-click the "Keyboard 0" label under "System Joysticks" then enter the settings.
Click-and-drag from here | Click-and-drag to here | Example Keyboard Joystick Settings |
---|---|---|
- Open the "FRC Driver Station" app, and wait for the Communications and Robot Code lights to turn green. You will now have these programs open as well as Synthesis and VS Code:
FRC Driver Station | FRC PC Dashboard | Robot Simulation |
---|---|---|
AKA "the Driver Station" | AKA "the default Dashboard" | AKA "the Simulation Window" |
The Driver Station is exactly what the driver uses in the real match to control the robot, but it also works with the simulation. | The default Dashboard is one way of seeing game data. You can find out more about dashboards on WPILib, but this one is probably not useful for us as we will likely be using one called Shuffleboard instead. You can close the default Dashboard whenever it opens. | The Simulation Window provides general tools for robot simulation, although a lot of simulation is carried out in Synthesis. We will be using it to set up virtual joysticks. |
-
Close the default Dashboard.
-
In the Driver Station, choose the correct OpMode (TeleOperated = Driver-Controlled, Autonomous, Practice or Test).
-
When you are ready, click "Enable" in the driver-station app (not Synthesis). In the driver station, you can click "disable" if you want to pause execution. In WPILib VS Code, you can see the console output and also completely end the code with the stop button.
More documentation will come soon!