Repository navigation
Description
This assumes that #24 and #25 have completed.
Instead of waiting to create a mediator object until we receive a message that targets a particular device, create the mediator object for each device at startup and let the mediator object use the device's fields (from #24) to determine which which messages to register callbacks for. This would allow us to validate the robot's devices before starting the simulation so we could catch errors earlier.
Note that, despite their names, WebotsMotorForwarder, MockGyro, MockedSparkEncoder, and MockedEncoder all implement something close to the mediator design pattern. It's not a perfect match, but it's the closest well-recognized pattern I could find. Anyway, currently they all implement the pattern differently and are not particularly amenable to unit testing. Let's rework them to be consistent and testable. This will make the code easier to maintain and easier for other developers to understand and write their own mediators. To that end, I suggest that each mediator class should:
- Have a name of the form
<Device>Mediatorwhere<Device>is the name of the corresponding Webots device (typically a PROTO defined in Create PROTOs corresponding to common FRC parts #24). - Have a constructor that takes:
a. the WebotsDevice
b. an optional object that implements a newWebotsDeviceFieldGetterinterface, which can be used to access the Webots' device's fields. Default to a simple implementation that uses the controller'sSupervisor.
c. optional objects that implement newWPIDeviceInitNotifier<T>interfaces, which can be used to register to get notified of the initialization of any*Simobjects that the mediator might need. The initialized*Simobject itself should be passed to the callback that is registered. Default to simple wrapper objects that use the static*Sim.registerStaticInitializedCallback()methods. Those wrapper objects should probably be static members of the associated*Simclasses. - upon creation (i.e. in the constructor):
a. Use the field getter object to parse the Webots device's config info from it's fields.
b. Use the config info and the notifier objects to get notified when the the relevant*Simobject(s) are initialized. - Implement
Runnablewith arunmethod that, once all needed*Simobjects have been initialized, performs the device-specific mediation between the webotsDeviceand*Simobjects. This may involve use of additional config info (e.g. gearmotor reduction ratio, or encoder resolution). - Optionally, once all needed
*Simobjects have been initialized, register callbacks on the*Simobjects to get notified of state changes and propagate them to the webotsDevice.
Activity
[-]Create a proxy object (Mock*) for each Device at startup[/-][+]Create an adapter object (Mock*) for each Device at startup[/+][-]Create an adapter object (Mock*) for each Device at startup[/-][+]Create a mediator object (currently Mock*) for each Device at startup[/+]fix #24 and #25, and start #26
fix #24 and #25, and start #26