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
.SampleProvider
;
14 import lejos
.robotics
.filter
.ConcatenationFilter
;
15 import lejos
.robotics
.subsumption
.Arbitrator
;
16 import lejos
.robotics
.subsumption
.Behavior
;
17 import nl
.ru
.des
.behaviours
.AvoidHighObjectBehaviour
;
18 import nl
.ru
.des
.behaviours
.AvoidLowObjectBehaviour
;
19 import nl
.ru
.des
.behaviours
.ShutdownBehaviour
;
20 import nl
.ru
.des
.behaviours
.StayInFieldBehaviour
;
21 import nl
.ru
.des
.behaviours
.WandererBehaviour
;
22 import nl
.ru
.des
.bluetooth
.BTController
;
23 import nl
.ru
.des
.bluetooth
.ColorMemory
;
25 public class MarsRover
{
26 public static final float SAMPLERATE
= 100;
28 @SuppressWarnings("resource")
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 final ColorMemory mh
= new ColorMemory();
38 LCDPrinter
.print("Place the robots in front of each other and press any key");
39 Button
.waitForAnyPress();
41 LCDPrinter
.print("Trying to pair");
42 BTController btController
;
43 //btController = BTController.getBTMaster("Rover1", mh); // Master
44 btController
= BTController
.getBTSlave(mh
); // Slave
47 LCDPrinter
.print("Loading keylistener...");
48 brick
.getKey("Escape").addKeyListener(new ButtonListener());
50 LCDPrinter
.print("Loading motors...");
51 EV3LargeRegulatedMotor rightMotor
= new EV3LargeRegulatedMotor(MotorPort
.D
);
52 EV3LargeRegulatedMotor leftMotor
= new EV3LargeRegulatedMotor(MotorPort
.A
);
53 leftMotor
.setSpeed(300);
54 rightMotor
.setSpeed(300);
55 rightMotor
.setAcceleration(1000);
56 leftMotor
.setAcceleration(1000);
58 LCDPrinter
.print("Loading touch sensors...");
59 SampleProvider touch
= new ConcatenationFilter(
60 new EV3TouchSensor(brick
.getPort("S1")).getTouchMode(),
61 new EV3TouchSensor(brick
.getPort("S4")).getTouchMode());
62 LCDPrinter
.print("Loading color sensor...");
63 SampleProvider color
= new EV3ColorSensor(brick
.getPort("S2")).getColorIDMode();
65 LCDPrinter
.print("Loading ultrasone sensor...");
66 SampleProvider ultraSonic
= new EV3UltrasonicSensor(brick
.getPort("S3")).getDistanceMode();
68 LCDPrinter
.print("Initializing behaviours...");
69 Behavior
[] behaviorList
= new Behavior
[] {
70 new WandererBehaviour(color
, leftMotor
, rightMotor
, mh
),
71 new AvoidLowObjectBehaviour(leftMotor
, rightMotor
, touch
),
72 new AvoidHighObjectBehaviour(leftMotor
, rightMotor
, ultraSonic
),
73 new StayInFieldBehaviour(color
, leftMotor
, rightMotor
),
74 new ShutdownBehaviour(mh
)
77 Arbitrator arbitrator
= new Arbitrator(behaviorList
);