Skip to content

Conversation

@cal-pratt
Copy link
Contributor

This PR is built upon #255 ; once that PR is finished this branch will be rebased

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 DataMediation class which can control when consumers accept values. DataMediation 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/idle state when inactive.

The two major methods in DataMediation are:

<Param, Source extends Param> DataMediation mediate(
    final Supplier<Source> supplier,
    final Consumer<Param> consumer);

<Param, Source extends Param> DataMediation mediate(
    final Observable<Source> source,
    final Source idle,
    final Consumer<Param> consumer);

The first method polls a Supplier for a value and passes it to a Consumer. The second method is similar however, it polls an Observable. When the DataMediation is idle it passes the idle value to the Consumer. Here's an example for mediating when the thrusters get updated:

final DataMediation mediation = new DataMediation(SLEEP_DURATION, TimeUnit.MILLISECONDS, io);
final Range range = new Range(Thruster.MAX_REV, Thruster.MAX_FWD);
mediation 
    .mediate(eventPublisher.valuesOfType(PortAftSpeedValue.class), new PortAftSpeedValue(),
        new Thruster(channels.get(PORT_AFT_CHANNEL).setOutputRange(range))::apply)
    .mediate(eventPublisher.valuesOfType(StarboardAftSpeedValue.class), new StarboardAftSpeedValue(),
        new Thruster(channels.get(STARBOARD_AFT_CHANNEL).setOutputRange(range))::apply)
...
mediation.setActive();

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. DataMediation supplies an initial values to the devices using the standard method.

@cal-pratt
Copy link
Contributor Author

I want to re-think this design a bit. Going to close the pr for now and open again later after config #270 changes have been made.

@cal-pratt cal-pratt closed this Mar 4, 2017
@cal-pratt cal-pratt deleted the data-mediation branch May 14, 2017 20:00
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