Skip to content

Conversation

@cal-pratt
Copy link
Contributor

@cal-pratt cal-pratt commented Jan 25, 2017

This PR is built upon #255 ; once that PR is finished this branch will be rebased (and also a better commits history will be made).

Reasoning:
Currently many of the io classes rely heavily on the EventPublisher. Realistically these devices should be simpler-- they either consume a value from an observable or create a value and emit it as an observable. Using an EventPublisher in each io device means that all of our tests become more complicated as we need to make a mock EventPublisher for each device test...
Further, the Rov class is responsible for handling the start/stop state of io devices. As we make more groups of items which run together (ie sensors on a different timer than thrusters), the granularity becomes harder to achieve.

Overview:
This PR intends to address these issues by creating a TaskManager class which can control how consumers accept values, how suppliers emit values, and when these tasks are active. TaskManager can:

  • accept many combinations of consumers/supplier pairs or observable/supplier pairs.
  • move data between consumers/supplier using an internal timer.
  • start and stop when data is being transferred.
  • set outputs to a constant/default state when inactive.

The two major methods in TaskManager are:

<Param, Source extends Param> TaskManager manage(
    final Supplier<Source> supplier,
    final Consumer<Param> consumer);

<Param, Source extends Param> TaskManager manage(
    final Observable<Source> source,
    final Source initial,
    final Consumer<Param> consumer);

The first method polls a Supplier for a value and passes it to a Consumer when the TaskManager is active. The second method is similar however, it polls an Observable and when the TaskManager is active, and when the TaskManager is stopped it passes the initial value to the Consumer. These methods return an instance of the TaskManager to enable method chaining which makes it pretty easy to instantiate and manage a device at the same time. Here's an example from the Rov ctor:

final TaskManager taskManager = new TaskManager(SLEEP_DURATION, TimeUnit.MILLISECONDS, io);
final SixThrusterConfig config = new SixThrusterConfig();
taskManager
    .manage(eventPublisher.valuesOfType(MotionValue.class), new MotionValue(),
        eventPublisher.valuesOfType(MotionPowerValue.class), new MotionPowerValue(),
        (m, mp) -> Arrays.stream(config.update(m, mp)).forEach(eventPublisher::emit));
...
final Range range = new Range(Thruster.MAX_REV, Thruster.MAX_FWD);
taskManager
    .manage(eventPublisher.valuesOfType(PortAftSpeedValue.class), new PortAftSpeedValue(),
        new Thruster(channels.get(PORT_AFT_CHANNEL).setOutputRange(range))::apply)
    .manage(eventPublisher.valuesOfType(StarboardAftSpeedValue.class), new StarboardAftSpeedValue(),
        new Thruster(channels.get(STARBOARD_AFT_CHANNEL).setOutputRange(range))::apply)
...
taskManager.start();

Notes:

  • There was a bug in TestEventPublisher.java where emitting objects casted as an interface would not result in the child class being recorded on the TestEventPublisher. eg:
    emit((SpeedValue)new PortAftSpeedValue()) would cause valuesOfType(PortAftSpeedValue.class) not to trigger. This is now fixed.
  • CpuInformation no longer causes non raspberry pi machines to crash
  • the writeZero methods in io classes such as Motor and Thruster have been removed. TaskManager supplies an initial values to the devices using the standard method.

@cal-pratt
Copy link
Contributor Author

Putting this on hold for now. Have to make some larger changes to imu.

@cal-pratt cal-pratt closed this Jan 27, 2017
@cal-pratt cal-pratt changed the title TaskManager for controlling io states DataMediaton for transferring data between a source and a consumer Jan 28, 2017
@cal-pratt cal-pratt changed the title DataMediaton for transferring data between a source and a consumer Task manager Jan 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants