This repository has been archived by the owner on Apr 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.java
64 lines (52 loc) · 1.87 KB
/
Core.java
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
package core;
import java.io.IOException;
import behaviours.Collision;
import behaviours.Drive;
import behaviours.GyroReset;
import behaviours.Scan;
import behaviours.Stop;
import lejos.hardware.Button;
import lejos.robotics.subsumption.Arbitrator;
import lejos.robotics.subsumption.Behavior;
import network.Server;
public class Core {
// Constants
public static final int MONITOR_DELAY = 1000;
public static final int PORT = 1234;
/**
* Execution start point of the Ev3 Brick program.
* Initialises:
* - Robot, Monitor, Server and Arbitrator instances
* @param args
*/
public static void main(String[] args) {
Server server = null;
Robot robot = new Robot();
Monitor monitor = new Monitor(robot, MONITOR_DELAY);
robot.installMonitor(monitor);
try {
server = new Server(PORT, robot);
robot.installServer(server);
} catch (IOException e) {
e.printStackTrace();
}
// Set up the behaviours for the Arbitrator and construct it. (higher the index, higher the priority)
Behavior b4 = new Stop(robot);
Behavior b3 = new Collision(robot);
Behavior b2 = new Scan(robot);
Behavior b1 = new GyroReset(robot);
Behavior b0 = new Drive(robot);
Behavior [] bArray = {b0, b1, b2, b3, b4};
Arbitrator arby = new Arbitrator(bArray);
// Clear arbitrator spew
for (int i=0; i<8; i++)
System.out.println("");
// Wait for the user to press start
monitor.print("Press Start!");
Button.waitForAnyPress();
// Start the Pilot Monitor
monitor.start();
// Start the Arbitrator
arby.go();
}
}