5 import lejos
.hardware
.motor
.EV3LargeRegulatedMotor
;
6 import lejos
.hardware
.sensor
.EV3TouchSensor
;
7 import lejos
.robotics
.SampleProvider
;
8 import lejos
.utility
.Delay
;
10 public class AvoidLowObjectBehaviour
extends AvoidBehaviour
{
11 private SampleProvider rightSample
, leftSample
;
12 private float[] samples
;
13 private long lastPush
= 0;
15 public AvoidLowObjectBehaviour(EV3LargeRegulatedMotor leftMotor
, EV3LargeRegulatedMotor rightMotor
,
16 EV3TouchSensor leftTouch
, EV3TouchSensor rightTouch
) {
17 super(leftMotor
, rightMotor
, new File("bump.wav"));
18 rightSample
= rightTouch
.getTouchMode();
19 leftSample
= leftTouch
.getTouchMode();
20 samples
= new float[rightTouch
.sampleSize()];
24 public boolean takeControl() {
25 //Check if left sensor is pressed
26 leftSample
.fetchSample(samples
, 0);
27 boolean takeControl
= false;
29 super.setAvoidDirection(false);
31 lastPush
= System
.currentTimeMillis();
34 //Check if right sensor is pressed
35 rightSample
.fetchSample(samples
, 0);
37 super.setAvoidDirection(true);
39 lastPush
= System
.currentTimeMillis();
41 return takeControl
|| System
.currentTimeMillis()-lastPush
< 1000;
45 public void action() {
46 rightMotor
.backward();