1 package nl
.ru
.des
.behaviours
;
3 import lejos
.hardware
.motor
.EV3LargeRegulatedMotor
;
4 import lejos
.robotics
.Color
;
5 import lejos
.robotics
.SampleProvider
;
6 import lejos
.robotics
.subsumption
.Behavior
;
8 public class StayInFieldBehaviour
extends ReactiveBehaviour
implements Behavior
{
9 public static final long BACKWARDSTIME
= 250;
10 public static final long TURNTIME
= 250;
12 private EV3LargeRegulatedMotor leftMotor
, rightMotor
;
14 public StayInFieldBehaviour(SampleProvider color
, EV3LargeRegulatedMotor leftMotor
,
15 EV3LargeRegulatedMotor rightMotor
) {
17 this.leftMotor
= leftMotor
;
18 this.rightMotor
= rightMotor
;
22 public boolean takeControl() {
24 return samples
[0] == Color
.BLACK
;
28 public void action() {
30 int leftacc
= leftMotor
.getAcceleration();
31 int rightacc
= rightMotor
.getAcceleration();
32 leftMotor
.setAcceleration(10000);
33 rightMotor
.setAcceleration(10000);
35 rightMotor
.backward();
36 long time
= System
.currentTimeMillis();
37 while (!suppressed
&& System
.currentTimeMillis() - time
> BACKWARDSTIME
) {
42 rightMotor
.backward();
43 time
= System
.currentTimeMillis();
44 while (!suppressed
&& System
.currentTimeMillis() - time
> TURNTIME
) {
48 rightMotor
.stop(true);
49 leftMotor
.setAcceleration(leftacc
);
50 rightMotor
.setAcceleration(rightacc
);