From: Mart Lubbers Date: Thu, 19 Nov 2015 20:23:37 +0000 (+0100) Subject: behaviours generate just fine now, missions is next. We also need some color functions X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=82d6b6dc9f3f9dbcaa9f8320649df29359c83279;p=des2015.git behaviours generate just fine now, missions is next. We also need some color functions --- diff --git a/dsl/runtime/specs/spec1.tdsl b/dsl/runtime/specs/spec1.tdsl index 6bbc02f..45e74a3 100644 --- a/dsl/runtime/specs/spec1.tdsl +++ b/dsl/runtime/specs/spec1.tdsl @@ -4,37 +4,37 @@ Speed 200 Behaviour Wander take control: action: - Left motor Forwards - Right motor Forwards + left motor forward + right motor forward wait forever Behaviour AvoidLowLeftObjects - take control: Touched on Left + take control: Touched on left action: - Left motor Backwards - Right motor Backwards + left motor backward + right motor backward wait 250 ms - Right motor Backwards - Left motor Forwards + right motor backward + left motor forward wait 250 ms Behaviour AvoidLowRightObjects - take control: Touched on Right + take control: Touched on right action: - Left motor Backwards - Right motor Backwards + left motor backward + right motor backward wait 250 ms - Right motor Forwards - Left motor Backwards + right motor forward + left motor backward wait 250 ms Behaviour AvoidHighObjects take control: Distance < 50 cm action: - Right motor Forwards + right motor forward wait 250 ms Behaviour StayInLine take control: (or Color is Black Color is DarkGray) action: - Right motor Forwards - Left motor Backwards + right motor forward + left motor backward wait 250 ms Mission Assignment using diff --git a/dsl/runtime/src/nl/ru/des/BasicBehaviour.java b/dsl/runtime/src/nl/ru/des/BasicBehaviour.java index 2f1dcda..aeb138d 100644 --- a/dsl/runtime/src/nl/ru/des/BasicBehaviour.java +++ b/dsl/runtime/src/nl/ru/des/BasicBehaviour.java @@ -4,18 +4,41 @@ import lejos.hardware.motor.EV3LargeRegulatedMotor; import lejos.robotics.subsumption.Behavior; public abstract class BasicBehaviour implements Behavior{ + protected boolean suppressed; protected EV3LargeRegulatedMotor leftMotor, rightMotor; + protected SensorCollector sensors; + protected ColorMemory colors; + protected long time; - public BasicBehaviour(nl.ru.des.Sensors sensors, EV3LargeRegulatedMotor leftMotor, EV3LargeRegulatedMotor rightMotor){ + public BasicBehaviour(SensorCollector sensors, EV3LargeRegulatedMotor leftMotor, + EV3LargeRegulatedMotor rightMotor, ColorMemory colors){ this.leftMotor = leftMotor; this.rightMotor = rightMotor; + this.colors = colors; + this.sensors = sensors; + } + + protected void reset(){ + rightMotor.setSpeed(Constants.speed); + rightMotor.setAcceleration(Constants.acceleration); + leftMotor.setSpeed(Constants.speed); + leftMotor.setAcceleration(Constants.acceleration); + rightMotor.stop(true); + leftMotor.stop(true); } @Override - public boolean takeControl() { - return true; + public void action() { + suppressed = false; } @Override - public void suppress() {} + public void suppress() { + suppressed = true; + } + + @Override + public boolean takeControl() { + return true; + } } diff --git a/dsl/runtime/src/nl/ru/des/ColorMemory.java b/dsl/runtime/src/nl/ru/des/ColorMemory.java new file mode 100644 index 0000000..08e9895 --- /dev/null +++ b/dsl/runtime/src/nl/ru/des/ColorMemory.java @@ -0,0 +1,5 @@ +package nl.ru.des; + +public class ColorMemory { + +} diff --git a/dsl/runtime/src/nl/ru/des/MarsRover.java b/dsl/runtime/src/nl/ru/des/MarsRover.java index c2890e4..f5aee01 100644 --- a/dsl/runtime/src/nl/ru/des/MarsRover.java +++ b/dsl/runtime/src/nl/ru/des/MarsRover.java @@ -10,7 +10,6 @@ import lejos.hardware.sensor.EV3ColorSensor; import lejos.hardware.sensor.EV3TouchSensor; import lejos.hardware.sensor.EV3UltrasonicSensor; import lejos.robotics.SampleProvider; -import nl.ru.des.dsl.Constants; public class MarsRover { public static final float SAMPLERATE = 100; @@ -29,10 +28,10 @@ public class MarsRover { LCDPrinter.print("Loading motors..."); EV3LargeRegulatedMotor rightMotor = new EV3LargeRegulatedMotor(MotorPort.D); EV3LargeRegulatedMotor leftMotor = new EV3LargeRegulatedMotor(MotorPort.A); - leftMotor.setSpeed(Constants.defaultSpeed); - rightMotor.setSpeed(Constants.defaultSpeed); - rightMotor.setAcceleration(Constants.defaultAcceleration); - leftMotor.setAcceleration(Constants.defaultAcceleration); + leftMotor.setSpeed(Constants.speed); + rightMotor.setSpeed(Constants.speed); + rightMotor.setAcceleration(Constants.acceleration); + leftMotor.setAcceleration(Constants.acceleration); LCDPrinter.print("Loading touch sensors..."); SampleProvider leftTouch = new EV3TouchSensor(brick.getPort("S1")).getTouchMode(); @@ -45,6 +44,6 @@ public class MarsRover { SampleProvider ultraSonic = new EV3UltrasonicSensor(brick.getPort("S3")).getDistanceMode(); LCDPrinter.print("Initializing behaviours..."); - Sensors sensors = new Sensors(ultraSonic, color, leftTouch, rightTouch); + SensorCollector sensors = new SensorCollector(ultraSonic, color, leftTouch, rightTouch); } } \ No newline at end of file diff --git a/dsl/runtime/src/nl/ru/des/ReactiveBehaviour.java b/dsl/runtime/src/nl/ru/des/ReactiveBehaviour.java deleted file mode 100644 index 9837e3c..0000000 --- a/dsl/runtime/src/nl/ru/des/ReactiveBehaviour.java +++ /dev/null @@ -1,24 +0,0 @@ -package nl.ru.des; - -import lejos.hardware.motor.EV3LargeRegulatedMotor; -import nl.ru.des.Sensors; - -public abstract class ReactiveBehaviour extends BasicBehaviour { - protected boolean suppressed; - protected Sensors sensors; - - public ReactiveBehaviour(Sensors sensors, EV3LargeRegulatedMotor leftMotor, EV3LargeRegulatedMotor rightMotor) { - super(sensors, leftMotor, rightMotor); - this.sensors = sensors; - } - - @Override - public void action() { - suppressed = false; - } - - @Override - public void suppress() { - suppressed = true; - } -} \ No newline at end of file diff --git a/dsl/runtime/src/nl/ru/des/Sensors.java b/dsl/runtime/src/nl/ru/des/SensorCollector.java similarity index 89% rename from dsl/runtime/src/nl/ru/des/Sensors.java rename to dsl/runtime/src/nl/ru/des/SensorCollector.java index 1b014d8..7695ee0 100644 --- a/dsl/runtime/src/nl/ru/des/Sensors.java +++ b/dsl/runtime/src/nl/ru/des/SensorCollector.java @@ -2,14 +2,14 @@ package nl.ru.des; import lejos.robotics.SampleProvider; -public class Sensors{ +public class SensorCollector{ public static final int DELAY = 50; private SampleProvider ultrasone, color, leftTouch, rightTouch; private float[] ultrasoneSamples, colorSamples, leftTouchSamples, rightTouchSamples; private long ultrasoneTime, colorTime, leftTouchTime, rightTouchTime; - public Sensors(SampleProvider ultrasone, + public SensorCollector(SampleProvider ultrasone, SampleProvider color, SampleProvider leftTouch, SampleProvider rightTouch){ @@ -27,7 +27,7 @@ public class Sensors{ rightTouchTime = System.currentTimeMillis(); } - public float getDistance(){ + public float distance(){ if(System.currentTimeMillis()-ultrasoneTime>DELAY){ ultrasone.fetchSample(ultrasoneSamples, 0); ultrasoneTime = System.currentTimeMillis(); @@ -35,7 +35,7 @@ public class Sensors{ return ultrasoneSamples[0]; } - public int getColor(){ + public int color(){ if(System.currentTimeMillis()-colorTime>DELAY){ color.fetchSample(colorSamples, 0); colorTime = System.currentTimeMillis(); @@ -43,7 +43,7 @@ public class Sensors{ return (int)colorSamples[0]; } - public boolean getLeftTouch(){ + public boolean leftTouch(){ if(System.currentTimeMillis()-leftTouchTime>DELAY){ leftTouch.fetchSample(leftTouchSamples, 0); leftTouchTime = System.currentTimeMillis(); @@ -51,7 +51,7 @@ public class Sensors{ return leftTouchSamples[0]==1; } - public boolean getRightTouch(){ + public boolean rightTouch(){ if(System.currentTimeMillis()-rightTouchTime>DELAY){ rightTouch.fetchSample(rightTouchSamples, 0); rightTouchTime = System.currentTimeMillis(); diff --git a/dsl/runtime/src/robots/missions/GenerateTaskDSL.mwe2 b/dsl/runtime/src/robots/missions/GenerateTaskDSL.mwe2 deleted file mode 100644 index cddc57c..0000000 --- a/dsl/runtime/src/robots/missions/GenerateTaskDSL.mwe2 +++ /dev/null @@ -1,133 +0,0 @@ -module robots.missions.GenerateTaskDSL - -import org.eclipse.emf.mwe.utils.* -import org.eclipse.xtext.generator.* -import org.eclipse.xtext.ui.generator.* - -var grammarURI = "classpath:/robots/missions/TaskDSL.xtext" -var fileExtensions = "tdsl" -var projectName = "desdsl" -var runtimeProject = "../${projectName}" -var generateXtendStub = true -var encoding = "UTF-8" - -Workflow { - bean = StandaloneSetup { - scanClassPath = true - platformUri = "${runtimeProject}/.." - // The following two lines can be removed, if Xbase is not used. - registerGeneratedEPackage = "org.eclipse.xtext.xbase.XbasePackage" - registerGenModelFile = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel" - } - - component = DirectoryCleaner { - directory = "${runtimeProject}/src-gen" - } - - component = DirectoryCleaner { - directory = "${runtimeProject}/model/generated" - } - - component = DirectoryCleaner { - directory = "${runtimeProject}.ui/src-gen" - } - - component = DirectoryCleaner { - directory = "${runtimeProject}.tests/src-gen" - } - - component = Generator { - pathRtProject = runtimeProject - pathUiProject = "${runtimeProject}.ui" - pathTestProject = "${runtimeProject}.tests" - projectNameRt = projectName - projectNameUi = "${projectName}.ui" - encoding = encoding - language = auto-inject { - uri = grammarURI - - // Java API to access grammar elements (required by several other fragments) - fragment = grammarAccess.GrammarAccessFragment auto-inject {} - - // generates Java API for the generated EPackages - fragment = ecore.EMFGeneratorFragment auto-inject {} - - // the old serialization component - // fragment = parseTreeConstructor.ParseTreeConstructorFragment auto-inject {} - - // serializer 2.0 - fragment = serializer.SerializerFragment auto-inject { - generateStub = false - } - - // a custom ResourceFactory for use with EMF - fragment = resourceFactory.ResourceFactoryFragment auto-inject {} - - // The antlr parser generator fragment. - fragment = parser.antlr.XtextAntlrGeneratorFragment auto-inject { - // options = { - // backtrack = true - // } - } - - // Xtend-based API for validation - fragment = validation.ValidatorFragment auto-inject { - // composedCheck = "org.eclipse.xtext.validation.ImportUriValidator" - // composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator" - } - - // old scoping and exporting API - // fragment = scoping.ImportURIScopingFragment auto-inject {} - // fragment = exporting.SimpleNamesFragment auto-inject {} - - // scoping and exporting API - fragment = scoping.ImportNamespacesScopingFragment auto-inject {} - fragment = exporting.QualifiedNamesFragment auto-inject {} - fragment = builder.BuilderIntegrationFragment auto-inject {} - - // generator API - fragment = generator.GeneratorFragment auto-inject {} - - // formatter API - fragment = formatting.FormatterFragment auto-inject {} - - // labeling API - fragment = labeling.LabelProviderFragment auto-inject {} - - // outline API - fragment = outline.OutlineTreeProviderFragment auto-inject {} - fragment = outline.QuickOutlineFragment auto-inject {} - - // quickfix API - fragment = quickfix.QuickfixProviderFragment auto-inject {} - - // content assist API - fragment = contentAssist.ContentAssistFragment auto-inject {} - - // generates a more lightweight Antlr parser and lexer tailored for content assist - fragment = parser.antlr.XtextAntlrUiGeneratorFragment auto-inject {} - - // generates junit test support classes into Generator#pathTestProject - fragment = junit.Junit4Fragment auto-inject {} - - // rename refactoring - fragment = refactoring.RefactorElementNameFragment auto-inject {} - - // provides the necessary bindings for java types integration - fragment = types.TypesGeneratorFragment auto-inject {} - - // generates the required bindings only if the grammar inherits from Xbase - fragment = xbase.XbaseGeneratorFragment auto-inject {} - - // generates the required bindings only if the grammar inherits from Xtype - fragment = xbase.XtypeGeneratorFragment auto-inject {} - - // provides a preference page for template proposals - fragment = templates.CodetemplatesGeneratorFragment auto-inject {} - - // provides a compare view - fragment = compare.CompareFragment auto-inject {} - } - } -} - diff --git a/dsl/runtime/src/robots/missions/TaskDSL.xtext b/dsl/runtime/src/robots/missions/TaskDSL.xtext deleted file mode 100644 index 54426ad..0000000 --- a/dsl/runtime/src/robots/missions/TaskDSL.xtext +++ /dev/null @@ -1,65 +0,0 @@ -grammar robots.missions.TaskDSL with org.eclipse.xtext.common.Terminals - -generate taskDSL "http://www.missions.robots/TaskDSL" - -Robot: - 'Name' name=ID - 'Acceleration' acc=INT - 'Speed' spd=INT - 'LeftMotor plugged in' leftMotorPort=MotorPort - 'RightMotor plugged in' righMotorPort=MotorPort - ('ColorSensor plugged in' colorSensorPort=SensorPort)? - ('TouchSensor plugged in' leftTouchSensorPort=SensorPort 'and' rightTouchSensorPort=SensorPort)? - ('UltrasoneSensor plugged in' ultrasoneSensorPort=SensorPort)? - ('Mission:' mission+=Mission)+; - -Mission: - behaviours+=Behaviour+ 'stops when' stoppingCondition=StoppingCondition -; - -StoppingCondition: - SensorLimitReached | CollectedColors; - -CollectedColors: - 'Collected Colors:' colors+=ColorValue+ -; - -SensorLimitReached: - TouchLimit | ColorLimit | DistanceLimit; - -ColorLimit: - 'ColorLimit: ' lim=ColorValue -; - -TouchLimit: - 'TouchStatus: ' lim=Touch -; - -Touch: - 'Touch' | 'NoTouch' -; - -DistanceLimit: - 'Distance:' dist=STRING 'meter' -; - -ColorValue: - 'Black' | 'Blue' | 'Brown' | 'Cyan' | 'DarkGray' | 'Gray' | 'Green' | 'LightGray' | 'Magenta' | 'Orange' | 'Pink' | 'Red' | 'White' | 'Yellow' -; - -Behaviour: - 'Behaviour' - 'Name:' name=ID - 'TakeControl:' takeControl=SensorLimitReached? - 'Action:' action=Action -; - -Action: - 'Avoid' | 'Wander' | 'Nothing' -; - -SensorPort: - 'S1' | 'S2' | 'S3' | 'S4'; - -MotorPort: - 'A' | 'B' | 'C' | 'D'; \ No newline at end of file diff --git a/dsl/runtime/src/robots/missions/TaskDSLRuntimeModule.java b/dsl/runtime/src/robots/missions/TaskDSLRuntimeModule.java deleted file mode 100644 index 2401334..0000000 --- a/dsl/runtime/src/robots/missions/TaskDSLRuntimeModule.java +++ /dev/null @@ -1,11 +0,0 @@ -/* - * generated by Xtext - */ -package robots.missions; - -/** - * Use this class to register components to be used at runtime / without the Equinox extension registry. - */ -public class TaskDSLRuntimeModule extends robots.missions.AbstractTaskDSLRuntimeModule { - -} diff --git a/dsl/runtime/src/robots/missions/TaskDSLStandaloneSetup.java b/dsl/runtime/src/robots/missions/TaskDSLStandaloneSetup.java deleted file mode 100644 index 08ec4c9..0000000 --- a/dsl/runtime/src/robots/missions/TaskDSLStandaloneSetup.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * generated by Xtext - */ -package robots.missions; - -/** - * Initialization support for running Xtext languages - * without equinox extension registry - */ -public class TaskDSLStandaloneSetup extends TaskDSLStandaloneSetupGenerated{ - - public static void doSetup() { - new TaskDSLStandaloneSetup().createInjectorAndDoEMFRegistration(); - } -} - diff --git a/dsl/runtime/src/robots/missions/formatting/TaskDSLFormatter.xtend b/dsl/runtime/src/robots/missions/formatting/TaskDSLFormatter.xtend deleted file mode 100644 index 5d904cf..0000000 --- a/dsl/runtime/src/robots/missions/formatting/TaskDSLFormatter.xtend +++ /dev/null @@ -1,30 +0,0 @@ -/* - * generated by Xtext - */ -package robots.missions.formatting - -import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter -import org.eclipse.xtext.formatting.impl.FormattingConfig -// import com.google.inject.Inject; -// import robots.missions.services.TaskDSLGrammarAccess - -/** - * This class contains custom formatting declarations. - * - * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#formatting - * on how and when to use it. - * - * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example - */ -class TaskDSLFormatter extends AbstractDeclarativeFormatter { - -// @Inject extension TaskDSLGrammarAccess - - override protected void configureFormatting(FormattingConfig c) { -// It's usually a good idea to activate the following three statements. -// They will add and preserve newlines around comments -// c.setLinewrap(0, 1, 2).before(SL_COMMENTRule) -// c.setLinewrap(0, 1, 2).before(ML_COMMENTRule) -// c.setLinewrap(0, 1, 1).after(ML_COMMENTRule) - } -} diff --git a/dsl/runtime/src/robots/missions/generator/TaskDSLGenerator.xtend b/dsl/runtime/src/robots/missions/generator/TaskDSLGenerator.xtend deleted file mode 100644 index 2139ca5..0000000 --- a/dsl/runtime/src/robots/missions/generator/TaskDSLGenerator.xtend +++ /dev/null @@ -1,24 +0,0 @@ -/* - * generated by Xtext - */ -package robots.missions.generator - -import org.eclipse.emf.ecore.resource.Resource -import org.eclipse.xtext.generator.IGenerator -import org.eclipse.xtext.generator.IFileSystemAccess - -/** - * Generates code from your model files on save. - * - * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation - */ -class TaskDSLGenerator implements IGenerator { - - override void doGenerate(Resource resource, IFileSystemAccess fsa) { -// fsa.generateFile('greetings.txt', 'People to greet: ' + -// resource.allContents -// .filter(typeof(Greeting)) -// .map[name] -// .join(', ')) - } -} diff --git a/dsl/runtime/src/robots/missions/scoping/TaskDSLScopeProvider.xtend b/dsl/runtime/src/robots/missions/scoping/TaskDSLScopeProvider.xtend deleted file mode 100644 index 4267cce..0000000 --- a/dsl/runtime/src/robots/missions/scoping/TaskDSLScopeProvider.xtend +++ /dev/null @@ -1,15 +0,0 @@ -/* - * generated by Xtext - */ -package robots.missions.scoping - -/** - * This class contains custom scoping description. - * - * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping - * on how and when to use it. - * - */ -class TaskDSLScopeProvider extends org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider { - -} diff --git a/dsl/runtime/src/robots/missions/validation/TaskDSLValidator.xtend b/dsl/runtime/src/robots/missions/validation/TaskDSLValidator.xtend deleted file mode 100644 index 67fdc6e..0000000 --- a/dsl/runtime/src/robots/missions/validation/TaskDSLValidator.xtend +++ /dev/null @@ -1,25 +0,0 @@ -/* - * generated by Xtext - */ -package robots.missions.validation - -//import org.eclipse.xtext.validation.Check - -/** - * This class contains custom validation rules. - * - * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation - */ -class TaskDSLValidator extends AbstractTaskDSLValidator { - -// public static val INVALID_NAME = 'invalidName' -// -// @Check -// def checkGreetingStartsWithCapital(Greeting greeting) { -// if (!Character.isUpperCase(greeting.name.charAt(0))) { -// warning('Name should start with a capital', -// MyDslPackage.Literals.GREETING__NAME, -// INVALID_NAME) -// } -// } -} diff --git a/dsl/xtend/src/robots/missions/TaskDSL.xtext b/dsl/xtend/src/robots/missions/TaskDSL.xtext index 3302953..79128de 100644 --- a/dsl/xtend/src/robots/missions/TaskDSL.xtext +++ b/dsl/xtend/src/robots/missions/TaskDSL.xtext @@ -12,7 +12,7 @@ Robot: Mission: 'Mission' name=ID 'using' behaviours+=[Behaviour]+ 'and stops when' stoppingExpression=StoppingExpression; StoppingExpression: - '(' op=Operator s+=StoppingExpression s+=StoppingExpression* ')' | + '(' op=Operator s+=StoppingExpression s+=StoppingExpression+ ')' | scond=StoppingCondition ; @@ -32,11 +32,16 @@ Action: Time: time=INT 'ms' | {Time} 'forever'; -enum Direction: BACKWARDS = 'Backwards' | FORWARDS = 'Forwards'; -enum Operator: AND = 'and' | OR = 'or'; -enum Comparison: GE='>' | LE='<'; -enum LeftRight: LEFT='Left' | RIGHT='Right'; -enum Color: +Direction: d=DirectionE; +enum DirectionE: BACKWARDS = 'backward' | FORWARDS = 'forward'; +Operator: d=OperatorE; +enum OperatorE: AND = 'and' | OR = 'or'; +Comparison: d=ComparisonE; +enum ComparisonE: GE='>' | LE='<'; +LeftRight: d=LeftRightE; +enum LeftRightE: LEFT='left' | RIGHT='right'; +Color: d=ColorE; +enum ColorE: BLACK='Black' | BLUE='Blue' | BROWN='Brown' | CYAN='Cyan' | DARKGRAY='DarkGray' | GRAY='Gray' | GREEN='Green' | LIGHTGRAY='LightGray' | MAGENTA='Magenta' | ORANGE='Orange' | PINK='Pink' | diff --git a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend index 2139ca5..ec286e9 100644 --- a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend +++ b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend @@ -3,9 +3,14 @@ */ package robots.missions.generator +import org.eclipse.emf.common.util.EList import org.eclipse.emf.ecore.resource.Resource -import org.eclipse.xtext.generator.IGenerator import org.eclipse.xtext.generator.IFileSystemAccess +import org.eclipse.xtext.generator.IGenerator +import robots.missions.taskDSL.Behaviour +import robots.missions.taskDSL.OperatorE +import robots.missions.taskDSL.Robot +import robots.missions.taskDSL.StoppingExpression /** * Generates code from your model files on save. @@ -15,10 +20,80 @@ import org.eclipse.xtext.generator.IFileSystemAccess class TaskDSLGenerator implements IGenerator { override void doGenerate(Resource resource, IFileSystemAccess fsa) { -// fsa.generateFile('greetings.txt', 'People to greet: ' + -// resource.allContents -// .filter(typeof(Greeting)) -// .map[name] -// .join(', ')) + 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)) + } + } + + def makeBehaviours(EList list)''' +package nl.ru.des; + +import lejos.hardware.motor.EV3LargeRegulatedMotor; + +public class Behaviours{ + «FOR b : list» + public static class «b.name»Behaviour extends BasicBehaviour { + public «b.name»Behaviour(SensorCollector sensors, EV3LargeRegulatedMotor rightMotor, + EV3LargeRegulatedMotor leftMotor, ColorMemory colors){ + super(sensors, rightMotor, leftMotor, colors); + } + «IF b.tc != null» + @Override public boolean takeControl(){ + return «printExpression(b.tc)»; + } + «ENDIF» + + @Override public void action(){ + super.action(); + «FOR a : b.actions» + «IF a.whichMotor != null» + «IF a.acc > 0» + «a.whichMotor.d.toString()»Motor.setAcceleration(«a.acc»); + «a.whichMotor.d.toString()»Motor.setSpeed(«a.spd»); + «ENDIF» + «a.whichMotor.d.toString()»Motor.«a.dir.d.toString()»(); + «ELSE» + time = System.currentTimeMillis(); + while(!suppressed«IF a.time.time > 0» && System.currentTimeMillis()-time>«a.time.time»«ENDIF»){ + Thread.yield(); + } + «ENDIF» + «ENDFOR» + reset(); + } } + «ENDFOR» +} + ''' + + def CharSequence printExpression(StoppingExpression e)''' + «IF e.scond != null» + «IF !e.scond.colors.nullOrEmpty» + colors.containsAll(new int[]{«FOR c : e.scond.colors SEPARATOR ","»«c.d.ordinal»«ENDFOR»}) + «ELSEIF e.scond.touch != null» + sensors.«e.scond.touch.d.toString()»Touch() + «ELSEIF e.scond.op != null» + sensors.distance() «e.scond.op.d.toString()» «e.scond.dist» + «ELSEIF e.scond.color != null» + sensors.color() == «e.scond.color.d.ordinal» + «ENDIF» + «ELSE» + «IF e.op.d.equals(OperatorE.AND)» + «FOR ex : e.s BEFORE "(" SEPARATOR "&&" AFTER ")"»«printExpression(ex)»«ENDFOR» + «ELSE» + «FOR ex : e.s BEFORE "(" SEPARATOR "&&" AFTER ")"»«printExpression(ex)»«ENDFOR» + «ENDIF» + «ENDIF» + ''' + + def CharSequence makeConstants(Robot robot)''' +package nl.ru.des; + +public class Constants{ + public final static int speed = «robot.spd»; + public final static int acceleration = «robot.acc»; +}''' + }