3a7e2563268e796c2a685ded9bb2819a8cfd5d77
[des2015.git] / mart / ev3 / ex2 / nl / ru / des / Main.java
1 package nl.ru.des;
2
3 import lejos.hardware.ev3.EV3;
4 import lejos.hardware.ev3.LocalEV3;
5 import lejos.hardware.lcd.Font;
6 import lejos.hardware.motor.EV3LargeRegulatedMotor;
7 import lejos.hardware.port.MotorPort;
8 import lejos.hardware.sensor.EV3ColorSensor;
9 import lejos.robotics.subsumption.Arbitrator;
10 import lejos.robotics.subsumption.Behavior;
11
12 public class Main {
13 public static Arbitrator arbitrator;
14
15 public static void main(String[] args) {
16 EV3 brick = LocalEV3.get();
17 LCDPrinter lcdprinter = new LCDPrinter(brick.getGraphicsLCD(), Font.getSmallFont());
18 lcdprinter.start();
19 /*
20 * Start the slave first. "Socket is 18" is always displayed, we can just ignore this
21 */
22 ColorMemory mh = new ColorMemory();
23
24 //BTController btController = BTController.getBTMaster("Rover2", mh); // Master
25 BTController btController = BTController.getBTSlave(mh); // Slave
26 btController.start();
27 BTController.SendMessage("Hi");
28
29 LCDPrinter.print("Robots are connected");
30
31 LCDPrinter.print("Starting up systems");
32
33
34 LCDPrinter.print("Loading keylistener...");
35 brick.getKey("Escape").addKeyListener(new ButtonListener());
36
37 LCDPrinter.print("Loading motors...");
38 EV3LargeRegulatedMotor rightMotor = new EV3LargeRegulatedMotor(MotorPort.D);
39 EV3LargeRegulatedMotor leftMotor = new EV3LargeRegulatedMotor(MotorPort.A);
40 leftMotor.setSpeed(200);
41 rightMotor.setSpeed(200);
42 rightMotor.setAcceleration(1000);
43 leftMotor.setAcceleration(1000);
44
45 // LCDPrinter.print("Loading touch sensors...");
46 // EV3TouchSensor leftTouch = new EV3TouchSensor(brick.getPort("S1"));
47 // EV3TouchSensor rightTouch = new EV3TouchSensor(brick.getPort("S4"));
48 LCDPrinter.print("Loading color sensor...");
49 EV3ColorSensor colorSensor = new EV3ColorSensor(brick.getPort("S2"));
50 ColorSensor colorSensorObject = new ColorSensor(colorSensor);
51
52 // LCDPrinter.print("Loading ultrasone sensor...");
53 // EV3UltrasonicSensor ultraSensor = new EV3UltrasonicSensor(brick.getPort("S3"));
54
55 LCDPrinter.print("Initializing behaviours...");
56 Behavior[] behaviorList = new Behavior[] {
57 new WandererBehaviour(colorSensorObject, leftMotor, rightMotor, mh),
58 new StayInFieldBehaviour(colorSensorObject, leftMotor, rightMotor)
59 //new CommBehaviour(leftMotor, rightMotor)
60 };
61
62 LCDPrinter.print("Initializing arbitrator...");
63 Main.arbitrator = new Arbitrator(behaviorList);
64 Main.arbitrator.start();
65 LCDPrinter.print("Takeoff!");
66 colorSensor.close();
67 // ultraSensor.close();
68 }
69 }