update, working bt and final schedule
authorMart Lubbers <mart@martlubbers.net>
Mon, 7 Dec 2015 10:54:52 +0000 (11:54 +0100)
committerMart Lubbers <mart@martlubbers.net>
Mon, 7 Dec 2015 10:54:52 +0000 (11:54 +0100)
dsl/runtime/src/nl/ru/des/BasicBehaviour.java
dsl/runtime/src/nl/ru/des/ColorMemory.java [deleted file]
dsl/runtime/src/nl/ru/des/Marster.java
dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java
dsl/runtime/src/nl/ru/des/sensors/BTController.java [moved from dsl/runtime/src/nl/ru/des/BTController.java with 70% similarity]
dsl/runtime/src/nl/ru/des/sensors/MessageHandler.java [moved from dsl/runtime/src/nl/ru/des/MessageHandler.java with 75% similarity]
dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java [moved from dsl/runtime/src/nl/ru/des/RemoteSensors.java with 95% similarity]
dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java [moved from dsl/runtime/src/nl/ru/des/SensorCollector.java with 97% similarity]
marsrover/document/dev.tex

index aeb138d..5095222 100644 (file)
@@ -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 (file)
index 61b0f2b..0000000
+++ /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<Integer> colors;
-       
-       public ColorMemory(SampleProvider color) {
-               colors = new HashSet<Integer>();
-       }
-
-       public void addColor(int current) {
-               if(!colors.contains(current)){
-                       colors.add(current);
-               }
-       }
-       public boolean containsAll(List<Integer> is) {
-               return colors.containsAll(is);
-       }
-
-}
index b31bb87..6fc32e8 100644 (file)
@@ -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<String> 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();
index ba433ba..4e9e5aa 100644 (file)
@@ -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(){
@@ -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<String> 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<String> startSlave() {
+       public static void startSlave() {
                BTConnector btconnector = new BTConnector();
                NXTConnection conn = btconnector.waitForConnection(60000, NXTConnection.RAW);
-               final DataOutputStream dataOutput = conn.openDataOutputStream();
-               final Queue<String> buf = new LinkedList<String>();
+               dataIn = conn.openDataInputStream();
+               dataOut = conn.openDataOutputStream();
+               buf = new LinkedList<String>();
                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
@@ -1,4 +1,4 @@
-package nl.ru.des;
+package nl.ru.des.sensors;
 
 public interface MessageHandler {
        public void handleMessage(String message);
@@ -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;
        }
        
@@ -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;
index 0ef4dd8..eafb75f 100644 (file)
@@ -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}