Fixed shutdown behaviour and added print expression
authorNatanael Adityasatria <nata.adit@gmail.com>
Mon, 7 Dec 2015 12:28:08 +0000 (13:28 +0100)
committerNatanael Adityasatria <nata.adit@gmail.com>
Mon, 7 Dec 2015 12:28:08 +0000 (13:28 +0100)
dsl/runtime/specs/spec1.tdsl
dsl/runtime/src/nl/ru/des/ShutdownBehaviour.java
dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend

index bfa224f..d3271c0 100644 (file)
@@ -32,11 +32,16 @@ Behaviour AvoidHighObjects
                right motor forward
                wait 250 ms
 Behaviour StayInLine
-       take control: (or Color is Black Color is DarkGray)
+       take control: Color is Black
        action:
                right motor forward
                left motor backward
                wait 250 ms
+Behaviour Meassure
+       take control: 
+       action:
+               measure rock
+               wait 250 ms
 Mission Assignment 
 using 
        Wander 
index 4e9e5aa..ae75647 100644 (file)
@@ -5,8 +5,8 @@ import nl.ru.des.sensors.SensorCollector;
 
 public class ShutdownBehaviour extends BasicBehaviour{
        public ShutdownBehaviour(SensorCollector sensors, EV3LargeRegulatedMotor leftMotor,
-                       EV3LargeRegulatedMotor rightMotor) {
-               super(sensors, leftMotor, rightMotor);
+                       EV3LargeRegulatedMotor rightMotor, EV3LargeRegulatedMotor measMotor) {
+               super(sensors, leftMotor, rightMotor, measMotor);
        }
        
        @Override public void action(){
index 06f9654..0e85304 100644 (file)
@@ -9,7 +9,9 @@ import org.eclipse.xtext.generator.IFileSystemAccess
 import org.eclipse.xtext.generator.IGenerator
 import robots.missions.taskDSL.Behaviour
 import robots.missions.taskDSL.Mission
+import robots.missions.taskDSL.OperatorE
 import robots.missions.taskDSL.Robot
+import robots.missions.taskDSL.StoppingExpression
 
 /**
  * Generates code from your model files on save.
@@ -71,7 +73,7 @@ public class Behaviours{
                }
                «IF b.tc != null»
                @Override public boolean takeControl(){
-                       return ;
+                       return «printExpression(b.tc)»;
                }
                «ENDIF»
                
@@ -99,7 +101,6 @@ public class Behaviours{
        «ENDFOR»
 }
        '''
-
        
        def CharSequence makeConstants(Robot robot)'''
 package nl.ru.des;
@@ -109,4 +110,23 @@ public class Constants{
        public final static int acceleration = «robot.acc»;
 }'''
        
+       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»})
+               «ELSEIF e.scond.touch != null»
+               sensors.«e.scond.touch.d.toString()»Touch()
+               «ELSEIF e.scond.dist != null»
+               sensors.distance() «e.scond.dist.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»
+       '''
 }
\ No newline at end of file