add sound
authorMart Lubbers <mart@martlubbers.net>
Wed, 6 Jan 2016 13:59:17 +0000 (14:59 +0100)
committerMart Lubbers <mart@martlubbers.net>
Wed, 6 Jan 2016 13:59:17 +0000 (14:59 +0100)
dsl/runtime/specs/wander.tdsl
dsl/runtime/src/nl/ru/des/Marster.java
dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java
dsl/runtime/src/nl/ru/des/sound/rick.wav [moved from mart/ev3/ex1/nl/ru/des/sounds/rick.wav with 100% similarity]
dsl/xtend/src/robots/missions/TaskDSL.xtext
dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend

index 5b9c1a0..d592a25 100644 (file)
@@ -37,10 +37,21 @@ Behaviour StayInFieldB
                right motor forward
                wait 1000 ms
                
-Behaviour MeasureLake
-       take control: (|| Color is Green Color is Blue Color is Red)
+Behaviour MeasureGreenLake
+       take control: (&& Color is Green not flag set GreenMeasured)
        action:
                measure Lake
+               set flag GreenMeasured
+Behaviour MeasureBlueLake
+       take control: (&& Color is Blue not flag set BlueMeasured)
+       action:
+               measure Lake
+               set flag BlueMeasured
+Behaviour MeasureRedLake
+       take control: (&& Color is Red not flag set RedMeasured)
+       action:
+               measure Lake
+               set flag RedMeasured
                
 Behaviour LocateL
        take control: Touched on left
@@ -90,10 +101,10 @@ Behaviour AvoidHigh
                
 //Mission pushRock
 //     using Drive LocateR LocateL Push StayInFieldB StayInFieldL StayInFieldR and stops when Never
-Mission avoidHighRocks
-       using Drive AvoidHigh BumpR BumpL StayInFieldB StayInFieldL StayInFieldR and stops when Never
-//Mission measureLake
-//     using Drive MeasureLake and stops when Never
+//Mission avoidHighRocks
+//     using Drive AvoidHigh BumpR BumpL StayInFieldB StayInFieldL StayInFieldR and stops when Never
+Mission measureLakes
+       using Drive MeasureRedLake MeasureGreenLake MeasureBlueLake and stops when (&& flag set GreenMeasured flag set BlueMeasured flag set RedMeasured)
 //Mission findBlueLakeWhileAvoidingRocks
 //     using Wander BumpR BumpL StayInFieldB StayInFieldL StayInFieldR and stops when Color is Blue
 //Mission findAllLakesAndMeasureThem
index 81ee5f6..0a48bc1 100644 (file)
@@ -1,8 +1,13 @@
 package nl.ru.des;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.LinkedList;
 import java.util.Random;
 
+import lejos.hardware.Sound;
 import lejos.hardware.ev3.EV3;
 import lejos.hardware.ev3.LocalEV3;
 import lejos.hardware.lcd.Font;
@@ -53,6 +58,18 @@ public class Marster {
                        BTController.startSlave();
                        rs.start(BTController.buf);
                } else {
+                       try {
+                               InputStream inp = Marster.class.getResourceAsStream("nl/ru/des/sound/rick.wav");
+                               FileOutputStream out = new FileOutputStream("rick.wav");
+                               byte buffer[] = new byte[2048];
+                               while(inp.read(buffer)>0){
+                                       out.write(buffer);
+                               }
+                               inp.close();
+                               out.close();
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }
                        String slave = brick.getName().equalsIgnoreCase("Rover5") ? "Rover6" : "Rover8";
                        LCDPrinter.print("Starting as as master...");
                        LCDPrinter.print("My name is " + brick.getName());
@@ -85,10 +102,11 @@ public class Marster {
                        for(Mission m : missions){
                                LCDPrinter.print("Start " + m.name + " mission...");
                                arb = new Arbitrator(m.behaviours);
-                               sc.resetColors();
+                               sc.reset();
                                arb.start();
                                LCDPrinter.print(m.name + " finished!!1one!");
                        }
+                       Sound.playSample(new File("rick.wav"));
                }
        }
 }
