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;
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
--- /dev/null
+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...
+ }
+}
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.
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;