f5aee01ca705562a5c689f6c3a6cdf6a9c7fd90d
[des2015.git] / dsl / runtime / src / nl / ru / des / MarsRover.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.TextLCD;
7 import lejos.hardware.motor.EV3LargeRegulatedMotor;
8 import lejos.hardware.port.MotorPort;
9 import lejos.hardware.sensor.EV3ColorSensor;
10 import lejos.hardware.sensor.EV3TouchSensor;
11 import lejos.hardware.sensor.EV3UltrasonicSensor;
12 import lejos.robotics.SampleProvider;
13
14 public class MarsRover {
15 public static final float SAMPLERATE = 100;
16
17 @SuppressWarnings("resource")
18 public static void main(String[] args) {
19 EV3 brick = LocalEV3.get();
20 TextLCD tlcd = brick.getTextLCD(Font.getSmallFont());
21 LCDPrinter.startLCDPrinter(tlcd);
22 System.setOut(LCDPrinter.getPrefixedPrintstream("out: ", tlcd));
23 System.setErr(LCDPrinter.getPrefixedPrintstream("err: ", tlcd));
24
25 LCDPrinter.print("Loading keylistener...");
26 brick.getKey("Escape").addKeyListener(new ButtonListener());
27
28 LCDPrinter.print("Loading motors...");
29 EV3LargeRegulatedMotor rightMotor = new EV3LargeRegulatedMotor(MotorPort.D);
30 EV3LargeRegulatedMotor leftMotor = new EV3LargeRegulatedMotor(MotorPort.A);
31 leftMotor.setSpeed(Constants.speed);
32 rightMotor.setSpeed(Constants.speed);
33 rightMotor.setAcceleration(Constants.acceleration);
34 leftMotor.setAcceleration(Constants.acceleration);
35
36 LCDPrinter.print("Loading touch sensors...");
37 SampleProvider leftTouch = new EV3TouchSensor(brick.getPort("S1")).getTouchMode();
38 SampleProvider rightTouch = new EV3TouchSensor(brick.getPort("S4")).getTouchMode();
39
40 LCDPrinter.print("Loading color sensor...");
41 SampleProvider color = new EV3ColorSensor(brick.getPort("S2")).getColorIDMode();
42
43 LCDPrinter.print("Loading ultrasone sensor...");
44 SampleProvider ultraSonic = new EV3UltrasonicSensor(brick.getPort("S3")).getDistanceMode();
45
46 LCDPrinter.print("Initializing behaviours...");
47 SensorCollector sensors = new SensorCollector(ultraSonic, color, leftTouch, rightTouch);
48 }
49 }