push
authorMart Lubbers <mart@martlubbers.net>
Thu, 10 Dec 2015 15:33:10 +0000 (16:33 +0100)
committerMart Lubbers <mart@martlubbers.net>
Thu, 10 Dec 2015 15:33:10 +0000 (16:33 +0100)
dsl/runtime/specs/wander.tdsl
dsl/runtime/src/nl/ru/des/BasicBehaviour.java
dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java
dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend

index 5100e52..a51a064 100644 (file)
@@ -16,15 +16,11 @@ Behaviour StayInFieldBoth
 Behaviour StayInFieldL
        take control: Light on left
        action:
-               right motor backward with speed 250 acceleration 10000
-               left motor forward with speed 250 acceleration 10000
-               wait 750 ms
+               turn right 90 with speed 100 acceleration 10000
 Behaviour StayInFieldR
        take control: Light on right
        action:
-               right motor forward with speed 250 acceleration 10000
-               left motor backward with speed 250 acceleration 10000
-               wait 750 ms
+               turn left 90 with speed 100 acceleration 10000
 Behaviour StayInFieldB
        take control: Distance dangerous at back
        action:
index 1d79edd..9b7742b 100644 (file)
@@ -5,7 +5,7 @@ import lejos.robotics.subsumption.Behavior;
 import nl.ru.des.sensors.SensorCollector;
 
 public abstract class BasicBehaviour implements Behavior{
-       protected boolean suppressed;
+       protected int suppressed;
        protected RegulatedMotor leftMotor, rightMotor, measMotor;
        protected SensorCollector sensors;
        protected long time;
@@ -25,6 +25,7 @@ public abstract class BasicBehaviour implements Behavior{
                leftMotor.setAcceleration(Constants.acceleration);
                rightMotor.stop(true);
                leftMotor.stop(true);
+               suppressed = 0;
        }
 
        protected void rockMeasure(){
@@ -36,25 +37,35 @@ public abstract class BasicBehaviour implements Behavior{
        }
        
        protected void rightTurn(int angle){
-               
+               float init = sensors.gyro();
+               rightMotor.backward();
+               leftMotor.forward();
+
+               while(suppressed != 2 && sensors.gyro()-90>init){
+                       Thread.yield();
+               }
        }
        
        protected void leftTurn(int angle){
-               
+               float init = sensors.gyro();
+               leftMotor.backward();
+               rightMotor.forward();
+               while(suppressed != 2 && sensors.gyro()+90<init){
+                       Thread.yield();
+               }
        }
        
        @Override
        public void action() {
-               suppressed = false;
+               suppressed = 1;
        }
 
        @Override
        public void suppress() {
-               suppressed = true;
+               suppressed = 2;
        }
        
-       @Override
-       public boolean takeControl() {
+       @Override public boolean takeControl(){
                return true;
        }
 }
index 29433c1..a9c2048 100644 (file)
@@ -39,23 +39,6 @@ public class SensorCollector implements MessageHandler{
                gyroTime = System.currentTimeMillis();
        }
        
-       public void debug(){
-               new Thread(){
-                       @Override public void run(){
-                               while(true){
-                                       ultra.fetchSample(ultraSamples, 0);
-                                       leftLight.fetchSample(leftLightSamples, 0);
-                                       rightLight.fetchSample(rightLightSamples, 0);
-                                       LCD.drawString("back: " + Float.toString(ultraSamples[0]), 0, 1);
-                                       LCD.drawString("front: " + Float.toString(frontUltra), 0, 2);
-                                       LCD.drawString("left: " + Float.toString(leftLightSamples[0]), 0, 3);
-                                       LCD.drawString("right: " + Float.toString(rightLightSamples[0]), 0, 4);
-                                       Delay.msDelay(250);
-                               }
-                       }
-               }.run();
-       }
-       
        //Local sensors
        public boolean backDistance(){
                if(System.currentTimeMillis()-ultraTime>DELAY){
index e57aea6..b4c56ae 100644 (file)
@@ -10,8 +10,8 @@ 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
+import robots.missions.taskDSL.Robot
 
 /**
  * Generates code from your model files on save.
@@ -73,7 +73,7 @@ public class «b.name»Behaviour extends BasicBehaviour {
        }
        «IF b.tc != null»
        @Override public boolean takeControl(){
-               return !suppressed || «printExpression(b.tc)»;
+               return suppressed == 1 || «printExpression(b.tc)»;
        }
        «ENDIF»
        
@@ -89,10 +89,16 @@ public class «b.name»Behaviour extends BasicBehaviour {
                        «ELSEIF a.measureWhat != null»
                        «a.measureWhat.d.toString()»Measure();
                        «ELSEIF a.turnDir != null»
+                               «IF a.acc > 0»
+                                       leftMotor.setAcceleration(«a.acc»);
+                                       leftMotor.setSpeed(«a.spd»);
+                                       rightMotor.setAcceleration(«a.acc»);
+                                       rightMotor.setSpeed(«a.spd»);
+                               «ENDIF»
                        «a.turnDir.d.toString()»Turn(«a.degrees»);
                        «ELSE»
                        time = System.currentTimeMillis();
-                       while(!suppressed«IF a.time.time > 0» && System.currentTimeMillis()-time>«a.time.time»«ENDIF»){
+                       while(suppressed != 2«IF a.time.time > 0» && System.currentTimeMillis()-time>«a.time.time»«ENDIF»){
                                Thread.yield(); 
                        }
                        «ENDIF»