From: Mart Lubbers Date: Wed, 6 Jan 2016 13:59:17 +0000 (+0100) Subject: add sound X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=f92a71770aa8fc8abe3a60660df2965ec18cb479;p=des2015.git add sound --- diff --git a/dsl/runtime/specs/wander.tdsl b/dsl/runtime/specs/wander.tdsl index 5b9c1a0..d592a25 100644 --- a/dsl/runtime/specs/wander.tdsl +++ b/dsl/runtime/specs/wander.tdsl @@ -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 diff --git a/dsl/runtime/src/nl/ru/des/Marster.java b/dsl/runtime/src/nl/ru/des/Marster.java index 81ee5f6..0a48bc1 100644 --- a/dsl/runtime/src/nl/ru/des/Marster.java +++ b/dsl/runtime/src/nl/ru/des/Marster.java @@ -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 diff --git a/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java index 4597d92..db10870 100644 --- a/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java +++ b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java @@ -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 collectedColors; + private Set 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(); + variables = new HashSet(); } //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; diff --git a/mart/ev3/ex1/nl/ru/des/sounds/rick.wav b/dsl/runtime/src/nl/ru/des/sound/rick.wav similarity index 100% rename from mart/ev3/ex1/nl/ru/des/sounds/rick.wav rename to dsl/runtime/src/nl/ru/des/sound/rick.wav diff --git a/dsl/xtend/src/robots/missions/TaskDSL.xtext b/dsl/xtend/src/robots/missions/TaskDSL.xtext index 641e3c3..7fb398a 100644 --- a/dsl/xtend/src/robots/missions/TaskDSL.xtext +++ b/dsl/xtend/src/robots/missions/TaskDSL.xtext @@ -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'| diff --git a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend index c11ade8..3baaa06 100644 --- a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend +++ b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend @@ -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»