From: Mart Lubbers Date: Mon, 7 Dec 2015 10:54:52 +0000 (+0100) Subject: update, working bt and final schedule X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=426ca40778af548128b5d5f37705fffcf1cc9c7b;p=des2015.git update, working bt and final schedule --- diff --git a/dsl/runtime/src/nl/ru/des/BasicBehaviour.java b/dsl/runtime/src/nl/ru/des/BasicBehaviour.java index aeb138d..5095222 100644 --- a/dsl/runtime/src/nl/ru/des/BasicBehaviour.java +++ b/dsl/runtime/src/nl/ru/des/BasicBehaviour.java @@ -2,19 +2,18 @@ package nl.ru.des; import lejos.hardware.motor.EV3LargeRegulatedMotor; import lejos.robotics.subsumption.Behavior; +import nl.ru.des.sensors.SensorCollector; public abstract class BasicBehaviour implements Behavior{ protected boolean suppressed; protected EV3LargeRegulatedMotor leftMotor, rightMotor; protected SensorCollector sensors; - protected ColorMemory colors; protected long time; public BasicBehaviour(SensorCollector sensors, EV3LargeRegulatedMotor leftMotor, - EV3LargeRegulatedMotor rightMotor, ColorMemory colors){ + EV3LargeRegulatedMotor rightMotor){ this.leftMotor = leftMotor; this.rightMotor = rightMotor; - this.colors = colors; this.sensors = sensors; } diff --git a/dsl/runtime/src/nl/ru/des/ColorMemory.java b/dsl/runtime/src/nl/ru/des/ColorMemory.java deleted file mode 100644 index 61b0f2b..0000000 --- a/dsl/runtime/src/nl/ru/des/ColorMemory.java +++ /dev/null @@ -1,26 +0,0 @@ -package nl.ru.des; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import lejos.robotics.SampleProvider; - -public class ColorMemory { - - private Set colors; - - public ColorMemory(SampleProvider color) { - colors = new HashSet(); - } - - public void addColor(int current) { - if(!colors.contains(current)){ - colors.add(current); - } - } - public boolean containsAll(List is) { - return colors.containsAll(is); - } - -} diff --git a/dsl/runtime/src/nl/ru/des/Marster.java b/dsl/runtime/src/nl/ru/des/Marster.java index b31bb87..6fc32e8 100644 --- a/dsl/runtime/src/nl/ru/des/Marster.java +++ b/dsl/runtime/src/nl/ru/des/Marster.java @@ -1,7 +1,5 @@ package nl.ru.des; -import java.util.Queue; - import lejos.hardware.Button; import lejos.hardware.ev3.EV3; import lejos.hardware.ev3.LocalEV3; @@ -16,6 +14,9 @@ import lejos.hardware.sensor.EV3UltrasonicSensor; import lejos.hardware.sensor.NXTLightSensor; import lejos.robotics.SampleProvider; import lejos.robotics.subsumption.Arbitrator; +import nl.ru.des.sensors.BTController; +import nl.ru.des.sensors.RemoteSensors; +import nl.ru.des.sensors.SensorCollector; public class Marster { public static Arbitrator arb; @@ -44,9 +45,10 @@ public class Marster { SampleProvider color = new EV3ColorSensor(brick.getPort("S4")).getColorIDMode(); RemoteSensors rs = new RemoteSensors(leftTouch, rightTouch, frontUltra, color); - LCDPrinter.print("Start BT..."); - Queue msgs = BTController.startSlave(); - rs.start(msgs); + LCDPrinter.print("Start BT... Press any key to commence"); + Button.waitForAnyEvent(); + BTController.startSlave(); + rs.start(BTController.buf); } else { LCDPrinter.print("Starting as as master..."); LCDPrinter.print("Loading motors..."); @@ -70,7 +72,8 @@ public class Marster { LCDPrinter.print("Loading gyro sensor..."); SampleProvider gyro = new EV3GyroSensor(brick.getPort("S4")).getAngleAndRateMode(); - LCDPrinter.print("Start BT..."); + LCDPrinter.print("Start BT... Press any key to commence"); + Button.waitForAnyEvent(); BTController.startMaster(brick.getName() == "Rover5" ? "Rover6" : "Rover8", new SensorCollector(backUltra, leftLight, rightLight, gyro)); LCDPrinter.print("Finished loading"); Button.waitForAnyPress(); diff --git a/dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java b/dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java index ba433ba..4e9e5aa 100644 --- a/dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java +++ b/dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java @@ -1,11 +1,12 @@ package nl.ru.des; import lejos.hardware.motor.EV3LargeRegulatedMotor; +import nl.ru.des.sensors.SensorCollector; public class ShutdownBehaviour extends BasicBehaviour{ public ShutdownBehaviour(SensorCollector sensors, EV3LargeRegulatedMotor leftMotor, - EV3LargeRegulatedMotor rightMotor, ColorMemory colors) { - super(sensors, leftMotor, rightMotor, colors); + EV3LargeRegulatedMotor rightMotor) { + super(sensors, leftMotor, rightMotor); } @Override public void action(){ diff --git a/dsl/runtime/src/nl/ru/des/BTController.java b/dsl/runtime/src/nl/ru/des/sensors/BTController.java similarity index 70% rename from dsl/runtime/src/nl/ru/des/BTController.java rename to dsl/runtime/src/nl/ru/des/sensors/BTController.java index 5c75784..206552e 100644 --- a/dsl/runtime/src/nl/ru/des/BTController.java +++ b/dsl/runtime/src/nl/ru/des/sensors/BTController.java @@ -1,4 +1,4 @@ -package nl.ru.des; +package nl.ru.des.sensors; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -10,17 +10,22 @@ import lejos.remote.nxt.BTConnector; import lejos.remote.nxt.NXTConnection; public class BTController{ + public static Queue buf; + public static DataInputStream dataIn; + public static DataOutputStream dataOut; + public static void startMaster(final String slave, final MessageHandler sh) { BTConnector btconnector = new BTConnector(); NXTConnection conn = btconnector.connect(slave, NXTConnection.RAW); - final DataInputStream dataInput = conn.openDataInputStream(); + dataOut = conn.openDataOutputStream(); + dataIn = conn.openDataInputStream(); new Thread() { @Override public void run() { StringBuilder sb = new StringBuilder(); while (true) { try { - int c = dataInput.readUnsignedByte(); + int c = dataIn.readUnsignedByte(); if (c == '\n') { sh.handleMessage(sb.toString()); sb = new StringBuilder(); @@ -35,18 +40,19 @@ public class BTController{ }.start(); } - public static Queue startSlave() { + public static void startSlave() { BTConnector btconnector = new BTConnector(); NXTConnection conn = btconnector.waitForConnection(60000, NXTConnection.RAW); - final DataOutputStream dataOutput = conn.openDataOutputStream(); - final Queue buf = new LinkedList(); + dataIn = conn.openDataInputStream(); + dataOut = conn.openDataOutputStream(); + buf = new LinkedList(); new Thread(){ @Override public void run(){ while (true) { if (!buf.isEmpty()) { try { - dataOutput.write(buf.poll().getBytes()); - dataOutput.flush(); + dataOut.write(buf.poll().getBytes()); + dataOut.flush(); } catch (IOException e) { e.printStackTrace(); } @@ -55,6 +61,5 @@ public class BTController{ } } }.start(); - return buf; } } \ No newline at end of file diff --git a/dsl/runtime/src/nl/ru/des/MessageHandler.java b/dsl/runtime/src/nl/ru/des/sensors/MessageHandler.java similarity index 75% rename from dsl/runtime/src/nl/ru/des/MessageHandler.java rename to dsl/runtime/src/nl/ru/des/sensors/MessageHandler.java index ecd00e9..3eac303 100644 --- a/dsl/runtime/src/nl/ru/des/MessageHandler.java +++ b/dsl/runtime/src/nl/ru/des/sensors/MessageHandler.java @@ -1,4 +1,4 @@ -package nl.ru.des; +package nl.ru.des.sensors; public interface MessageHandler { public void handleMessage(String message); diff --git a/dsl/runtime/src/nl/ru/des/RemoteSensors.java b/dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java similarity index 95% rename from dsl/runtime/src/nl/ru/des/RemoteSensors.java rename to dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java index afebb11..d25adb3 100644 --- a/dsl/runtime/src/nl/ru/des/RemoteSensors.java +++ b/dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java @@ -1,8 +1,9 @@ -package nl.ru.des; +package nl.ru.des.sensors; import java.util.Queue; import lejos.robotics.SampleProvider; +import nl.ru.des.LCDPrinter; public class RemoteSensors{ public static final int DELAY = 250; @@ -10,7 +11,7 @@ public class RemoteSensors{ private float[] leftSamples, rightSamples, ultraSamples, colorSamples; private float leftLatest, rightLatest, ultraLatest, colorLatest; - public enum RemoteSensorEnum{ + public enum RemoteSensorEnum { LEFT, RIGHT, ULTRA, COLOR; } diff --git a/dsl/runtime/src/nl/ru/des/SensorCollector.java b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java similarity index 97% rename from dsl/runtime/src/nl/ru/des/SensorCollector.java rename to dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java index 9a58ae4..3faae09 100644 --- a/dsl/runtime/src/nl/ru/des/SensorCollector.java +++ b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java @@ -1,4 +1,4 @@ -package nl.ru.des; +package nl.ru.des.sensors; import lejos.robotics.SampleProvider; @@ -85,9 +85,8 @@ public class SensorCollector implements MessageHandler{ @Override public void handleMessage(String m) { - LCDPrinter.print(m); String s = m.substring(1); - switch(RemoteSensors.RemoteSensorEnum.values()[Integer.valueOf(m.charAt(0))]){ + switch(RemoteSensors.RemoteSensorEnum.values()[Integer.valueOf(Character.toString(m.charAt(0)))]){ case COLOR: color = Integer.valueOf(s); break; diff --git a/marsrover/document/dev.tex b/marsrover/document/dev.tex index 0ef4dd8..eafb75f 100644 --- a/marsrover/document/dev.tex +++ b/marsrover/document/dev.tex @@ -5,18 +5,19 @@ iterations will have an implementation phase, a testing phase, an analysis phase, and a design phase. Furthermore, each of the iterations will have goals and results. The iterations and their deliverables are listed in \autoref{tab:devit}. The schedule for finishing iterations are listed in -\autoref{tab:deadli}. On the 23rd of december the must should be finished and -if they are we try to complete as many iterations as possible. +\autoref{tab:deadli}. On the 6th of January the must-have should be finished +and if they are we try to complete as many iterations as possible. \begin{table}[h!] \centering \begin{tabu} to \linewidth{llX} \toprule Deadline & Iterations\\ \midrule - 3 Dec 2015 & 1--2\\ - 9 Dec 2015 & 3--5\\ - 16 Dec 2015 & 6--9\\ - 23 Dec 2015 & 10--11\\ + 9 Dec 2015 & 1--2\\ + 16 Dec 2015 & 3--5\\ + 23 Dec 2015 & 6--9\\ + 6 Jan 2015 & 10--11\\ + 13 Jan 2015 & Demo\\ \bottomrule \end{tabu} \caption{Deadlines}\label{tab:deadli}