SimDevice Types for CAN Wrapping HALSIM Library #6917
-
Hi, I am an intern at Autodesk working on Synthesis, an FRC robot simulator for Fusion CAD exports. We're working on a code simulation system, where users can run their code on a robot being simulated in Synthesis. We're doing this with the WPILib HalSim WebSocket specification, where the robot code runs on a device and it gets piped over a WebSocket connection to Synthesis, which can also send back necessary sensor data. This was trivial for PWM devices, but we quickly found that critical CAN vendor devices didn't support simulation via the specification, so we decided to create a library of our own custom device wrappers that inherit from the device they enable simulation for, called SyntheSim. Important Some vendor CAN devices such as the We are doing this using the SimDevice class which is used by our custom device classes that extend the CAN devices we are offering simulation support for, in accordance with the HALSim WebSocket Specification. The question we have is how to change the device Notice how the vendor devices show up as having the type "PWM" or "CANMotor", while our custom devices (distinguished by their adherence to the WS spec and the "SYN" keyword) show up as "SimDevices", with the notable exception of the We need to send over type information to determine how to simulate them in Synthesis. Note that this is a separate field from Does anyone have any insight into how vendors are supposed to set the sent simulated device type? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
So it turns out that WPILib gets the Function found here |
Beta Was this translation helpful? Give feedback.
So it turns out that WPILib gets the
type
andid
(which is sent over the WebSocket connection as thedevice
field) by splitting the name you pass in when constructing theSimDevice
by the delimiter ":". So all we need to do is adhere to the particular naming convention of "[DeviceType]:[DeviceName]" and then theDeviceId
gets tacked on there as well by WPILib. For example: "CANMotor:CANSparkMax[1]"Function found here
We couldn't find this anywhere in documentation, it was discovered by @HunterBarclay while he was perusing the WPILib codebase.