-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLight.java
More file actions
74 lines (62 loc) · 1.92 KB
/
Light.java
File metadata and controls
74 lines (62 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.easternedgerobotics.rov.io;
import com.easternedgerobotics.rov.io.devices.PWM;
import com.easternedgerobotics.rov.value.SpeedValue;
import rx.Observable;
public class Light {
/**
* Max forward PWM signal value (in μs) for the connected to lighting controller.
*/
public static final float MAX_FWD = 2000;
/**
* Max reverse used to center the stop period at 0%.
*/
public static final float MAX_REV = 1000;
/**
* Flashing period for the lights.
*/
private static final float PERIOD = 600;
/**
* Flashing max intensity for the lights.
*/
private static final float AMPLITUDE = .3f;
/**
* The output PWM device to write speeds.
*/
private final PWM device;
/**
* The latest value from the speed observable.
*/
private SpeedValue value;
/**
* Create a Lighting device which uses a pololu channel for communication.
* The Min and Max SpeedValue value for this device is 0 and 1 respectively.
*
* @param values speed observable mapped to the pololu channel
* @param device PWM output to write speeds
*/
public Light(final Observable<SpeedValue> values, final PWM device) {
this.device = device;
values.subscribe(v -> value = v);
}
/**
* Write the latest {@code SpeedValue} for this light.
*/
public final void write() {
if (value.getSpeed() < 0 || value.getSpeed() > 1) {
throw new IllegalArgumentException("Light channel values must be between 0 and 1");
}
device.write(value.getSpeed());
}
/**
* Write zero to the light.
*/
public final void writeZero() {
device.writeZero();
}
/**
* Write the default flashing light values.
*/
public final void flash() {
device.write((float) (AMPLITUDE * (1 - Math.sin(2 * Math.PI / PERIOD * System.currentTimeMillis()))));
}
}