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
//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
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;
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());
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
package nl.ru.des.sensors;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
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;
leftTouch = false;
rightTouch = false;
frontUltra = Float.MAX_VALUE;
- collectedColors = new HashSet<Integer>();
+ variables = new HashSet<String>();
}
//Local sensors
}
//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(){
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;
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'|
«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»");
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»