You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 constructor that takes:
a. the Webots Device
b. an optional object that implements a new WebotsDeviceFieldGetter interface, which can be used to access the Webots' device's fields. Default to a simple implementation that uses the controller's Supervisor.
c. optional objects that implement new WPIDeviceInitNotifier<T> interfaces, which can be used to register to get notified of the initialization of any *Sim objects that the mediator might need. The initialized *Sim object 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 *Sim classes.
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 *Sim object(s) are initialized.
Implement Runnable with a run method that, once all needed *Sim objects have been initialized, performs the device-specific mediation between the webots Device and *Sim objects. This may involve use of additional config info (e.g. gearmotor reduction ratio, or encoder resolution).
Optionally, once all needed *Sim objects have been initialized, register callbacks on the *Sim objects to get notified of state changes and propagate them to the webots Device.
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, andMockedEncoderall 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:<Device>Mediatorwhere<Device>is the name of the corresponding Webots device (typically a PROTO defined in Create PROTOs corresponding to common FRC parts #24).a. the Webots
Deviceb. an optional object that implements a new
WebotsDeviceFieldGetterinterface, 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 new
WPIDeviceInitNotifier<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.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.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).*Simobjects have been initialized, register callbacks on the*Simobjects to get notified of state changes and propagate them to the webotsDevice.