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);
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;
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();
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);
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;
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<String> 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() {
}
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<String>();
import java.util.Queue;
import lejos.robotics.SampleProvider;
+import lejos.utility.Delay;
import nl.ru.des.LCDPrinter;
public class RemoteSensors{
public void start(Queue<String> q){
long last = System.currentTimeMillis();
+ Delay.msDelay(1000);
LCDPrinter.print("Start sending values...");
while(true){
if(System.currentTimeMillis()-last > DELAY && q.size()<5){
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");
}
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;
@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:
'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;
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));
}
}
}
'''
- def CharSequence makeBehaviours(EList<Behaviour> 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»
}
'''
\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
\end{tabu}
\caption{Deadlines}\label{tab:deadli}
\end{table}
-\begin{table}[h!]
+\begin{table}[H]
\centering
\begin{tabu} to \linewidth{rlXX}
\toprule
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
\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)}