From 095cdf6fc0cbad75c6057a401cbab23c18931a3d Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Wed, 6 Jan 2016 14:26:23 +0100 Subject: [PATCH] standard missions done --- dsl/runtime/specs/spec1.tdsl | 53 ----------------- dsl/runtime/specs/wander.tdsl | 58 ++++++++++++++++--- dsl/runtime/src/nl/ru/des/BasicBehaviour.java | 37 +++++++++++- .../nl/ru/des/sensors/SensorCollector.java | 8 ++- dsl/xtend/src/robots/missions/TaskDSL.xtext | 7 ++- .../missions/generator/TaskDSLGenerator.xtend | 7 ++- .../validation/TaskDSLValidator.xtend | 39 +++++-------- 7 files changed, 116 insertions(+), 93 deletions(-) delete mode 100644 dsl/runtime/specs/spec1.tdsl diff --git a/dsl/runtime/specs/spec1.tdsl b/dsl/runtime/specs/spec1.tdsl deleted file mode 100644 index ce35b55..0000000 --- a/dsl/runtime/specs/spec1.tdsl +++ /dev/null @@ -1,53 +0,0 @@ --Acceleration 1000 -Speed 200 -Behaviour Wander - take control: - action: - left motor forward - right motor forward - wait forever - measure lake - measure rock -Behaviour AvoidLowLeftObjects - take control: Touched on left - action: - left motor backward - right motor backward - wait 250 ms - right motor backward - left motor forward - wait 250 ms -Behaviour AvoidLowRightObjects - take control: Touched on right - action: - left motor backward - right motor backward - wait 250 ms - right motor forward - left motor backward - wait 250 ms -Behaviour AvoidHighObjects - take control: - action: - right motor forward - wait 250 ms -Behaviour StayInLine - take control: Color is Black - action: - right motor forward - left motor backward - wait 250 ms -Behaviour Measure - take control: - action: - measure rock - wait 250 ms -Mission Assignment -using - Wander - AvoidLowLeftObjects - AvoidLowRightObjects - AvoidHighObjects - StayInLine -and stops when - Collected at least Blue Green Yellow \ No newline at end of file diff --git a/dsl/runtime/specs/wander.tdsl b/dsl/runtime/specs/wander.tdsl index be30d5a..5b9c1a0 100644 --- a/dsl/runtime/specs/wander.tdsl +++ b/dsl/runtime/specs/wander.tdsl @@ -1,6 +1,12 @@ Acceleration 1000 Speed 150 +Behaviour Drive + take control: + action: + left motor forward + right motor forward + wait forever Behaviour Wander take control: action: @@ -34,7 +40,34 @@ Behaviour StayInFieldB Behaviour MeasureLake take control: (|| Color is Green Color is Blue Color is Red) action: - measure + measure Lake + +Behaviour LocateL + take control: Touched on left + action: + right motor forward + left motor backward + wait 500 ms + right motor forward + left motor forward + wait 1000 ms + +Behaviour LocateR + take control: Touched on right + action: + left motor forward + right motor backward + wait 500 ms + right motor forward + left motor forward + wait 1000 ms + +Behaviour Push + take control: (&& Touched on left Touched on right) + action: + left motor forward + right motor forward + wait 1000 ms Behaviour BumpL take control: Touched on left @@ -49,10 +82,21 @@ Behaviour BumpR right motor backward with speed 50 acceleration 1000 left motor backward wait 2000 ms + +Behaviour AvoidHigh + take control: Distance dangerous at front + action: + turn randomly 10 to 11 degrees -Mission findBlueLakeWhileAvoidingRocks - using Wander BumpR BumpL StayInFieldB StayInFieldL StayInFieldR and stops when Color is Blue -Mission findAllLakesAndMeasureThem - using Wander MeasureLake StayInFieldB StayInFieldL StayInFieldR and stops when Collected at least Green Blue Red -Mission justWander - using Wander StayInFieldB StayInFieldL StayInFieldR and stops when Color is Cyan \ No newline at end of file +//Mission pushRock +// using Drive LocateR LocateL Push StayInFieldB StayInFieldL StayInFieldR and stops when Never +Mission avoidHighRocks + using Drive AvoidHigh BumpR BumpL StayInFieldB StayInFieldL StayInFieldR and stops when Never +//Mission measureLake +// using Drive MeasureLake and stops when Never +//Mission findBlueLakeWhileAvoidingRocks +// using Wander BumpR BumpL StayInFieldB StayInFieldL StayInFieldR and stops when Color is Blue +//Mission findAllLakesAndMeasureThem +// using Wander MeasureLake StayInFieldB StayInFieldL StayInFieldR and stops when Collected at least Green Blue Red +//Mission justWander +// using Wander Wander StayInFieldB StayInFieldL StayInFieldR and stops when Color is Cyan \ No newline at end of file diff --git a/dsl/runtime/src/nl/ru/des/BasicBehaviour.java b/dsl/runtime/src/nl/ru/des/BasicBehaviour.java index 2a6240e..2de5ab3 100644 --- a/dsl/runtime/src/nl/ru/des/BasicBehaviour.java +++ b/dsl/runtime/src/nl/ru/des/BasicBehaviour.java @@ -31,7 +31,27 @@ public abstract class BasicBehaviour implements Behavior{ leftMotor.stop(true); } - protected void measure(){ + protected void measureLake(){ + long time = System.currentTimeMillis(); + rightMotor.backward(); + leftMotor.backward(); + while(System.currentTimeMillis()-time<500){ + Thread.yield(); + } + + rightMotor.stop(true); + leftMotor.stop(true); + rightMotor.setSpeed(25); + leftMotor.setSpeed(25); + if(sensors.leftLight() && !sensors.rightLight()){ + leftTurn(15); + } else if (sensors.rightLight() && !sensors.leftLight()){ + rightTurn(15); + } + + rightMotor.stop(true); + leftMotor.stop(true); + measMotor.backward(); while(!suppressed && !measMotor.isStalled()){ Thread.yield(); @@ -41,7 +61,8 @@ public abstract class BasicBehaviour implements Behavior{ Thread.yield(); } measMotor.stop(true); - rightTurn(90); + reset(); + rightTurn(45); } protected void turnRandom(int from, int to){ @@ -85,12 +106,24 @@ public abstract class BasicBehaviour implements Behavior{ public void action() { suppressed = false; finished = false; + rightMotor.setSpeed(Constants.speed); + rightMotor.setAcceleration(Constants.acceleration); + leftMotor.setSpeed(Constants.speed); + leftMotor.setAcceleration(Constants.acceleration); + rightMotor.stop(true); + leftMotor.stop(true); } @Override public void suppress() { suppressed = true; finished = true; + 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(){ diff --git a/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java index 59fe6cd..4597d92 100644 --- a/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java +++ b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java @@ -10,9 +10,9 @@ import lejos.robotics.SampleProvider; public class SensorCollector implements MessageHandler{ public static final int DELAY = 200; - private static final float DANGER_DISTANCE_FRONT = 0.15f; + private static final float DANGER_DISTANCE_FRONT = 0.175f; private static final float DANGER_DISTANCE_BACK = 0.035f; - private static final float DANGER_LIGHT = 0.45f; + private static final float DANGER_LIGHT = 0.40f; private Set collectedColors; @@ -45,6 +45,10 @@ public class SensorCollector implements MessageHandler{ rightLightTime = System.currentTimeMillis(); gyroTime = System.currentTimeMillis(); + color = -1; + leftTouch = false; + rightTouch = false; + frontUltra = Float.MAX_VALUE; collectedColors = new HashSet(); } diff --git a/dsl/xtend/src/robots/missions/TaskDSL.xtext b/dsl/xtend/src/robots/missions/TaskDSL.xtext index 14a834f..641e3c3 100644 --- a/dsl/xtend/src/robots/missions/TaskDSL.xtext +++ b/dsl/xtend/src/robots/missions/TaskDSL.xtext @@ -21,7 +21,8 @@ StoppingCondition: 'Touched on' touch=LeftRight | 'Light on' light=LeftRight | 'Distance dangerous at ' dist=BackFront | - 'Color is' color=Color; + 'Color is' color=Color | + {StoppingCondition} 'Never'; Behaviour: 'Behaviour' name=ID 'take control:' tc=StoppingExpression? @@ -30,7 +31,7 @@ Behaviour: 'Behaviour' name=ID Action: whichMotor=LeftRight 'motor' moveDir=Direction ('with speed' spd=INT 'acceleration' acc=INT)? | 'turn' turnType=Turn ('with speed' spd=INT 'acceleration' acc=INT)? | - {Action} 'measure'| + 'measure' rl=RockLake| 'wait' time=Time; Turn: @@ -41,7 +42,7 @@ Turn: Time: time=INT 'ms' | {Time} 'forever'; RockLake: d=RockLakeE; -enum RockLakeE: ROCK='rock' | LAKE='lake'; +enum RockLakeE: ROCK='Rock' | LAKE='Lake'; Direction: d=DirectionE; enum DirectionE: BACKWARDS = 'backward' | FORWARDS = 'forward'; Operator: d=OperatorE; diff --git a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend index f413af6..c11ade8 100644 --- a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend +++ b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend @@ -105,11 +105,10 @@ public class «b.name»Behaviour extends BasicBehaviour { turnRandom(«a.turnType.start», «a.turnType.end»); «ENDIF» «ELSE» - measure(); + measure«a.rl.d.toString()»(); «ENDIF» «ENDFOR» LCDPrinter.print("Stop: «b.name»"); - reset(); } } ''' @@ -134,6 +133,8 @@ public class Constants{ sensors.«e.scond.dist.d.toString()»Distance() «ELSEIF e.scond.color != null» sensors.color() == «e.scond.color.d.ordinal» + «ELSE» + false «ENDIF» «ELSEIF e.negscond != null» !(«printExpression(e.negscond)») @@ -142,6 +143,6 @@ public class Constants{ «FOR ex : e.s BEFORE "(" SEPARATOR "&&" AFTER ")"»«printExpression(ex)»«ENDFOR» «ELSE» «FOR ex : e.s BEFORE "(" SEPARATOR "||" AFTER ")"»«printExpression(ex)»«ENDFOR» - «ENDIF» + «ENDIF» «ENDIF»''' } \ No newline at end of file diff --git a/dsl/xtend/src/robots/missions/validation/TaskDSLValidator.xtend b/dsl/xtend/src/robots/missions/validation/TaskDSLValidator.xtend index 96fe5ac..f3926b5 100644 --- a/dsl/xtend/src/robots/missions/validation/TaskDSLValidator.xtend +++ b/dsl/xtend/src/robots/missions/validation/TaskDSLValidator.xtend @@ -10,30 +10,23 @@ package robots.missions.validation * 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) +// def checkOnlyOneBehaviourPerMissionEmptyTakeControl(Mission m) { +// var List empty = new LinkedList(); +// var List all = new LinkedList(); +// for(Behaviour b : m.behaviours){ +// if(b.tc == null){ +// empty.add(b.name); +// } +// all.add(b.name); +// } +// if(empty.size > 1){ +// warning("Multiple behaviours without takeControl predicate. You might want to remove some of: " + empty.toString(), m.eContainingFeature); +// } +// if(all.toSet().size() < all.size()){ +// warning("You have duplicate behaviours.", m, TaskDSLPackage.Literals::MISSION__BEHAVIOURS); // } // } -/* @Check - def checkStoppingExpressionShouldHaveOneBehaviourToCollectColor(Mission mission) { - var isCollectColorExist = false; - if (!mission.se.scond.colors.nullOrEmpty) { - var blist = mission.behaviours; - for (var j = 0; j < blist.size; j++) { - if (!blist.get(j).clcColor.nullOrEmpty) { - isCollectColorExist = true; - } - } - } - if (!isCollectColorExist) { - error("Must specify one behaviour to collect color", null) - } - }*/ + +//Validate if the random degrees are correct } -- 2.20.1