From: Mart Lubbers Date: Mon, 11 Jan 2016 11:21:38 +0000 (+0100) Subject: removed LCD class X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=8ac11d4775c780e307727b0e5dc865cf64517a59;p=des2015.git removed LCD class --- diff --git a/dsl/runtime/specs/wander.tdsl b/dsl/runtime/specs/wander.tdsl index 30081c8..bcf2f3b 100644 --- a/dsl/runtime/specs/wander.tdsl +++ b/dsl/runtime/specs/wander.tdsl @@ -67,20 +67,12 @@ Behaviour PushL action: right motor forward left motor backward - /*wait 500 ms - right motor forward - left motor forward - wait 500ms*/ Behaviour PushR take control: Touched on right action: left motor forward right motor backward - /*wait 500 ms - right motor forward - left motor forward - wait 1000 ms*/ Behaviour PushB take control: (&& Touched on left Touched on right) @@ -88,20 +80,19 @@ Behaviour PushB set flag Pushing left motor forward right motor forward - wait 10000 ms + wait forever Behaviour StopPushing take control: (&& not Touched on left not Touched on right flag set Pushing) action: set flag Pushed -/*Mission FindAndMeasureLakes +Mission FindAndMeasureLakes using Wander StayInFieldR StayInFieldL StayInFieldB GreenLake RedLake BlueLake and stops when (&& flag set GreenLake flag set RedLake flag set BlueLake) - Mission FindAndMeasureRocks using Wander StayInFieldR StayInFieldL StayInFieldB MeasureRock - and stops when flag set Measured */ + and stops when flag set Measured Mission PushRocks using Wander PushL PushR PushB StopPushing StayInFieldR StayInFieldL StayInFieldB and stops when flag set Pushed \ No newline at end of file diff --git a/dsl/runtime/src/nl/ru/des/BasicBehaviour.java b/dsl/runtime/src/nl/ru/des/BasicBehaviour.java index 455cbe2..b5d4bc1 100644 --- a/dsl/runtime/src/nl/ru/des/BasicBehaviour.java +++ b/dsl/runtime/src/nl/ru/des/BasicBehaviour.java @@ -110,7 +110,7 @@ public abstract class BasicBehaviour implements Behavior{ } rightMotor.stop(true); leftMotor.stop(true); - LCDPrinter.print(Float.toString(sensors.gyro())); + System.out.println(Float.toString(sensors.gyro())); } protected void leftTurn(int angle){ @@ -124,7 +124,7 @@ public abstract class BasicBehaviour implements Behavior{ } rightMotor.stop(true); leftMotor.stop(true); - LCDPrinter.print(Float.toString(sensors.gyro())); + System.out.println(Float.toString(sensors.gyro())); } @Override diff --git a/dsl/runtime/src/nl/ru/des/ButtonListener.java b/dsl/runtime/src/nl/ru/des/ButtonListener.java index 29df1ac..69d42fe 100644 --- a/dsl/runtime/src/nl/ru/des/ButtonListener.java +++ b/dsl/runtime/src/nl/ru/des/ButtonListener.java @@ -7,7 +7,7 @@ class ButtonListener implements KeyListener { @Override public void keyPressed(Key k) { - LCDPrinter.print("Bye"); + System.out.println("Bye"); System.exit(0); } diff --git a/dsl/runtime/src/nl/ru/des/LCDPrinter.java b/dsl/runtime/src/nl/ru/des/LCDPrinter.java deleted file mode 100644 index c041f4d..0000000 --- a/dsl/runtime/src/nl/ru/des/LCDPrinter.java +++ /dev/null @@ -1,76 +0,0 @@ -package nl.ru.des; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.Deque; -import java.util.LinkedList; - -import lejos.hardware.lcd.TextLCD; -import lejos.utility.Delay; - -public class LCDPrinter{ - public static final int PRINTDELAY = 50; - - private static class Message{ - public String msg; - public boolean nl; - - public Message(String msg, boolean nl){ - this.msg = msg; - this.nl = nl; - } - } - - private static Deque buffer = new LinkedList(); - - public static void startLCDPrinter(final TextLCD glcd) { - new Thread(new Runnable(){ - @Override - public void run() { - while (true) { - if (!buffer.isEmpty()) { - Message c = buffer.remove(); - if(c.msg.length() > glcd.getTextWidth()){ - buffer.addFirst(new Message(c.msg.substring(glcd.getTextWidth(), c.msg.length()), c.nl)); - c.msg = c.msg.substring(0, glcd.getTextWidth()); - } - if(c.nl){ - glcd.scroll(); - } else { - glcd.clear(glcd.getTextHeight()-1); - } - glcd.drawString(c.msg, 0, glcd.getTextHeight()-1); - } - Delay.msDelay(PRINTDELAY); - } - } - }).start(); - LCDPrinter.print("LCDThread started"); - } - - public static void print(String s){ - print(s, true); - } - - public synchronized static void print(String s, boolean nl){ - buffer.addLast(new Message(s, nl)); - } - - public static PrintStream getPrefixedPrintstream(final String prefix, final TextLCD glcd){ - return new PrintStream(new OutputStream(){ - private char[] line = new char[glcd.getTextWidth()]; - private int index = 0; - - @Override - public void write(int b) throws IOException { - if(index == line.length-prefix.length() || b == '\n'){ - LCDPrinter.print(prefix + String.valueOf(line, 0, index)); - index = 0; - } else { - line[index++] = (char)b; - } - } - }); - } -} \ No newline at end of file diff --git a/dsl/runtime/src/nl/ru/des/Marster.java b/dsl/runtime/src/nl/ru/des/Marster.java index 3684c0a..16dd328 100644 --- a/dsl/runtime/src/nl/ru/des/Marster.java +++ b/dsl/runtime/src/nl/ru/des/Marster.java @@ -1,5 +1,6 @@ package nl.ru.des; +import java.io.PrintStream; import java.util.LinkedList; import java.util.Random; @@ -8,7 +9,7 @@ import lejos.hardware.Sound; import lejos.hardware.ev3.EV3; import lejos.hardware.ev3.LocalEV3; import lejos.hardware.lcd.Font; -import lejos.hardware.lcd.TextLCD; +import lejos.hardware.lcd.LCDOutputStream; import lejos.hardware.motor.EV3LargeRegulatedMotor; import lejos.hardware.motor.EV3MediumRegulatedMotor; import lejos.hardware.port.MotorPort; @@ -30,25 +31,24 @@ public class Marster { @SuppressWarnings("resource") public static void main(String[] args) { EV3 brick = LocalEV3.get(); - TextLCD tlcd = brick.getTextLCD(Font.getSmallFont()); - LCDPrinter.startLCDPrinter(tlcd); - System.setOut(LCDPrinter.getPrefixedPrintstream("out: ", tlcd)); - System.setErr(LCDPrinter.getPrefixedPrintstream("err: ", tlcd)); + PrintStream lcd = new PrintStream(new LCDOutputStream(brick.getTextLCD(Font.getSmallFont()))); + System.setOut(lcd); + System.setErr(lcd); - LCDPrinter.print("Loading keylistener..."); + System.out.println("Loading keylistener..."); brick.getKey("Escape").addKeyListener(new ButtonListener()); if(brick.getName().equalsIgnoreCase("Rover6") || brick.getName().equalsIgnoreCase("Rover8")){ - LCDPrinter.print("Starting as a slave..."); - LCDPrinter.print("My name is " + brick.getName()); - LCDPrinter.print("Loading touch sensors..."); + System.out.println("Starting as a slave..."); + System.out.println("My name is " + brick.getName()); + System.out.println("Loading touch sensors..."); SampleProvider leftTouch = new EV3TouchSensor(brick.getPort("S1")).getTouchMode(); SampleProvider rightTouch = new EV3TouchSensor(brick.getPort("S2")).getTouchMode(); - LCDPrinter.print("Loading ultrasone sensor..."); + System.out.println("Loading ultrasone sensor..."); SampleProvider frontUltra = new EV3UltrasonicSensor(brick.getPort("S3")).getDistanceMode(); - LCDPrinter.print("Loading color sensors..."); + System.out.println("Loading color sensors..."); SampleProvider color = new EV3ColorSensor(brick.getPort("S4")).getColorIDMode(); RemoteSensors rs = new RemoteSensors(leftTouch, rightTouch, frontUltra, color); @@ -60,10 +60,10 @@ public class Marster { } } else { String slave = brick.getName().equalsIgnoreCase("Rover5") ? "Rover6" : "Rover8"; - LCDPrinter.print("Starting as as master..."); - LCDPrinter.print("My name is " + brick.getName()); - LCDPrinter.print("Going to connect to: " + slave); - LCDPrinter.print("Loading motors..."); + System.out.println("Starting as as master..."); + System.out.println("My name is " + brick.getName()); + System.out.println("Going to connect to: " + slave); + System.out.println("Loading motors..."); RegulatedMotor rightMotor = new EV3LargeRegulatedMotor(MotorPort.A); RegulatedMotor leftMotor = new EV3LargeRegulatedMotor(MotorPort.B); RegulatedMotor measMotor = new EV3MediumRegulatedMotor(MotorPort.C); @@ -72,32 +72,32 @@ public class Marster { measMotor.setSpeed(50); rightMotor.setAcceleration(Constants.acceleration); leftMotor.setAcceleration(Constants.acceleration); - measMotor.setAcceleration(100); + measMotor.setAcceleration(50); - LCDPrinter.print("Loading touch sensors..."); + System.out.println("Loading touch sensors..."); SampleProvider leftLight = new NXTLightSensor(brick.getPort("S1")).getRedMode(); SampleProvider rightLight = new NXTLightSensor(brick.getPort("S2")).getRedMode(); - LCDPrinter.print("Loading ultrasone sensor..."); + System.out.println("Loading ultrasone sensor..."); SampleProvider backUltra = new EV3UltrasonicSensor(brick.getPort("S3")).getDistanceMode(); - LCDPrinter.print("Loading gyro sensor..."); + System.out.println("Loading gyro sensor..."); SensorCollector sc = new SensorCollector(backUltra, leftLight, rightLight, new EV3GyroSensor(brick.getPort("S4"))); BTController.startMaster(slave, sc); - LCDPrinter.print("Finished loading"); + System.out.println("Finished loading"); sc.calibrate(); LinkedList missions = Missions.getMissions(sc, rightMotor, leftMotor, measMotor); random = new Random(); - LCDPrinter.print("Press any button to start"); + System.out.println("Press any button to start"); Button.waitForAnyEvent(); for(Mission m : missions){ - LCDPrinter.print("Start " + m.name + " mission..."); + System.out.println("Start " + m.name + " mission..."); arb = new Arbitrator(m.behaviours); sc.reset(); - Sound.buzz(); arb.start(); - LCDPrinter.print(m.name + " finished!!1one!"); + Sound.buzz(); + System.out.println(m.name + " finished!!1one!"); } System.exit(0); } diff --git a/dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java b/dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java index 7993fe0..6bf5eae 100644 --- a/dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java +++ b/dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java @@ -4,7 +4,7 @@ import lejos.robotics.subsumption.Behavior; public abstract class ShutdownBehaviour implements Behavior{ @Override public void action(){ - LCDPrinter.print("Terminate mission"); + System.out.println("Terminate mission"); Marster.arb.stop(); } diff --git a/dsl/runtime/src/nl/ru/des/sensors/BTController.java b/dsl/runtime/src/nl/ru/des/sensors/BTController.java index 37214a5..0f1ec0f 100644 --- a/dsl/runtime/src/nl/ru/des/sensors/BTController.java +++ b/dsl/runtime/src/nl/ru/des/sensors/BTController.java @@ -9,7 +9,6 @@ import java.util.Queue; import lejos.hardware.Button; import lejos.remote.nxt.BTConnector; import lejos.remote.nxt.NXTConnection; -import nl.ru.des.LCDPrinter; public class BTController{ public static Queue buf; @@ -19,11 +18,11 @@ public class BTController{ private static BTConnector btconnector; public static void startMaster(final String slave, final MessageHandler sh) { - LCDPrinter.print("Start BT... Press any key to commence"); + System.out.println("Start BT... Press any key to commence"); Button.waitForAnyEvent(); btconnector = new BTConnector(); while(conn == null){ - LCDPrinter.print("Connecting to " + slave); + System.out.println("Connecting to " + slave); conn = btconnector.connect(slave, NXTConnection.RAW); } dataOut = conn.openDataOutputStream(); @@ -50,11 +49,11 @@ public class BTController{ } public static void startSlave() { - LCDPrinter.print("Start BT... Press any key to commence"); + System.out.println("Start BT... Press any key to commence"); Button.waitForAnyEvent(); btconnector = new BTConnector(); while(conn == null){ - LCDPrinter.print("Waiting for the master..."); + System.out.println("Waiting for the master..."); conn = btconnector.waitForConnection(60000, NXTConnection.RAW); } dataIn = conn.openDataInputStream(); diff --git a/dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java b/dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java index 642a5e6..b664ab4 100644 --- a/dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java +++ b/dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java @@ -4,7 +4,6 @@ import java.util.Queue; import lejos.robotics.SampleProvider; import lejos.utility.Delay; -import nl.ru.des.LCDPrinter; public class RemoteSensors{ public static final int DELAY = 200; @@ -30,7 +29,7 @@ public class RemoteSensors{ public void start(Queue q){ long last = System.currentTimeMillis(); Delay.msDelay(1000); - LCDPrinter.print("Start sending values..."); + System.out.println("Start sending values..."); while(true){ if(System.currentTimeMillis()-last > DELAY && q.size()<5){ last = System.currentTimeMillis(); diff --git a/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java index af8e87a..64a26b4 100644 --- a/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java +++ b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java @@ -7,7 +7,6 @@ import lejos.hardware.Button; import lejos.hardware.sensor.EV3GyroSensor; import lejos.robotics.SampleProvider; import lejos.utility.Delay; -import nl.ru.des.LCDPrinter; public class SensorCollector implements MessageHandler{ public static final int DELAY = 200; @@ -57,32 +56,32 @@ public class SensorCollector implements MessageHandler{ public void calibrate() { - LCDPrinter.print("Put left light on Blue"); + System.out.println("Put left light on Blue"); Button.waitForAnyEvent(); leftLight(); DANGER_LIGHT = leftLightSamples[0]; - LCDPrinter.print("Light limit: " + Float.toString(DANGER_LIGHT)); + System.out.println("Light limit: " + Float.toString(DANGER_LIGHT)); Delay.msDelay(350); - LCDPrinter.print("Put left light on Black"); + System.out.println("Put left light on Black"); Button.waitForAnyEvent(); leftLight(); DANGER_LIGHT = (leftLightSamples[0]+DANGER_LIGHT)/2.0f; - LCDPrinter.print("Light limit: " + Float.toString(DANGER_LIGHT)); + System.out.println("Light limit: " + Float.toString(DANGER_LIGHT)); Delay.msDelay(350); - LCDPrinter.print("Place back ultra safe"); + System.out.println("Place back ultra safe"); Button.waitForAnyEvent(); backDistance(); DANGER_DISTANCE_BACK = ultraSamples[0] + 0.05f; - LCDPrinter.print("Back ultra limit: " + Float.toString(DANGER_DISTANCE_BACK)); + System.out.println("Back ultra limit: " + Float.toString(DANGER_DISTANCE_BACK)); Delay.msDelay(350); - LCDPrinter.print("Place front ultra in danger"); + System.out.println("Place front ultra in danger"); Button.waitForAnyEvent(); DANGER_DISTANCE_FRONT = frontUltra; - LCDPrinter.print("Calibration done"); - LCDPrinter.print("Front ultra limit: " + Float.toString(DANGER_DISTANCE_FRONT)); + System.out.println("Calibration done"); + System.out.println("Front ultra limit: " + Float.toString(DANGER_DISTANCE_FRONT)); } //Local sensors diff --git a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend index 5af781f..16aa0e6 100644 --- a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend +++ b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend @@ -78,7 +78,7 @@ public class «b.name»Behaviour extends BasicBehaviour { «ENDIF» @Override public void action(){ - LCDPrinter.print("Start: «b.name»"); + System.out.println("Start: «b.name»"); super.action(); «FOR a : b.actions» «IF a.whichMotor != null» @@ -112,7 +112,7 @@ public class «b.name»Behaviour extends BasicBehaviour { } «ENDIF» «ENDFOR» - LCDPrinter.print("Stop: «b.name»"); + System.out.print("Stop: «b.name»"); } } '''