missions started, todo: color collecting, mission switching
authorMart Lubbers <mart@martlubbers.net>
Fri, 20 Nov 2015 07:53:15 +0000 (08:53 +0100)
committerMart Lubbers <mart@martlubbers.net>
Fri, 20 Nov 2015 07:53:15 +0000 (08:53 +0100)
dsl/runtime/src/nl/ru/des/ColorMemory.java
dsl/runtime/src/nl/ru/des/MarsRover.java
dsl/runtime/src/nl/ru/des/Mission.java [new file with mode: 0644]
dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java [new file with mode: 0644]
dsl/xtend/src/robots/missions/TaskDSL.xtext
dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend

index 08e9895..cec193e 100644 (file)
@@ -1,5 +1,14 @@
 package nl.ru.des;
 
+import lejos.robotics.SampleProvider;
+
 public class ColorMemory {
 
+       public ColorMemory(SampleProvider color) {
+       }
+
+       public boolean containsAll(int[] is) {
+               return false;
+       }
+
 }
index f5aee01..c4b3ddf 100644 (file)
@@ -10,6 +10,7 @@ import lejos.hardware.sensor.EV3ColorSensor;
 import lejos.hardware.sensor.EV3TouchSensor;
 import lejos.hardware.sensor.EV3UltrasonicSensor;
 import lejos.robotics.SampleProvider;
+import lejos.robotics.subsumption.Arbitrator;
 
 public class MarsRover {
        public static final float SAMPLERATE = 100;
@@ -45,5 +46,15 @@ public class MarsRover {
 
                LCDPrinter.print("Initializing behaviours...");
                SensorCollector sensors = new SensorCollector(ultraSonic, color, leftTouch, rightTouch);
+               
+               LCDPrinter.print("Initializing color collector...");
+               ColorMemory colorMemory = new ColorMemory(color);
+               
+               Arbitrator a;
+               for(Mission m : Missions.getMissions(sensors, rightMotor, leftMotor, colorMemory)){
+                       LCDPrinter.print("Start " + m.name + " mission...");
+                       a = new Arbitrator(m.behaviours);
+                       a.start();
+               }
        }
 }
\ No newline at end of file
diff --git a/dsl/runtime/src/nl/ru/des/Mission.java b/dsl/runtime/src/nl/ru/des/Mission.java
new file mode 100644 (file)
index 0000000..c80678e
--- /dev/null
@@ -0,0 +1,13 @@
+package nl.ru.des;
+
+import lejos.robotics.subsumption.Behavior;
+
+public class Mission {
+       public String name;
+       public Behavior[] behaviours;
+       
+       public Mission(String name, Behavior[] behaviours){
+               this.name = name;
+               this.behaviours = behaviours;
+       }
+}
diff --git a/dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java b/dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java
new file mode 100644 (file)
index 0000000..85aa07b
--- /dev/null
@@ -0,0 +1,15 @@
+package nl.ru.des;
+
+import lejos.hardware.motor.EV3LargeRegulatedMotor;
+
+public class ShutdownBehaviour extends BasicBehaviour{
+
+       public ShutdownBehaviour(SensorCollector sensors, EV3LargeRegulatedMotor leftMotor,
+                       EV3LargeRegulatedMotor rightMotor, ColorMemory colors) {
+               super(sensors, leftMotor, rightMotor, colors);
+       }
+       
+       @Override public void action(){
+               //Here it should stop the current arbitrator, not sure how yet...
+       }
+}
index 79128de..9c14fa3 100644 (file)
@@ -9,7 +9,7 @@ Robot:
        behaviour+=Behaviour+
        mission+=Mission+;
 
-Mission: 'Mission' name=ID 'using' behaviours+=[Behaviour]+ 'and stops when' stoppingExpression=StoppingExpression;
+Mission: 'Mission' name=ID 'using' behaviours+=[Behaviour]+ 'and stops when' se=StoppingExpression;
 
 StoppingExpression:
        '(' op=Operator s+=StoppingExpression s+=StoppingExpression+ ')' |
index ec286e9..9aecf7e 100644 (file)
@@ -11,6 +11,7 @@ import robots.missions.taskDSL.Behaviour
 import robots.missions.taskDSL.OperatorE
 import robots.missions.taskDSL.Robot
 import robots.missions.taskDSL.StoppingExpression
+import robots.missions.taskDSL.Mission
 
 /**
  * Generates code from your model files on save.
@@ -22,12 +23,43 @@ class TaskDSLGenerator implements IGenerator {
        override void doGenerate(Resource resource, IFileSystemAccess fsa) {
                var root = resource.allContents.head as Robot;
                if(root != null){
-                       fsa.generateFile("nl/ru/des/Constants.java", makeConstants(root))
-                       fsa.generateFile("nl/ru/des/Behaviours.java", makeBehaviours(root.behaviour))
+                       fsa.generateFile("nl/ru/des/Constants.java", makeConstants(root));
+                       fsa.generateFile("nl/ru/des/Behaviours.java", makeBehaviours(root.behaviour));
+                       fsa.generateFile("nl/ru/des/Missions.java", makeMissions(root.mission));
                }
        }
        
-       def makeBehaviours(EList<Behaviour> list)'''
+       def CharSequence makeMissions(EList<Mission> list)'''
+package nl.ru.des;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import lejos.hardware.motor.EV3LargeRegulatedMotor;
+import lejos.robotics.subsumption.Behavior;
+import nl.ru.des.Behaviours;
+
+public class Missions{
+       public static List<Mission> getMissions(SensorCollector sensors, EV3LargeRegulatedMotor rightMotor,
+                       EV3LargeRegulatedMotor leftMotor, ColorMemory colors){
+               LinkedList<Mission> missions = new LinkedList<Mission>();
+               «FOR m : list»
+               missions.add(new Mission("«m.name»", new Behavior[]{
+                       «FOR b : m.behaviours SEPARATOR ","»
+                       new Behaviours.«b.name»Behaviour(sensors, rightMotor, leftMotor, colors)
+                       «ENDFOR»,
+                       new ShutdownBehaviour(sensors, rightMotor, leftMotor, colors){
+                               @Override public boolean takeControl(){
+                                       return «printExpression(m.se)»;
+                               }
+                       }}
+               «ENDFOR»));
+               return missions;
+       }
+}      
+'''
+       
+       def CharSequence makeBehaviours(EList<Behaviour> list)'''
 package nl.ru.des;
 
 import lejos.hardware.motor.EV3LargeRegulatedMotor;