\ No newline at end of file
index 4597d92..db10870 100644 (file)
@@ -1,6 +1,5 @@
 package nl.ru.des.sensors;
 
-import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -14,7 +13,7 @@ public class SensorCollector implements MessageHandler{
        private static final float DANGER_DISTANCE_BACK = 0.035f;
        private static final float DANGER_LIGHT = 0.40f;
        
-       private Set<Integer> collectedColors;
+       private Set<String> variables;
        
        //Local sensors
        private EV3GyroSensor gyroSensor;
@@ -49,7 +48,7 @@ public class SensorCollector implements MessageHandler{
                leftTouch = false;
                rightTouch = false;
                frontUltra = Float.MAX_VALUE;
-               collectedColors = new HashSet<Integer>();
+               variables = new HashSet<String>();
        }
        
        //Local sensors
@@ -90,12 +89,16 @@ public class SensorCollector implements MessageHandler{
        }
        
        //Remote sensors
-       public void resetColors(){
-               collectedColors.clear();
+       public void reset(){
+               variables.clear();
        }
        
-       public boolean collected(int[] colors){
-               return collectedColors.containsAll(Arrays.asList(colors));
+       public boolean collected(String var){
+               return variables.contains(var);
+       }
+
+       public void saveVar(String var) {
+               variables.add(var);
        }
        
        public int color(){
@@ -120,7 +123,6 @@ public class SensorCollector implements MessageHandler{
                switch(RemoteSensors.RemoteSensorEnum.values()[Integer.valueOf(Character.toString(m.charAt(0)))]){
                case COLOR:
                        color = Integer.valueOf(s);
-                       collectedColors.add(color);
                        break;
                case LEFT:
                        leftTouch = Integer.valueOf(s)==1;
index 641e3c3..7fb398a 100644 (file)
@@ -17,22 +17,24 @@ StoppingExpression:
        scond=StoppingCondition;
 
 StoppingCondition:
-       'Collected at least' colors+=Color+ |
+       'flag set' varName=ID |
        'Touched on' touch=LeftRight |
        'Light on' light=LeftRight |
        'Distance dangerous at ' dist=BackFront |
        'Color is' color=Color |
        {StoppingCondition} 'Never';
 
-Behaviour: 'Behaviour' name=ID 
+Behaviour: 'Behaviour' name=ID
        'take control:' tc=StoppingExpression?
-       'action:' actions+=Action+;
+       'action:' actions+=Action+
+       ;
 
 Action:
        whichMotor=LeftRight 'motor' moveDir=Direction ('with speed' spd=INT 'acceleration' acc=INT)? |
        'turn' turnType=Turn ('with speed' spd=INT 'acceleration' acc=INT)? |
        'measure' rl=RockLake|
-       'wait' time=Time;
+       'wait' time=Time |
+       'set flag' varName=ID;
        
 Turn:
        turnDir=LeftRight 'exactly' degrees=INT 'degrees'|
index c11ade8..3baaa06 100644 (file)
@@ -104,8 +104,10 @@ public class «b.name»Behaviour extends BasicBehaviour {
                                «ELSE»
                                        turnRandom(«a.turnType.start», «a.turnType.end»);
                                «ENDIF»
-                       «ELSE»
+                       «ELSEIF a.rl != null»
                        measure«a.rl.d.toString()»();
+                       «ELSE»
+                       sensors.saveVar("«a.varName.toString()»");
                        «ENDIF»
                «ENDFOR»
                LCDPrinter.print("Stop: «b.name»");
@@ -123,8 +125,8 @@ public class Constants{
        
        def CharSequence printExpression(StoppingExpression e)'''
        «IF e.scond != null»
-               «IF !e.scond.colors.nullOrEmpty»
-               sensors.collected(new int[]{«FOR c : e.scond.colors SEPARATOR ","»«c.d.ordinal»«ENDFOR»})
+               «IF e.scond.varName != null»
+               sensors.collected("«e.scond.varName.toString()»")
                «ELSEIF e.scond.touch != null»
                sensors.«e.scond.touch.d.toString()»Touch()
                «ELSEIF e.scond.light != null»