From: Mart Lubbers Date: Wed, 9 Dec 2015 11:58:34 +0000 (+0100) Subject: bt working, different behaviours X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=476c651adb42cd9be8758e4f6ef2fe9ee2519fd5;p=des2015.git bt working, different behaviours --- diff --git a/dsl/runtime/src/nl/ru/des/BasicBehaviour.java b/dsl/runtime/src/nl/ru/des/BasicBehaviour.java index c91e613..d67f83b 100644 --- a/dsl/runtime/src/nl/ru/des/BasicBehaviour.java +++ b/dsl/runtime/src/nl/ru/des/BasicBehaviour.java @@ -1,23 +1,23 @@ package nl.ru.des; -import lejos.hardware.motor.EV3LargeRegulatedMotor; +import lejos.robotics.RegulatedMotor; import lejos.robotics.subsumption.Behavior; import nl.ru.des.sensors.SensorCollector; public abstract class BasicBehaviour implements Behavior{ protected boolean suppressed; - protected EV3LargeRegulatedMotor leftMotor, rightMotor, measMotor; + protected RegulatedMotor leftMotor, rightMotor, measMotor; protected SensorCollector sensors; protected long time; - public BasicBehaviour(SensorCollector sensors, EV3LargeRegulatedMotor leftMotor, - EV3LargeRegulatedMotor rightMotor, EV3LargeRegulatedMotor measMotor){ + public BasicBehaviour(SensorCollector sensors, RegulatedMotor leftMotor, + RegulatedMotor rightMotor, RegulatedMotor measMotor){ this.leftMotor = leftMotor; this.rightMotor = rightMotor; this.measMotor = measMotor; this.sensors = sensors; } - + protected void reset(){ rightMotor.setSpeed(Constants.speed); rightMotor.setAcceleration(Constants.acceleration); diff --git a/dsl/runtime/src/nl/ru/des/Marster.java b/dsl/runtime/src/nl/ru/des/Marster.java index 6fc32e8..6353904 100644 --- a/dsl/runtime/src/nl/ru/des/Marster.java +++ b/dsl/runtime/src/nl/ru/des/Marster.java @@ -6,12 +6,14 @@ import lejos.hardware.ev3.LocalEV3; import lejos.hardware.lcd.Font; import lejos.hardware.lcd.TextLCD; import lejos.hardware.motor.EV3LargeRegulatedMotor; +import lejos.hardware.motor.EV3MediumRegulatedMotor; import lejos.hardware.port.MotorPort; import lejos.hardware.sensor.EV3ColorSensor; import lejos.hardware.sensor.EV3GyroSensor; import lejos.hardware.sensor.EV3TouchSensor; import lejos.hardware.sensor.EV3UltrasonicSensor; import lejos.hardware.sensor.NXTLightSensor; +import lejos.robotics.RegulatedMotor; import lejos.robotics.SampleProvider; import lejos.robotics.subsumption.Arbitrator; import nl.ru.des.sensors.BTController; @@ -34,6 +36,7 @@ public class Marster { if(brick.getName().equalsIgnoreCase("Rover6") || brick.getName().equalsIgnoreCase("Rover8")){ LCDPrinter.print("Starting as a slave..."); + LCDPrinter.print("My name is " + brick.getName()); LCDPrinter.print("Loading touch sensors..."); SampleProvider leftTouch = new EV3TouchSensor(brick.getPort("S1")).getTouchMode(); SampleProvider rightTouch = new EV3TouchSensor(brick.getPort("S2")).getTouchMode(); @@ -45,16 +48,17 @@ public class Marster { SampleProvider color = new EV3ColorSensor(brick.getPort("S4")).getColorIDMode(); RemoteSensors rs = new RemoteSensors(leftTouch, rightTouch, frontUltra, color); - LCDPrinter.print("Start BT... Press any key to commence"); - Button.waitForAnyEvent(); BTController.startSlave(); rs.start(BTController.buf); } else { + String slave = brick.getName().equalsIgnoreCase("Rover5") ? "Rover6" : "Rover8"; LCDPrinter.print("Starting as as master..."); + LCDPrinter.print("My name is " + brick.getName()); + LCDPrinter.print("Going to connect to: " + slave); LCDPrinter.print("Loading motors..."); - EV3LargeRegulatedMotor rightMotor = new EV3LargeRegulatedMotor(MotorPort.A); - EV3LargeRegulatedMotor leftMotor = new EV3LargeRegulatedMotor(MotorPort.B); - EV3LargeRegulatedMotor measMotor = new EV3LargeRegulatedMotor(MotorPort.C); + RegulatedMotor rightMotor = new EV3LargeRegulatedMotor(MotorPort.A); + RegulatedMotor leftMotor = new EV3LargeRegulatedMotor(MotorPort.B); + RegulatedMotor measMotor = new EV3MediumRegulatedMotor(MotorPort.C); // leftMotor.setSpeed(Constants.speed); // rightMotor.setSpeed(Constants.speed); // measMotor.setSpeed(100); @@ -72,9 +76,7 @@ public class Marster { LCDPrinter.print("Loading gyro sensor..."); SampleProvider gyro = new EV3GyroSensor(brick.getPort("S4")).getAngleAndRateMode(); - LCDPrinter.print("Start BT... Press any key to commence"); - Button.waitForAnyEvent(); - BTController.startMaster(brick.getName() == "Rover5" ? "Rover6" : "Rover8", new SensorCollector(backUltra, leftLight, rightLight, gyro)); + BTController.startMaster(slave, new SensorCollector(backUltra, leftLight, rightLight, gyro)); LCDPrinter.print("Finished loading"); Button.waitForAnyPress(); // Arbitrator a; diff --git a/dsl/runtime/src/nl/ru/des/sensors/BTController.java b/dsl/runtime/src/nl/ru/des/sensors/BTController.java index 206552e..062fa61 100644 --- a/dsl/runtime/src/nl/ru/des/sensors/BTController.java +++ b/dsl/runtime/src/nl/ru/des/sensors/BTController.java @@ -6,17 +6,26 @@ import java.io.IOException; import java.util.LinkedList; import java.util.Queue; +import lejos.hardware.Button; import lejos.remote.nxt.BTConnector; import lejos.remote.nxt.NXTConnection; +import nl.ru.des.LCDPrinter; public class BTController{ public static Queue buf; - public static DataInputStream dataIn; - public static DataOutputStream dataOut; + private static DataInputStream dataIn; + private static DataOutputStream dataOut; + private static NXTConnection conn; + private static BTConnector btconnector; public static void startMaster(final String slave, final MessageHandler sh) { - BTConnector btconnector = new BTConnector(); - NXTConnection conn = btconnector.connect(slave, NXTConnection.RAW); + LCDPrinter.print("Start BT... Press any key to commence"); + Button.waitForAnyEvent(); + btconnector = new BTConnector(); + while(conn == null){ + LCDPrinter.print("Connecting to " + slave); + conn = btconnector.connect(slave, NXTConnection.RAW); + } dataOut = conn.openDataOutputStream(); dataIn = conn.openDataInputStream(); new Thread() { @@ -41,8 +50,13 @@ public class BTController{ } public static void startSlave() { - BTConnector btconnector = new BTConnector(); - NXTConnection conn = btconnector.waitForConnection(60000, NXTConnection.RAW); + LCDPrinter.print("Start BT... Press any key to commence"); + Button.waitForAnyEvent(); + btconnector = new BTConnector(); + while(conn == null){ + LCDPrinter.print("Waiting for the master..."); + conn = btconnector.waitForConnection(60000, NXTConnection.RAW); + } dataIn = conn.openDataInputStream(); dataOut = conn.openDataOutputStream(); buf = new LinkedList(); diff --git a/dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java b/dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java index d25adb3..2075512 100644 --- a/dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java +++ b/dsl/runtime/src/nl/ru/des/sensors/RemoteSensors.java @@ -3,6 +3,7 @@ package nl.ru.des.sensors; import java.util.Queue; import lejos.robotics.SampleProvider; +import lejos.utility.Delay; import nl.ru.des.LCDPrinter; public class RemoteSensors{ @@ -28,6 +29,7 @@ public class RemoteSensors{ public void start(Queue q){ long last = System.currentTimeMillis(); + Delay.msDelay(1000); LCDPrinter.print("Start sending values..."); while(true){ if(System.currentTimeMillis()-last > DELAY && q.size()<5){ @@ -38,13 +40,13 @@ public class RemoteSensors{ q.add(Integer.toString(RemoteSensorEnum.LEFT.ordinal())+Integer.toString((int)leftLatest)+"\n"); } right.fetchSample(rightSamples, 0); + if(rightSamples[0] != rightLatest){ rightLatest = rightSamples[0]; q.add(Integer.toString(RemoteSensorEnum.RIGHT.ordinal())+Integer.toString((int)rightLatest)+"\n"); } - ultra.fetchSample(ultraSamples, 0); - if(ultraSamples[0] != ultraLatest){ + if(Math.abs(ultraSamples[0] - ultraLatest) > 0.025){ ultraLatest = ultraSamples[0]; q.add(Integer.toString(RemoteSensorEnum.ULTRA.ordinal())+Float.toString(ultraLatest)+"\n"); } diff --git a/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java index 3faae09..60652d8 100644 --- a/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java +++ b/dsl/runtime/src/nl/ru/des/sensors/SensorCollector.java @@ -1,6 +1,7 @@ package nl.ru.des.sensors; import lejos.robotics.SampleProvider; +import nl.ru.des.LCDPrinter; public class SensorCollector implements MessageHandler{ public static final int DELAY = 300; @@ -85,6 +86,7 @@ public class SensorCollector implements MessageHandler{ @Override public void handleMessage(String m) { + LCDPrinter.print("Sensor: " + Character.toString(m.charAt(0)) + " with value: " + m.substring(1)); String s = m.substring(1); switch(RemoteSensors.RemoteSensorEnum.values()[Integer.valueOf(Character.toString(m.charAt(0)))]){ case COLOR: diff --git a/dsl/xtend/src/robots/missions/TaskDSL.xtext b/dsl/xtend/src/robots/missions/TaskDSL.xtext index 1dd8afd..65351f9 100644 --- a/dsl/xtend/src/robots/missions/TaskDSL.xtext +++ b/dsl/xtend/src/robots/missions/TaskDSL.xtext @@ -28,12 +28,13 @@ Behaviour: 'Behaviour' name=ID 'action:' actions+=Action+; Action: - whichMotor=LeftRight 'motor' dir=Direction ('with speed' spd=INT 'acceleration' acc=INT)? | + whichMotor=LeftRight 'motor' moveDir=Direction ('with speed' spd=INT 'acceleration' acc=INT)? | + 'turn' turnDir=LeftRight degrees=INT ('with speed' spd=INT 'acceleration' acc=INT)? | 'measure' measureWhat=RockLake | 'wait' time=Time; Time: time=INT 'ms' | {Time} 'forever'; - + RockLake: d=RockLakeE; enum RockLakeE: ROCK='rock' | LAKE='lake'; Direction: d=DirectionE; diff --git a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend index 0e85304..84a1261 100644 --- a/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend +++ b/dsl/xtend/src/robots/missions/generator/TaskDSLGenerator.xtend @@ -24,7 +24,9 @@ class TaskDSLGenerator implements IGenerator { 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)); + for(Behaviour b : root.behaviour){ + fsa.generateFile("nl/ru/des/" + b.name + "Behaviour.java", makeBehaviour(b)); + } //fsa.generateFile("nl/ru/des/Missions.java", makeMissions(root.mission)); } } @@ -58,47 +60,43 @@ public class Missions{ } ''' - def CharSequence makeBehaviours(EList list)''' + def CharSequence makeBehaviour(Behaviour b)''' package nl.ru.des; -import lejos.hardware.motor.EV3LargeRegulatedMotor; +import lejos.robotics.RegulatedMotor; import nl.ru.des.sensors.SensorCollector; -public class Behaviours{ - «FOR b : list» - public static class «b.name»Behaviour extends BasicBehaviour { - public «b.name»Behaviour(SensorCollector sensors, EV3LargeRegulatedMotor rightMotor, - EV3LargeRegulatedMotor leftMotor, EV3LargeRegulatedMotor measMotor){ - super(sensors, rightMotor, leftMotor, measMotor); - } - «IF b.tc != null» - @Override public boolean takeControl(){ - return «printExpression(b.tc)»; +public class «b.name»Behaviour extends BasicBehaviour { + public «b.name»Behaviour(SensorCollector sensors, RegulatedMotor rightMotor, + RegulatedMotor leftMotor, RegulatedMotor measMotor){ + super(sensors, rightMotor, leftMotor, measMotor); + } + «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()»(); - «ELSEIF a.measureWhat != null» - «a.measureWhat.d.toString()»Measure(); - «ELSE» - time = System.currentTimeMillis(); - while(!suppressed«IF a.time.time > 0» && System.currentTimeMillis()-time>«a.time.time»«ENDIF»){ - Thread.yield(); - } + «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» - «ENDFOR» - reset(); - } + «a.whichMotor.d.toString()»Motor.«a.moveDir.d.toString()»(); + «ELSEIF a.measureWhat != null» + «a.measureWhat.d.toString()»Measure(); + «ELSE» + time = System.currentTimeMillis(); + while(!suppressed«IF a.time.time > 0» && System.currentTimeMillis()-time>«a.time.time»«ENDIF»){ + Thread.yield(); + } + «ENDIF» + «ENDFOR» + reset(); } - «ENDFOR» } ''' diff --git a/marsrover/document/dev.tex b/marsrover/document/dev.tex index eafb75f..305da04 100644 --- a/marsrover/document/dev.tex +++ b/marsrover/document/dev.tex @@ -7,7 +7,7 @@ and results. The iterations and their deliverables are listed in \autoref{tab:devit}. The schedule for finishing iterations are listed in \autoref{tab:deadli}. On the 6th of January the must-have should be finished and if they are we try to complete as many iterations as possible. -\begin{table}[h!] +\begin{table}[H] \centering \begin{tabu} to \linewidth{llX} \toprule @@ -22,7 +22,7 @@ and if they are we try to complete as many iterations as possible. \end{tabu} \caption{Deadlines}\label{tab:deadli} \end{table} -\begin{table}[h!] +\begin{table}[H] \centering \begin{tabu} to \linewidth{rlXX} \toprule diff --git a/marsrover/document/map.tex b/marsrover/document/map.tex index 746bda5..686e483 100644 --- a/marsrover/document/map.tex +++ b/marsrover/document/map.tex @@ -7,7 +7,7 @@ movement are placed on the master brick too. All other sensors are placed on the slave brick. Any increased latency on those sensors will not danger the safety. The final mapping is described in \autoref{tab:mapping}. -\begin{table}[h] +\begin{table}[H] \centering \begin{tabular}{lll} \toprule diff --git a/marsrover/document/preamble.tex b/marsrover/document/preamble.tex index 4942b2e..d9442c7 100644 --- a/marsrover/document/preamble.tex +++ b/marsrover/document/preamble.tex @@ -8,6 +8,7 @@ \usepackage{longtable} % For page spanning tables \usepackage{multirow} % For multirow tables \usepackage{tabu} % For nicer automatic spanning tables +\usepackage{float} % For better table and figure placement \title{MarsRover proposal} \author{Natanael Adityasatria (s4417992)\and Mart Lubbers (s4109503)}