3 import lejos
.hardware
.motor
.EV3LargeRegulatedMotor
;
4 import lejos
.robotics
.subsumption
.Behavior
;
6 public class StayInFieldBehaviour
implements Behavior
{
7 public static final long BACKWARDSTIME
= 250;
8 public static final long TURNTIME
= 250;
10 private ColorSensor colorSensor
;
11 private EV3LargeRegulatedMotor leftMotor
, rightMotor
;
12 private boolean suppressed
;
14 public StayInFieldBehaviour(ColorSensor colorSensor
, EV3LargeRegulatedMotor leftMotor
, EV3LargeRegulatedMotor rightMotor
) {
15 this.colorSensor
= colorSensor
;
16 this.leftMotor
= leftMotor
;
17 this.rightMotor
= rightMotor
;
21 public boolean takeControl() {
22 return colorSensor
.getCurrentColor() == "Black";
26 public void action() {
28 int leftacc
= leftMotor
.getAcceleration();
29 int rightacc
= rightMotor
.getAcceleration();
30 leftMotor
.setAcceleration(10000);
31 rightMotor
.setAcceleration(10000);
33 rightMotor
.backward();
34 long time
= System
.currentTimeMillis();
35 while(!suppressed
&& System
.currentTimeMillis()-time
> BACKWARDSTIME
){
40 rightMotor
.backward();
41 time
= System
.currentTimeMillis();
42 while(!suppressed
&& System
.currentTimeMillis()-time
> TURNTIME
){
46 rightMotor
.stop(true);
47 leftMotor
.setAcceleration(leftacc
);
48 rightMotor
.setAcceleration(rightacc
);
52 public void suppress() {