3 import lejos
.hardware
.Button
;
4 import lejos
.hardware
.ev3
.EV3
;
5 import lejos
.hardware
.ev3
.LocalEV3
;
6 import lejos
.hardware
.lcd
.Font
;
7 import lejos
.hardware
.lcd
.TextLCD
;
8 import lejos
.hardware
.motor
.EV3LargeRegulatedMotor
;
9 import lejos
.hardware
.port
.MotorPort
;
10 import lejos
.hardware
.sensor
.EV3ColorSensor
;
11 import lejos
.hardware
.sensor
.EV3TouchSensor
;
12 import lejos
.hardware
.sensor
.EV3UltrasonicSensor
;
13 import lejos
.robotics
.subsumption
.Arbitrator
;
14 import lejos
.robotics
.subsumption
.Behavior
;
15 import nl
.ru
.des
.behaviours
.AvoidHighObjectBehaviour
;
16 import nl
.ru
.des
.behaviours
.AvoidLowObjectBehaviour
;
17 import nl
.ru
.des
.behaviours
.ShutdownBehaviour
;
18 import nl
.ru
.des
.behaviours
.StayInFieldBehaviour
;
19 import nl
.ru
.des
.behaviours
.WandererBehaviour
;
20 import nl
.ru
.des
.bluetooth
.BTController
;
21 import nl
.ru
.des
.bluetooth
.ColorMemory
;
22 import nl
.ru
.des
.sensors
.ColorSensor
;
23 import nl
.ru
.des
.sensors
.TouchSensor
;
24 import nl
.ru
.des
.sensors
.UltraSoneSensor
;
27 public static Arbitrator arbitrator
;
29 public static void main(String
[] args
) {
30 EV3 brick
= LocalEV3
.get();
31 TextLCD tlcd
= brick
.getTextLCD(Font
.getSmallFont());
32 LCDPrinter
.startLCDPrinter(tlcd
);
33 System
.setOut(LCDPrinter
.getPrefixedPrintstream("out: ", tlcd
));
34 System
.setErr(LCDPrinter
.getPrefixedPrintstream("err: ", tlcd
));
36 ColorMemory mh
= new ColorMemory();
38 LCDPrinter
.print("Loading keylistener...");
39 brick
.getKey("Escape").addKeyListener(new ButtonListener());
41 BTController btController
;
42 LCDPrinter
.print("Trying to pair");
43 btController
= BTController
.getBTMaster("Rover1", mh
); // Master
44 //btController = BTController.getBTSlave(mh); // Slave
47 LCDPrinter
.print("Robots are connected");
49 LCDPrinter
.print("Loading motors...");
50 EV3LargeRegulatedMotor rightMotor
= new EV3LargeRegulatedMotor(MotorPort
.D
);
51 EV3LargeRegulatedMotor leftMotor
= new EV3LargeRegulatedMotor(MotorPort
.A
);
52 leftMotor
.setSpeed(200);
53 rightMotor
.setSpeed(200);
54 rightMotor
.setAcceleration(1000);
55 leftMotor
.setAcceleration(1000);
57 LCDPrinter
.print("Loading touch sensors...");
58 TouchSensor leftTouchSensor
= new TouchSensor(new EV3TouchSensor(brick
.getPort("S1")));
59 TouchSensor rightTouchSensor
= new TouchSensor(new EV3TouchSensor(brick
.getPort("S4")));
60 LCDPrinter
.print("Loading color sensor...");
61 ColorSensor colorSensorObject
= new ColorSensor(new EV3ColorSensor(brick
.getPort("S2")));
63 LCDPrinter
.print("Loading ultrasone sensor...");
64 UltraSoneSensor ultraSoneSensor
= new UltraSoneSensor(new EV3UltrasonicSensor(brick
.getPort("S3")));
66 LCDPrinter
.print("Initializing behaviours...");
67 Behavior
[] behaviorList
= new Behavior
[] {
68 new WandererBehaviour(colorSensorObject
, leftMotor
, rightMotor
, mh
),
69 new StayInFieldBehaviour(colorSensorObject
, leftMotor
, rightMotor
),
70 new AvoidLowObjectBehaviour(leftMotor
, rightMotor
, leftTouchSensor
, rightTouchSensor
),
71 new AvoidHighObjectBehaviour(leftMotor
, rightMotor
, ultraSoneSensor
),
72 new ShutdownBehaviour(mh
)
75 LCDPrinter
.print("Initializing arbitrator...");
76 Main
.arbitrator
= new Arbitrator(behaviorList
);
77 LCDPrinter
.print("Press any button for takeoff!");
78 Button
.waitForAnyPress();
79 Main
.arbitrator
.start();
80 LCDPrinter
.print("Finish");