The Synthesis simulator comes with code simulation already integrated. However, a development environment for what ever code your are trying to simulate will be required. Synthesis' code simulation relies on the WPILib HALSim extensions, specifically the websocket-client extension. You'll need to make the following changes to your build.gradle
in order to properly simulate your code in Synthesis.
You'll need to enable desktop support for your project in order to run the HALSim:
def includeDesktopSupport = true
In order to communicate with your browser, you'll need to enable the websocket server extension with the following:
wpi.sim.envVar("HALSIMWS_HOST", "127.0.0.1")
wpi.sim.addWebsocketsServer().defaultEnabled = true
For CAN-based device support (TalonFX, CANSparkMax, most Gyros), you'll need our own library–SyntheSim. Currently only available for Java, SyntheSim adds additional support for third party devices that don't follow WPILib's web socket specification. It's still in early development, so you'll need to clone and install the library locally in order to use it:
$ git clone https://github.com/Autodesk/synthesis.git
$ cd synthesis/simulation/SyntheSimJava
$ ./gradlew build && ./gradlew publishToMavenLocal
Next, you'll need to have the local maven repository is added to your project by making sure the following is included in your build.gradle
file:
repositories {
mavenLocal()
...
}
Finally, you can add the SyntheSim dependency to your build.gradle
:
dependencies {
...
implementation "com.autodesk.synthesis:SyntheSimJava:1.0.0"
...
}
All of these instructions can be found in the SyntheSim README.
SyntheSim is very much a work in progress. If there is a particular device that isn't compatible, feel free to head to our GitHub to see about contributing.
This should be added by default, but in case it isn't, add this to your build.gradle
to enable the SimGUI extension by default.
wpi.sim.addGui().defaultEnabled = true
This will allow you to change the state of the robot, as well as hook up any joysticks you'd like to use during teleop. You must use this GUI in order to bring your robot out of disconnected mode, otherwise we won't be able to change the state of your robot from within the app.
To start your robot code, you can use the following simulate commands with gradle:
$ ./gradlew simulateJava
or for C++:
$ ./gradlew simulateNative
WPILib also has a command from within VSCode you can use the start your robot code:
Once started, make sure in the SimGUI that your robot state is set to "Disabled", not "Disconnected".
Open up Fission and spawn in a robot. Once spawned in, place it down and open the config panel. This can be done by using the left-hand menu and navigating to your robot in the config panel, or by right-clicking on your robot and selecting the "Configure" option.
Next, switch the brain currently controlling the robot. In order to give the simulation control over the robot, the brain must be switched from "Synthesis" to "WPILib". At the moment, only one robot can be controlled by the simulation at a time.
In the top-right, there should be a connection status indicator. If your robot program was running prior to switching to the "WPILib" brain, it should connect quickly.
Under your robot in the config panel, there should be a Simulation option now. Here you can find all the settings for the code simulation.
You can enabled auto reconnect incase you are having issues with this. In order for it to take affect, you have to enable the setting, then switch back to the "Synthesis" brain and then back again to the "WPILib" brain. This setting will be saved.
This panel can be used to "wire up" your robot. It will show you all the inputs and outputs available from both the simulation and robot. The handles (little circles with labels) are colored to indicate the type of data they represent. Hover over the information icons for more information.
The bottom-left controls can be used to zoom in/out, fit your view to the nodes, and add junction nodes for connection many connections to many connections.
The Auto Testing panel allows for iterative testing of an autonomous routine. I'd recommend making sure that the auto reconnect option is enabled.
You can specify a max time, alliance station, and game data. Once you've decided on those and have place the robot where you want, you can start your auto routine. After the specified amount of time, or when the stop button is pressed, the simulation will freeze and you can either reset to where you started, or close the panel.
If you need help with anything regarding Synthesis or it's related features please reach out through our discord server. It's the best way to get in contact with the community and our current developers.