From: Mart Lubbers Date: Tue, 12 Jan 2016 14:38:05 +0000 (+0100) Subject: final push X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=e8a3f6d576e6ab6d62d8c363e28d7ec18d381b8f;p=des2015.git final push --- diff --git a/dsl/runtime/specs/wander.tdsl b/dsl/runtime/specs/wander.tdsl index 1dc70fd..f7e3697 100644 --- a/dsl/runtime/specs/wander.tdsl +++ b/dsl/runtime/specs/wander.tdsl @@ -39,19 +39,19 @@ Behaviour StayInFieldB wait 1000 ms Behaviour GreenLake - take control: (&& Color is Green not flag set GreenMeasured) + take control: (&& (|| Color is Green Color is Yellow) not flag set GreenLake) action: measure Lake set flag GreenLake Behaviour BlueLake - take control: (&& Color is Blue not flag set BlueMeasured) + take control: (&& Color is Blue not flag set BlueLake) action: measure Lake set flag BlueLake Behaviour RedLake - take control: (&& Color is Red not flag set RedMeasured) + take control: (&& Color is Red not flag set RedLake) action: measure Lake set flag RedLake @@ -61,18 +61,30 @@ Behaviour MeasureRock action: measure Rock set flag Measured + +Behaviour AvoidL + take control: Touched on left + action: + left motor forward + right motor backward + +Behaviour AvoidR + take control: Touched on right + action: + right motor forward + left motor backward Behaviour PushL take control: Touched on left action: right motor forward - left motor backward + left motor forward with speed 50 acceleration 1000 Behaviour PushR take control: Touched on right action: left motor forward - right motor backward + right motor forward with speed 50 acceleration 1000 Behaviour PushB take control: (&& Touched on left Touched on right) @@ -85,23 +97,33 @@ Behaviour PushB Behaviour StopPushing take control: (&& not Touched on left not Touched on right flag set Pushing) action: + left motor backward + right motor backward + wait 1000ms + turn left exactly 180 degrees set flag Pushed Behaviour FoundLineL - take control: Light on left + take control: (&& (|| not flag set LeftLine not flag set RightLine) Light on left not Light on right Color is Black) action: + left motor backward with speed 75 acceleration 1000 + right motor backward with speed 75 acceleration 1000 + wait 1000 ms set flag LeftLine Behaviour FoundLineR - take control: Light on right + take control: (&& (|| not flag set LeftLine not flag set RightLine) Light on right not Light on left Color is Black) action: + left motor backward with speed 75 acceleration 1000 + right motor backward with speed 75 acceleration 1000 + wait 1000 ms set flag RightLine Behaviour FollowLGood take control: (&& flag set LeftLine Light on left) action: left motor forward with speed 75 acceleration 1000 - right motor backward with speed 50 acceleration 1000 + right motor backward with speed 60 acceleration 1000 Behaviour FollowLBad take control: (&& flag set LeftLine not Light on left) @@ -113,7 +135,7 @@ Behaviour FollowRGood take control: (&& flag set RightLine Light on right) action: right motor forward with speed 75 acceleration 1000 - left motor backward with speed 50 acceleration 1000 + left motor backward with speed 60 acceleration 1000 Behaviour FollowRBad take control: (&& flag set RightLine not Light on right) @@ -122,20 +144,19 @@ Behaviour FollowRBad left motor forward with speed 100 acceleration 1000 Behaviour FoundParkingSpace - take control: (&& (|| flag set LeftLine flag set RightLine) Color is White)// (|| Light on left Light on right)) + take control: (&& (|| flag set LeftLine flag set RightLine) Color is White) action: set flag Parked - /* -Mission FindAndMeasureLakes - using Wander StayInFieldR StayInFieldL StayInFieldB GreenLake RedLake BlueLake - and stops when (&& flag set GreenLake flag set RedLake flag set BlueLake) Mission FindAndMeasureRocks - using Wander StayInFieldR StayInFieldL StayInFieldB MeasureRock + using Drive StayInFieldR StayInFieldL StayInFieldB AvoidL AvoidR MeasureRock and stops when flag set Measured +Mission FindAndMeasureLakes + using Drive StayInFieldR StayInFieldL StayInFieldB AvoidL AvoidR GreenLake RedLake BlueLake + and stops when (&& flag set GreenLake flag set RedLake flag set BlueLake) Mission PushRocks - using Wander PushL PushR PushB StopPushing StayInFieldR StayInFieldL StayInFieldB - and stops when flag set Pushed*/ + using Drive PushL PushR PushB StayInFieldR StayInFieldL StayInFieldB StopPushing + and stops when flag set Pushed Mission Park - using Drive FoundLineL FoundLineR FollowLBad FollowLGood FollowRBad FollowRGood FoundParkingSpace + using Drive FoundLineL FoundLineR FollowLBad FollowLGood FollowRBad FollowRGood StayInFieldB FoundParkingSpace and stops when flag set Parked \ 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 b5d4bc1..945a709 100644 --- a/dsl/runtime/src/nl/ru/des/BasicBehaviour.java +++ b/dsl/runtime/src/nl/ru/des/BasicBehaviour.java @@ -45,32 +45,38 @@ public abstract class BasicBehaviour implements Behavior{ rightMotor.setSpeed(25); leftMotor.setSpeed(25); if(sensors.leftLight() && !sensors.rightLight()){ - leftTurn(15); + leftTurn(10); } else if (sensors.rightLight() && !sensors.leftLight()){ - rightTurn(15); + rightTurn(10); } rightMotor.stop(true); leftMotor.stop(true); - measMotor.backward(); - while(!suppressed && !measMotor.isStalled()){ + measMotor.rotate(-100, true); + while(!suppressed && !measMotor.isStalled() && measMotor.isMoving()){ Thread.yield(); } - measMotor.forward(); - while(!suppressed && !measMotor.isStalled()){ + measMotor.rotate(100, true); + while(!suppressed && !measMotor.isStalled() && measMotor.isMoving()){ Thread.yield(); } measMotor.stop(true); - turnRandom(30, 45); + reset(); + rightMotor.backward(); + leftMotor.backward(); + while(System.currentTimeMillis()-time < 250){ + Thread.yield(); + } + turnRandom(45, 60); } protected void measureRock(){ long time = System.currentTimeMillis(); rightMotor.forward(); leftMotor.forward(); - while(System.currentTimeMillis()-time<1500){ + while(System.currentTimeMillis()-time<1000){ Thread.yield(); } @@ -87,6 +93,11 @@ public abstract class BasicBehaviour implements Behavior{ } measMotor.stop(true); + rightMotor.backward(); + leftMotor.backward(); + while(System.currentTimeMillis()-time<1000){ + Thread.yield(); + } turnRandom(30, 45); } diff --git a/dsl/runtime/src/nl/ru/des/Marster.java b/dsl/runtime/src/nl/ru/des/Marster.java index 16dd328..a5c47c7 100644 --- a/dsl/runtime/src/nl/ru/des/Marster.java +++ b/dsl/runtime/src/nl/ru/des/Marster.java @@ -1,10 +1,10 @@ package nl.ru.des; +import java.io.File; import java.io.PrintStream; import java.util.LinkedList; import java.util.Random; -import lejos.hardware.Button; import lejos.hardware.Sound; import lejos.hardware.ev3.EV3; import lejos.hardware.ev3.LocalEV3; @@ -20,6 +20,7 @@ import lejos.hardware.sensor.EV3UltrasonicSensor; import lejos.hardware.sensor.NXTLightSensor; import lejos.robotics.RegulatedMotor; import lejos.robotics.SampleProvider; +import lejos.utility.Delay; import nl.ru.des.sensors.BTController; import nl.ru.des.sensors.RemoteSensors; import nl.ru.des.sensors.SensorCollector; @@ -28,6 +29,44 @@ public class Marster { public static Arbitrator arb; public static Random random; + public static void playPacman(){ + int whole = 2000; + Sound.playNote(Sound.PIANO, 494, whole/16);// b4 + Sound.playNote(Sound.PIANO, 988, whole/16);// b5 + Sound.playNote(Sound.PIANO, 740, whole/16);// f#5 + Sound.playNote(Sound.PIANO, 622, whole/16);// eb5 + Sound.playNote(Sound.PIANO, 988, whole/32);// b5 + Sound.playNote(Sound.PIANO, 740, whole/16+whole/32);// f#5 + Sound.playNote(Sound.PIANO, 622, whole/8);// eb5 + + Sound.playNote(Sound.PIANO, 523, whole/16);// c5 + Sound.playNote(Sound.PIANO, 1047, whole/16);// c6 + Sound.playNote(Sound.PIANO, 784, whole/16);// g5 + Sound.playNote(Sound.PIANO, 659, whole/16);// e5 + Sound.playNote(Sound.PIANO, 1047, whole/32);// c6 + Sound.playNote(Sound.PIANO, 784, whole/16+whole/32);// g5 + Sound.playNote(Sound.PIANO, 659, whole/8);// e5 + + Sound.playNote(Sound.PIANO, 494, whole/16);// b4 + Sound.playNote(Sound.PIANO, 988, whole/16);// b5 + Sound.playNote(Sound.PIANO, 740, whole/16);// f#5 + Sound.playNote(Sound.PIANO, 622, whole/16);// eb5 + Sound.playNote(Sound.PIANO, 988, whole/32);// b5 + Sound.playNote(Sound.PIANO, 740, whole/16+whole/32);// f#5 + Sound.playNote(Sound.PIANO, 622, whole/8);// eb5 + + Sound.playNote(Sound.PIANO, 622, whole/32);// eb5 + Sound.playNote(Sound.PIANO, 659, whole/32);// e5 + Sound.playNote(Sound.PIANO, 698, whole/16);// f5 + Sound.playNote(Sound.PIANO, 698, whole/32);// f5 + Sound.playNote(Sound.PIANO, 740, whole/32);// f#5 + Sound.playNote(Sound.PIANO, 784, whole/16);// g5 + Sound.playNote(Sound.PIANO, 784, whole/32);// g5 + Sound.playNote(Sound.PIANO, 831, whole/32);// ab5 + Sound.playNote(Sound.PIANO, 880, whole/16);// a5 + Sound.playNote(Sound.PIANO, 988, whole/8);// b5 + } + @SuppressWarnings("resource") public static void main(String[] args) { EV3 brick = LocalEV3.get(); @@ -37,7 +76,6 @@ public class Marster { System.out.println("Loading keylistener..."); brick.getKey("Escape").addKeyListener(new ButtonListener()); - if(brick.getName().equalsIgnoreCase("Rover6") || brick.getName().equalsIgnoreCase("Rover8")){ System.out.println("Starting as a slave..."); System.out.println("My name is " + brick.getName()); @@ -89,16 +127,18 @@ public class Marster { sc.calibrate(); LinkedList missions = Missions.getMissions(sc, rightMotor, leftMotor, measMotor); random = new Random(); - System.out.println("Press any button to start"); - Button.waitForAnyEvent(); + Delay.msDelay(2000); + playPacman(); for(Mission m : missions){ System.out.println("Start " + m.name + " mission..."); arb = new Arbitrator(m.behaviours); sc.reset(); arb.start(); Sound.buzz(); + Delay.msDelay(5000); System.out.println(m.name + " finished!!1one!"); } + Sound.playSample(new File("rick.wav"), Sound.VOL_MAX); System.exit(0); } } diff --git a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend index 16aa0e6..1df66c0 100644 --- a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend +++ b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend @@ -38,6 +38,7 @@ import java.util.LinkedList; import lejos.robotics.subsumption.Behavior; import lejos.robotics.RegulatedMotor; +import lejos.robotics.Color; import nl.ru.des.sensors.SensorCollector; @@ -64,6 +65,7 @@ public class Missions{ package nl.ru.des; import lejos.robotics.RegulatedMotor; +import lejos.robotics.Color; import nl.ru.des.sensors.SensorCollector; public class «b.name»Behaviour extends BasicBehaviour { @@ -136,7 +138,7 @@ public class Constants{ «ELSEIF e.scond.dist != null» sensors.«e.scond.dist.d.toString()»Distance() «ELSEIF e.scond.color != null» - sensors.color() == «e.scond.color.d.ordinal» + sensors.color() == Color.«e.scond.color.d.getName()» «ELSE» false «ENDIF» diff --git a/marsrover/rick.wav b/marsrover/rick.wav new file mode 100644 index 0000000..9e46ce1 Binary files /dev/null and b/marsrover/rick.wav differ