66import com .easternedgerobotics .rov .control .SixThrusterConfig ;
77import com .easternedgerobotics .rov .event .BroadcastEventPublisher ;
88import com .easternedgerobotics .rov .event .EventPublisher ;
9- import com .easternedgerobotics .rov .io .ADC ;
10- import com .easternedgerobotics .rov .io .Accelerometer ;
11- import com .easternedgerobotics .rov .io .Barometer ;
12- import com .easternedgerobotics .rov .io .Bluetooth ;
9+ import com .easternedgerobotics .rov .io .Bar30PressureSensor ;
1310import com .easternedgerobotics .rov .io .BluetoothReader ;
14- import com .easternedgerobotics .rov .io .CpuInformation ;
15- import com .easternedgerobotics .rov .io .Gyroscope ;
1611import com .easternedgerobotics .rov .io .Light ;
17- import com .easternedgerobotics .rov .io .Magnetometer ;
1812import com .easternedgerobotics .rov .io .Motor ;
19- import com .easternedgerobotics .rov .io .PWM ;
20- import com .easternedgerobotics .rov .io .Thermometer ;
2113import com .easternedgerobotics .rov .io .Thruster ;
14+ import com .easternedgerobotics .rov .io .devices .ADC ;
15+ import com .easternedgerobotics .rov .io .devices .Accelerometer ;
16+ import com .easternedgerobotics .rov .io .devices .Barometer ;
17+ import com .easternedgerobotics .rov .io .devices .Bluetooth ;
18+ import com .easternedgerobotics .rov .io .devices .Gyroscope ;
19+ import com .easternedgerobotics .rov .io .devices .I2C ;
20+ import com .easternedgerobotics .rov .io .devices .Magnetometer ;
21+ import com .easternedgerobotics .rov .io .devices .PWM ;
22+ import com .easternedgerobotics .rov .io .devices .Thermometer ;
2223import com .easternedgerobotics .rov .io .pololu .AltIMU10v3 ;
2324import com .easternedgerobotics .rov .io .pololu .Maestro ;
24- import com .easternedgerobotics .rov .io .pololu .PololuBus ;
25+ import com .easternedgerobotics .rov .io .rpi .RaspberryCpuInformation ;
26+ import com .easternedgerobotics .rov .io .rpi .RaspberryI2CBus ;
2527import com .easternedgerobotics .rov .math .Range ;
2628import com .easternedgerobotics .rov .value .CameraSpeedValueA ;
2729import com .easternedgerobotics .rov .value .CameraSpeedValueB ;
@@ -82,9 +84,13 @@ final class Rov {
8284
8385 private final Accelerometer accelerometer ;
8486
85- private final Barometer barometer ;
87+ private final Barometer internalBarometer ;
8688
87- private final Thermometer thermometer ;
89+ private final Thermometer internalThermometer ;
90+
91+ private final Barometer externalBarometer ;
92+
93+ private final Thermometer externalThermometer ;
8894
8995 private final Gyroscope gyroscope ;
9096
@@ -99,10 +105,12 @@ final class Rov {
99105 private final Subject <Void , Void > killSwitch = PublishSubject .create ();
100106
101107 <AltIMU extends Accelerometer & Barometer & Thermometer & Gyroscope & Magnetometer ,
108+ PressureSensor extends Barometer & Thermometer ,
102109 MaestroChannel extends ADC & PWM > Rov (
103110 final EventPublisher eventPublisher ,
104111 final List <MaestroChannel > channels ,
105112 final AltIMU imu ,
113+ final PressureSensor externalPressure ,
106114 final Bluetooth bluetooth ,
107115 final RovConfig rovConfig
108116 ) {
@@ -216,11 +224,14 @@ MaestroChannel extends ADC & PWM> Rov(
216224 channels .get (config .lightBChannel ()).setOutputRange (new Range (Light .MAX_REV , Light .MAX_FWD )))
217225 ));
218226
219- barometer = () -> imu .pressure ();
227+ internalBarometer = () -> imu .pressure ();
220228 magnetometer = () -> imu .rotation ();
221229 accelerometer = () -> imu .acceleration ();
222230 gyroscope = () -> imu .angularVelocity ();
223- thermometer = () -> imu .temperature ();
231+ internalThermometer = () -> imu .temperature ();
232+
233+ externalBarometer = () -> externalPressure .pressure ();
234+ externalThermometer = () -> externalPressure .temperature ();
224235
225236 this .bluetooth = bluetooth ;
226237 }
@@ -253,7 +264,7 @@ void shutdown() {
253264 */
254265 void init (final Scheduler io , final Scheduler sensorRead , final Scheduler clock ) {
255266 Logger .debug ("Wiring up heartbeat, timeout, and thruster updates" );
256- final CpuInformation cpuInformation = new CpuInformation (
267+ final RaspberryCpuInformation cpuInformation = new RaspberryCpuInformation (
257268 RasprimeCpuValue ::new , config .cpuPollInterval (), TimeUnit .SECONDS );
258269 cpuInformation .observe ().subscribe (eventPublisher ::emit , Logger ::error );
259270
@@ -279,18 +290,18 @@ void init(final Scheduler io, final Scheduler sensorRead, final Scheduler clock)
279290
280291 thrusters .forEach (Thruster ::writeZero );
281292
282- // Temporarily commented section to prevent logs overflowing. FIX ME!!!
283-
284293 final Observable <Long > sensorInterval = Observable .interval (
285294 config .sensorPollInterval (),
286295 TimeUnit .MILLISECONDS ,
287296 sensorRead );
288297 sensorInterval .subscribe (tick -> {
289- eventPublisher .emit (barometer .pressure ());
298+ eventPublisher .emit (internalBarometer .pressure ());
290299 eventPublisher .emit (accelerometer .acceleration ());
291300 eventPublisher .emit (gyroscope .angularVelocity ());
292301 eventPublisher .emit (magnetometer .rotation ());
293- eventPublisher .emit (thermometer .temperature ());
302+ eventPublisher .emit (internalThermometer .temperature ());
303+ eventPublisher .emit (externalBarometer .pressure ());
304+ eventPublisher .emit (externalThermometer .temperature ());
294305 });
295306
296307 bluetooth .start (eventPublisher );
@@ -338,14 +349,14 @@ private void onCompleted() {
338349 public static void main (final String [] args ) throws InterruptedException , IOException {
339350 final String app = "rov" ;
340351 final HelpFormatter formatter = new HelpFormatter ();
341- final Option defaultConfig = Option .builder ("d" )
352+ final Option defaultConfigOption = Option .builder ("d" )
342353 .longOpt ("default" )
343354 .hasArg ()
344355 .argName ("DEFAULT" )
345356 .desc ("name of the default config file" )
346357 .required ()
347358 .build ();
348- final Option config = Option .builder ("c" )
359+ final Option configOption = Option .builder ("c" )
349360 .longOpt ("config" )
350361 .hasArg ()
351362 .argName ("CONFIG" )
@@ -354,44 +365,51 @@ public static void main(final String[] args) throws InterruptedException, IOExce
354365 .build ();
355366
356367 final Options options = new Options ();
357- options .addOption (defaultConfig );
358- options .addOption (config );
368+ options .addOption (defaultConfigOption );
369+ options .addOption (configOption );
359370
360371 try {
361372 final CommandLineParser parser = new DefaultParser ();
362373 final CommandLine arguments = parser .parse (options , args );
363374
364- final LaunchConfig launchConfig = new Config (
365- arguments .getOptionValue ("d" ),
366- arguments .getOptionValue ("c" )
367- ).getConfig ("launch" , LaunchConfig .class );
375+ final Config config = new Config (arguments .getOptionValue ("d" ), arguments .getOptionValue ("c" ));
376+ final LaunchConfig launchConfig = config .getConfig ("launch" , LaunchConfig .class );
377+ final RovConfig rovConfig = config .getConfig ("rov" , RovConfig .class );
368378
369379 final InetAddress broadcastAddress = InetAddress .getByName (launchConfig .broadcast ());
370380 final int broadcastPort = launchConfig .defaultBroadcastPort ();
371381 final DatagramSocket socket = new DatagramSocket (broadcastPort );
372382 final EventPublisher eventPublisher = new BroadcastEventPublisher (new UdpBroadcast <>(
373383 socket , broadcastAddress , broadcastPort , new BasicOrder <>()));
384+
374385 final Serial serial = SerialFactory .createInstance ();
375- final RovConfig rovConfig = new Config (
376- arguments . getOptionValue ( "d" ),
377- arguments . getOptionValue ( "c" )
378- ). getConfig ( "rov" , RovConfig . class );
386+ final List < I2C > i2cBus = new RaspberryI2CBus ( rovConfig . i2cBus ());
387+
388+ final Scheduler sensorRead = Schedulers . newThread ();
389+
379390 final Rov rov = new Rov (
380391 eventPublisher ,
381- new Maestro <>(serial , rovConfig .maestroDeviceNumber ()),
382- new AltIMU10v3 (new PololuBus (rovConfig .i2cBus ()), rovConfig .altImuSa0High ()),
392+ new Maestro <>(
393+ serial ,
394+ rovConfig .maestroDeviceNumber ()),
395+ new AltIMU10v3 (
396+ i2cBus ,
397+ rovConfig .altImuSa0High ()),
398+ new Bar30PressureSensor (
399+ i2cBus .get (Bar30PressureSensor .ADDRESS ),
400+ sensorRead ,
401+ rovConfig .pressureSensorConvertTime ()),
383402 new BluetoothReader (
384403 rovConfig .bluetoothComPortName (),
385404 rovConfig .bluetoothComPort (),
386405 rovConfig .bluetoothConnectionTimeout (),
387- rovConfig .bluetoothBaudRate ()
388- ),
406+ rovConfig .bluetoothBaudRate ()),
389407 rovConfig );
390408
391409 Runtime .getRuntime ().addShutdownHook (new Thread (rov ::shutdown ));
392410
393411 serial .open (launchConfig .serialPort (), launchConfig .baudRate ());
394- rov .init (Schedulers .io (), Schedulers . newThread () , Schedulers .computation ());
412+ rov .init (Schedulers .io (), sensorRead , Schedulers .computation ());
395413
396414 Logger .info ("Started" );
397415 eventPublisher .await ();
0 commit comments