Skip to content

Auto-generate *Sim classes for CAN devices #98

@brettle

Description

@brettle

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:

  1. 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).
  2. 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.
  3. 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:

  1. 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.
  2. Doing 2 would make DeepBlueSim.jarWPIWebSockets.jar depend on wpilib.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions