Behaviour StayInFieldL
take control: Light on left
action:
- right motor backward with speed 250 acceleration 10000
- left motor forward with speed 250 acceleration 10000
- wait 750 ms
+ turn right 90 with speed 100 acceleration 10000
Behaviour StayInFieldR
take control: Light on right
action:
- right motor forward with speed 250 acceleration 10000
- left motor backward with speed 250 acceleration 10000
- wait 750 ms
+ turn left 90 with speed 100 acceleration 10000
Behaviour StayInFieldB
take control: Distance dangerous at back
action:
import nl.ru.des.sensors.SensorCollector;
public abstract class BasicBehaviour implements Behavior{
- protected boolean suppressed;
+ protected int suppressed;
protected RegulatedMotor leftMotor, rightMotor, measMotor;
protected SensorCollector sensors;
protected long time;
leftMotor.setAcceleration(Constants.acceleration);
rightMotor.stop(true);
leftMotor.stop(true);
+ suppressed = 0;
}
protected void rockMeasure(){
}
protected void rightTurn(int angle){
-
+ float init = sensors.gyro();
+ rightMotor.backward();
+ leftMotor.forward();
+
+ while(suppressed != 2 && sensors.gyro()-90>init){
+ Thread.yield();
+ }
}
protected void leftTurn(int angle){
-
+ float init = sensors.gyro();
+ leftMotor.backward();
+ rightMotor.forward();
+ while(suppressed != 2 && sensors.gyro()+90<init){
+ Thread.yield();
+ }
}
@Override
public void action() {
- suppressed = false;
+ suppressed = 1;
}
@Override
public void suppress() {
- suppressed = true;
+ suppressed = 2;
}
- @Override
- public boolean takeControl() {
+ @Override public boolean takeControl(){
return true;
}
}
gyroTime = System.currentTimeMillis();
}
- public void debug(){
- new Thread(){
- @Override public void run(){
- while(true){
- ultra.fetchSample(ultraSamples, 0);
- leftLight.fetchSample(leftLightSamples, 0);
- rightLight.fetchSample(rightLightSamples, 0);
- LCD.drawString("back: " + Float.toString(ultraSamples[0]), 0, 1);
- LCD.drawString("front: " + Float.toString(frontUltra), 0, 2);
- LCD.drawString("left: " + Float.toString(leftLightSamples[0]), 0, 3);
- LCD.drawString("right: " + Float.toString(rightLightSamples[0]), 0, 4);
- Delay.msDelay(250);
- }
- }
- }.run();
- }
-
//Local sensors
public boolean backDistance(){
if(System.currentTimeMillis()-ultraTime>DELAY){
import robots.missions.taskDSL.Behaviour
import robots.missions.taskDSL.Mission
import robots.missions.taskDSL.OperatorE
-import robots.missions.taskDSL.Robot
import robots.missions.taskDSL.StoppingExpression
+import robots.missions.taskDSL.Robot
/**
* Generates code from your model files on save.
}
«IF b.tc != null»
@Override public boolean takeControl(){
- return !suppressed || «printExpression(b.tc)»;
+ return suppressed == 1 || «printExpression(b.tc)»;
}
«ENDIF»
«ELSEIF a.measureWhat != null»
«a.measureWhat.d.toString()»Measure();
«ELSEIF a.turnDir != null»
+ «IF a.acc > 0»
+ leftMotor.setAcceleration(«a.acc»);
+ leftMotor.setSpeed(«a.spd»);
+ rightMotor.setAcceleration(«a.acc»);
+ rightMotor.setSpeed(«a.spd»);
+ «ENDIF»
«a.turnDir.d.toString()»Turn(«a.degrees»);
«ELSE»
time = System.currentTimeMillis();
- while(!suppressed«IF a.time.time > 0» && System.currentTimeMillis()-time>«a.time.time»«ENDIF»){
+ while(suppressed != 2«IF a.time.time > 0» && System.currentTimeMillis()-time>«a.time.time»«ENDIF»){
Thread.yield();
}
«ENDIF»