From d26ca60c0346639b0d93d671906eaf8a4763c10c Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Fri, 20 Nov 2015 08:53:15 +0100 Subject: [PATCH] missions started, todo: color collecting, mission switching --- dsl/runtime/src/nl/ru/des/ColorMemory.java | 9 +++++ dsl/runtime/src/nl/ru/des/MarsRover.java | 11 ++++++ dsl/runtime/src/nl/ru/des/Mission.java | 13 +++++++ .../src/nl/ru/des/ShutdownBehaviour.java | 15 ++++++++ dsl/xtend/src/robots/missions/TaskDSL.xtext | 2 +- .../missions/generator/TaskDSLGenerator.xtend | 38 +++++++++++++++++-- 6 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 dsl/runtime/src/nl/ru/des/Mission.java create mode 100644 dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java diff --git a/dsl/runtime/src/nl/ru/des/ColorMemory.java b/dsl/runtime/src/nl/ru/des/ColorMemory.java index 08e9895..cec193e 100644 --- a/dsl/runtime/src/nl/ru/des/ColorMemory.java +++ b/dsl/runtime/src/nl/ru/des/ColorMemory.java @@ -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; + } + } diff --git a/dsl/runtime/src/nl/ru/des/MarsRover.java b/dsl/runtime/src/nl/ru/des/MarsRover.java index f5aee01..c4b3ddf 100644 --- a/dsl/runtime/src/nl/ru/des/MarsRover.java +++ b/dsl/runtime/src/nl/ru/des/MarsRover.java @@ -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 index 0000000..c80678e --- /dev/null +++ b/dsl/runtime/src/nl/ru/des/Mission.java @@ -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 index 0000000..85aa07b --- /dev/null +++ b/dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java @@ -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... + } +} diff --git a/dsl/xtend/src/robots/missions/TaskDSL.xtext b/dsl/xtend/src/robots/missions/TaskDSL.xtext index 79128de..9c14fa3 100644 --- a/dsl/xtend/src/robots/missions/TaskDSL.xtext +++ b/dsl/xtend/src/robots/missions/TaskDSL.xtext @@ -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+ ')' | diff --git a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend index ec286e9..9aecf7e 100644 --- a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend +++ b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend @@ -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 list)''' + def CharSequence makeMissions(EList 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 getMissions(SensorCollector sensors, EV3LargeRegulatedMotor rightMotor, + EV3LargeRegulatedMotor leftMotor, ColorMemory colors){ + LinkedList missions = new LinkedList(); + «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 list)''' package nl.ru.des; import lejos.hardware.motor.EV3LargeRegulatedMotor; -- 2.20.1