Made the robot connected
[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.lcd.LCD;
7 import lejos.hardware.motor.EV3LargeRegulatedMotor;
8 import lejos.hardware.port.MotorPort;
9 import lejos.hardware.sensor.EV3ColorSensor;
10 import lejos.robotics.subsumption.Arbitrator;
11 import lejos.robotics.subsumption.Behavior;
12
13 public class Main {
14 public static Arbitrator arbitrator;
15
16 public static void main(String[] args) {
17 EV3 brick = LocalEV3.get();
18 LCDPrinter lcdprinter = new LCDPrinter(brick.getGraphicsLCD(), Font.getSmallFont());
19
20 /*
21 * Start the slave first. "Socket is 18" is always displayed, we can just ignore this
22 */
23 //BTMemory.getBTMemory(false, "Rover2");
24 BTMemory.getBTMemory(true, "Rover1");
25 LCDPrinter.print("Robots are connected");
26
27 LCDPrinter.print("Starting up systems");
28 lcdprinter.start();
29
30 LCDPrinter.print("Loading keylistener...");
31 brick.getKey("Escape").addKeyListener(new ButtonListener());
32
33 LCDPrinter.print("Loading motors...");
34 EV3LargeRegulatedMotor rightMotor = new EV3LargeRegulatedMotor(MotorPort.D);
35 EV3LargeRegulatedMotor leftMotor = new EV3LargeRegulatedMotor(MotorPort.A);
36 leftMotor.setSpeed(200);
37 rightMotor.setSpeed(200);
38 rightMotor.setAcceleration(1000);
39 leftMotor.setAcceleration(1000);
40
41 // LCDPrinter.print("Loading touch sensors...");
42 // EV3TouchSensor leftTouch = new EV3TouchSensor(brick.getPort("S1"));
43 // EV3TouchSensor rightTouch = new EV3TouchSensor(brick.getPort("S4"));
44 LCDPrinter.print("Loading color sensor...");
45 EV3ColorSensor colorSensor = new EV3ColorSensor(brick.getPort("S2"));
46 ColorSensor colorSensorObject = new ColorSensor(colorSensor);
47
48 // LCDPrinter.print("Loading ultrasone sensor...");
49 // EV3UltrasonicSensor ultraSensor = new EV3UltrasonicSensor(brick.getPort("S3"));
50
51 LCDPrinter.print("Initializing behaviours...");
52 Behavior[] behaviorList = new Behavior[] {
53 new WandererBehaviour(colorSensorObject, leftMotor, rightMotor),
54 new StayInFieldBehaviour(colorSensorObject, leftMotor, rightMotor)
55 };
56
57
58 LCDPrinter.print("Initializing arbitrator...");
59 Main.arbitrator = new Arbitrator(behaviorList);
60 Main.arbitrator.start();
61 LCDPrinter.print("Takeoff!");
62 colorSensor.close();
63 // ultraSensor.close();
64 }
65 }