Repository navigation
Expand file tree
/
Copy pathPilotProps.java
More file actions
71 lines (59 loc) · 1.93 KB
/
Copy pathPilotProps.java
File metadata and controls
71 lines (59 loc) · 1.93 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
package ev3dev.utils;
import ev3dev.actuators.lego.motors.Motor;
import lejos.robotics.RegulatedMotor;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* Configuration class for Differential Pilot.
*
* @author Lawrie Griffiths, Juan Antonio Breña Moral
*/
public class PilotProps extends Properties {
public static final String PERSISTENT_FILENAME = "pilot.props";
public static final String KEY_WHEELDIAMETER = "wheelDiameter";
public static final String KEY_TRACKWIDTH = "trackWidth";
public static final String KEY_LEFTMOTOR = "leftMotor";
public static final String KEY_RIGHTMOTOR = "rightMotor";
public static final String KEY_REVERSE = "reverse";
/**
* Method to load values from file
*
* @throws IOException Not found
*/
public void loadPersistentValues() throws IOException {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
try (InputStream resourceStream = loader.getResourceAsStream(PERSISTENT_FILENAME)) {
this.load(resourceStream);
}
}
/**
* Store values in the file
*
* @throws IOException Not found
*/
public void storePersistentValues() throws IOException {
try (FileOutputStream fos = new FileOutputStream(new File(PERSISTENT_FILENAME))) {
this.store(fos, null);
}
}
/**
* Utility method to get Motor instance from string (A, B or C)
*/
public static RegulatedMotor getMotor(String motor) {
if (motor.equals("A")) {
return Motor.A;
} else if (motor.equals("B")) {
return Motor.B;
} else if (motor.equals("C")) {
return Motor.C;
} else if (motor.equals("D")) {
return Motor.D;
} else {
//TODO Review this case.
return null;
}
}
}