Currently, using the sim support provided by lib199 is error prone because it requires knowing the names of the various devices and properties and using those names (as strings) to create and use SimDeviceSim objects. To address this:
- Use the
asyncapi-generator like we do in DeepBlueSim, to auto-generate *Sim classes for the various CAN devices we create SimDevices for. These would have names like CANEncoderSim, CANMotorSim, CANDutyCycleSim, etc. The constructors would take the class name (e.g. CANSparkMax), port number, and an optional "input" name (for devices with multiple inputs).
- Make the public API provided by the
*Sim classes as consistent as possible with the API provided by WPI's *Sim classes. In particular, the register*Callback methods should return a CallbackStore subclass and any cancel*Callback methods should not be public.
- Create simple subclasses of the above
*Sim classes for each of the actual device objects we simulate (e.g. CANSparkMaxSim extends CANMotorSim) and have the constructors for those take the actual device objects (e.g. a CANSparkMax) and construct the appropriate class name to pass to the *Sim super constructor.
Side note: Although we could reuse these *Sim classes in DeepBlueSim.jarWPIWebSockets.jar (instead of auto-generating separate *Sim classes there), that would have the following disadvantages:
- Reusing the result of 1 above would involve either making
DeepBlueSim.jarWPIWebSockets.jar depend on lib199.jar or putting the *Sim classes in a separate jar that both lib199.jar and WPIWebSockets.jar (and robot projects) depend on.
- Doing 2 would make
DeepBlueSim.jarWPIWebSockets.jar depend on wpilib.
- Doing 3 would make
DeepBlueSim.jarWPIWebSockets.jar depend on vendordeps if the sims weren't split into a separate jar.
Those extra dependencies don't seem worth the effort since the "real" common API is defined by the wpilib-ws.yaml file use to auto-generate the *Sim classes in both projects anyways.
Currently, using the sim support provided by lib199 is error prone because it requires knowing the names of the various devices and properties and using those names (as strings) to create and use
SimDeviceSimobjects. To address this:asyncapi-generatorlike we do inDeepBlueSim, to auto-generate*Simclasses for the various CAN devices we createSimDevicesfor. These would have names likeCANEncoderSim,CANMotorSim,CANDutyCycleSim, etc. The constructors would take the class name (e.g.CANSparkMax), port number, and an optional "input" name (for devices with multiple inputs).*Simclasses as consistent as possible with the API provided by WPI's*Simclasses. In particular, theregister*Callbackmethods should return aCallbackStoresubclass and anycancel*Callbackmethods should not be public.*Simclasses for each of the actual device objects we simulate (e.g.CANSparkMaxSimextendsCANMotorSim) and have the constructors for those take the actual device objects (e.g. aCANSparkMax) and construct the appropriate class name to pass to the*Simsuper constructor.Side note: Although we could reuse these
*Simclasses inDeepBlueSim.jarWPIWebSockets.jar(instead of auto-generating separate*Simclasses there), that would have the following disadvantages:DeepBlueSim.jarWPIWebSockets.jardepend on lib199.jar or putting the*Simclasses in a separate jar that bothlib199.jarandWPIWebSockets.jar(and robot projects) depend on.DeepBlueSim.jarWPIWebSockets.jardepend on wpilib.DeepBlueSim.jarWPIWebSockets.jardepend on vendordeps if the sims weren't split into a separate jar.Those extra dependencies don't seem worth the effort since the "real" common API is defined by the
wpilib-ws.yamlfile use to auto-generate the*Simclasses in both projects anyways.