action:
right motor forward
left motor backward
- /*wait 500 ms
- right motor forward
- left motor forward
- wait 500ms*/
Behaviour PushR
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 PushB
take control: (&& Touched on left Touched on right)
set flag Pushing
left motor forward
right motor forward
- wait 10000 ms
+ wait forever
Behaviour StopPushing
take control: (&& not Touched on left not Touched on right flag set Pushing)
action:
set flag Pushed
-/*Mission FindAndMeasureLakes
+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
- and stops when flag set Measured */
+ and stops when flag set Measured
Mission PushRocks
using Wander PushL PushR PushB StopPushing StayInFieldR StayInFieldL StayInFieldB
and stops when flag set Pushed
\ No newline at end of file
}
rightMotor.stop(true);
leftMotor.stop(true);
- LCDPrinter.print(Float.toString(sensors.gyro()));
+ System.out.println(Float.toString(sensors.gyro()));
}
protected void leftTurn(int angle){
}
rightMotor.stop(true);
leftMotor.stop(true);
- LCDPrinter.print(Float.toString(sensors.gyro()));
+ System.out.println(Float.toString(sensors.gyro()));
}
@Override
@Override
public void keyPressed(Key k) {
- LCDPrinter.print("Bye");
+ System.out.println("Bye");
System.exit(0);
}
+++ /dev/null
-package nl.ru.des;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.util.Deque;
-import java.util.LinkedList;
-
-import lejos.hardware.lcd.TextLCD;
-import lejos.utility.Delay;
-
-public class LCDPrinter{
- public static final int PRINTDELAY = 50;
-
- private static class Message{
- public String msg;
- public boolean nl;
-
- public Message(String msg, boolean nl){
- this.msg = msg;
- this.nl = nl;
- }
- }
-
- private static Deque<Message> buffer = new LinkedList<Message>();
-
- public static void startLCDPrinter(final TextLCD glcd) {
- new Thread(new Runnable(){
- @Override
- public void run() {
- while (true) {
- if (!buffer.isEmpty()) {
- Message c = buffer.remove();
- if(c.msg.length() > glcd.getTextWidth()){
- buffer.addFirst(new Message(c.msg.substring(glcd.getTextWidth(), c.msg.length()), c.nl));
- c.msg = c.msg.substring(0, glcd.getTextWidth());
- }
- if(c.nl){
- glcd.scroll();
- } else {
- glcd.clear(glcd.getTextHeight()-1);
- }
- glcd.drawString(c.msg, 0, glcd.getTextHeight()-1);
- }
- Delay.msDelay(PRINTDELAY);
- }
- }
- }).start();
- LCDPrinter.print("LCDThread started");
- }
-
- public static void print(String s){
- print(s, true);
- }
-
- public synchronized static void print(String s, boolean nl){
- buffer.addLast(new Message(s, nl));
- }
-
- public static PrintStream getPrefixedPrintstream(final String prefix, final TextLCD glcd){
- return new PrintStream(new OutputStream(){
- private char[] line = new char[glcd.getTextWidth()];
- private int index = 0;
-
- @Override
- public void write(int b) throws IOException {
- if(index == line.length-prefix.length() || b == '\n'){
- LCDPrinter.print(prefix + String.valueOf(line, 0, index));
- index = 0;
- } else {
- line[index++] = (char)b;
- }
- }
- });
- }
-}
\ No newline at end of file
package nl.ru.des;
+import java.io.PrintStream;
import java.util.LinkedList;
import java.util.Random;
import lejos.hardware.ev3.EV3;
import lejos.hardware.ev3.LocalEV3;
import lejos.hardware.lcd.Font;
-import lejos.hardware.lcd.TextLCD;
+import lejos.hardware.lcd.LCDOutputStream;
import lejos.hardware.motor.EV3LargeRegulatedMotor;
import lejos.hardware.motor.EV3MediumRegulatedMotor;
import lejos.hardware.port.MotorPort;
@SuppressWarnings("resource")
public static void main(String[] args) {
EV3 brick = LocalEV3.get();
- TextLCD tlcd = brick.getTextLCD(Font.getSmallFont());
- LCDPrinter.startLCDPrinter(tlcd);
- System.setOut(LCDPrinter.getPrefixedPrintstream("out: ", tlcd));
- System.setErr(LCDPrinter.getPrefixedPrintstream("err: ", tlcd));
+ PrintStream lcd = new PrintStream(new LCDOutputStream(brick.getTextLCD(Font.getSmallFont())));
+ System.setOut(lcd);
+ System.setErr(lcd);
- LCDPrinter.print("Loading keylistener...");
+ System.out.println("Loading keylistener...");
brick.getKey("Escape").addKeyListener(new ButtonListener());
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...");
+ System.out.println("Starting as a slave...");
+ System.out.println("My name is " + brick.getName());
+ System.out.println("Loading touch sensors...");
SampleProvider leftTouch = new EV3TouchSensor(brick.getPort("S1")).getTouchMode();
SampleProvider rightTouch = new EV3TouchSensor(brick.getPort("S2")).getTouchMode();
- LCDPrinter.print("Loading ultrasone sensor...");
+ System.out.println("Loading ultrasone sensor...");
SampleProvider frontUltra = new EV3UltrasonicSensor(brick.getPort("S3")).getDistanceMode();
- LCDPrinter.print("Loading color sensors...");
+ System.out.println("Loading color sensors...");
SampleProvider color = new EV3ColorSensor(brick.getPort("S4")).getColorIDMode();
RemoteSensors rs = new RemoteSensors(leftTouch, rightTouch, frontUltra, color);
}
} 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...");
+ System.out.println("Starting as as master...");
+ System.out.println("My name is " + brick.getName());
+ System.out.println("Going to connect to: " + slave);
+ System.out.println("Loading motors...");
RegulatedMotor rightMotor = new EV3LargeRegulatedMotor(MotorPort.A);
RegulatedMotor leftMotor = new EV3LargeRegulatedMotor(MotorPort.B);
RegulatedMotor measMotor = new EV3MediumRegulatedMotor(MotorPort.C);
measMotor.setSpeed(50);
rightMotor.setAcceleration(Constants.acceleration);
leftMotor.setAcceleration(Constants.acceleration);
- measMotor.setAcceleration(100);
+ measMotor.setAcceleration(50);
- LCDPrinter.print("Loading touch sensors...");
+ System.out.println("Loading touch sensors...");
SampleProvider leftLight = new NXTLightSensor(brick.getPort("S1")).getRedMode();
SampleProvider rightLight = new NXTLightSensor(brick.getPort("S2")).getRedMode();
- LCDPrinter.print("Loading ultrasone sensor...");
+ System.out.println("Loading ultrasone sensor...");
SampleProvider backUltra = new EV3UltrasonicSensor(brick.getPort("S3")).getDistanceMode();
- LCDPrinter.print("Loading gyro sensor...");
+ System.out.println("Loading gyro sensor...");
SensorCollector sc = new SensorCollector(backUltra, leftLight, rightLight, new EV3GyroSensor(brick.getPort("S4")));
BTController.startMaster(slave, sc);
- LCDPrinter.print("Finished loading");
+ System.out.println("Finished loading");
sc.calibrate();
LinkedList<Mission> missions = Missions.getMissions(sc, rightMotor, leftMotor, measMotor);
random = new Random();
- LCDPrinter.print("Press any button to start");
+ System.out.println("Press any button to start");
Button.waitForAnyEvent();
for(Mission m : missions){
- LCDPrinter.print("Start " + m.name + " mission...");
+ System.out.println("Start " + m.name + " mission...");
arb = new Arbitrator(m.behaviours);
sc.reset();
- Sound.buzz();
arb.start();
- LCDPrinter.print(m.name + " finished!!1one!");
+ Sound.buzz();
+ System.out.println(m.name + " finished!!1one!");
}
System.exit(0);
}
public abstract class ShutdownBehaviour implements Behavior{
@Override public void action(){
- LCDPrinter.print("Terminate mission");
+ System.out.println("Terminate mission");
Marster.arb.stop();
}
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;
private static BTConnector btconnector;
public static void startMaster(final String slave, final MessageHandler sh) {
- LCDPrinter.print("Start BT... Press any key to commence");
+ System.out.println("Start BT... Press any key to commence");
Button.waitForAnyEvent();
btconnector = new BTConnector();
while(conn == null){
- LCDPrinter.print("Connecting to " + slave);
+ System.out.println("Connecting to " + slave);
conn = btconnector.connect(slave, NXTConnection.RAW);
}
dataOut = conn.openDataOutputStream();
}
public static void startSlave() {
- LCDPrinter.print("Start BT... Press any key to commence");
+ System.out.println("Start BT... Press any key to commence");
Button.waitForAnyEvent();
btconnector = new BTConnector();
while(conn == null){
- LCDPrinter.print("Waiting for the master...");
+ System.out.println("Waiting for the master...");
conn = btconnector.waitForConnection(60000, NXTConnection.RAW);
}
dataIn = conn.openDataInputStream();
import lejos.robotics.SampleProvider;
import lejos.utility.Delay;
-import nl.ru.des.LCDPrinter;
public class RemoteSensors{
public static final int DELAY = 200;
public void start(Queue<String> q){
long last = System.currentTimeMillis();
Delay.msDelay(1000);
- LCDPrinter.print("Start sending values...");
+ System.out.println("Start sending values...");
while(true){
if(System.currentTimeMillis()-last > DELAY && q.size()<5){
last = System.currentTimeMillis();
import lejos.hardware.sensor.EV3GyroSensor;
import lejos.robotics.SampleProvider;
import lejos.utility.Delay;
-import nl.ru.des.LCDPrinter;
public class SensorCollector implements MessageHandler{
public static final int DELAY = 200;
public void calibrate() {
- LCDPrinter.print("Put left light on Blue");
+ System.out.println("Put left light on Blue");
Button.waitForAnyEvent();
leftLight();
DANGER_LIGHT = leftLightSamples[0];
- LCDPrinter.print("Light limit: " + Float.toString(DANGER_LIGHT));
+ System.out.println("Light limit: " + Float.toString(DANGER_LIGHT));
Delay.msDelay(350);
- LCDPrinter.print("Put left light on Black");
+ System.out.println("Put left light on Black");
Button.waitForAnyEvent();
leftLight();
DANGER_LIGHT = (leftLightSamples[0]+DANGER_LIGHT)/2.0f;
- LCDPrinter.print("Light limit: " + Float.toString(DANGER_LIGHT));
+ System.out.println("Light limit: " + Float.toString(DANGER_LIGHT));
Delay.msDelay(350);
- LCDPrinter.print("Place back ultra safe");
+ System.out.println("Place back ultra safe");
Button.waitForAnyEvent();
backDistance();
DANGER_DISTANCE_BACK = ultraSamples[0] + 0.05f;
- LCDPrinter.print("Back ultra limit: " + Float.toString(DANGER_DISTANCE_BACK));
+ System.out.println("Back ultra limit: " + Float.toString(DANGER_DISTANCE_BACK));
Delay.msDelay(350);
- LCDPrinter.print("Place front ultra in danger");
+ System.out.println("Place front ultra in danger");
Button.waitForAnyEvent();
DANGER_DISTANCE_FRONT = frontUltra;
- LCDPrinter.print("Calibration done");
- LCDPrinter.print("Front ultra limit: " + Float.toString(DANGER_DISTANCE_FRONT));
+ System.out.println("Calibration done");
+ System.out.println("Front ultra limit: " + Float.toString(DANGER_DISTANCE_FRONT));
}
//Local sensors
«ENDIF»
@Override public void action(){
- LCDPrinter.print("Start: «b.name»");
+ System.out.println("Start: «b.name»");
super.action();
«FOR a : b.actions»
«IF a.whichMotor != null»
}
«ENDIF»
«ENDFOR»
- LCDPrinter.print("Stop: «b.name»");
+ System.out.print("Stop: «b.name»");
}
}
'''