3 import lejos
.hardware
.Button
;
4 import lejos
.hardware
.motor
.EV3LargeRegulatedMotor
;
5 import lejos
.hardware
.sensor
.EV3UltrasonicSensor
;
6 import lejos
.robotics
.SampleProvider
;
8 public class AvoidHighObjectBehaviour
extends AvoidBehaviour
{
9 private SampleProvider ultrasoneSample
;
10 private float[] samples
;
13 public AvoidHighObjectBehaviour(EV3LargeRegulatedMotor leftMotor
, EV3LargeRegulatedMotor rightMotor
,
14 EV3UltrasonicSensor ultraSone
) {
15 super(leftMotor
, rightMotor
, "detect.wav");
16 ultrasoneSample
= ultraSone
.getDistanceMode();
17 samples
= new float[ultrasoneSample
.sampleSize()];
21 private void calibrate(){
22 LCDPrinter
.print("Calibrate ultrasone, place object in the turn radius...");
23 Button
.waitForAnyPress();
24 ultrasoneSample
.fetchSample(samples
, 0);
26 LCDPrinter
.print("Limit: " + limit
);
30 public boolean takeControl() {
31 ultrasoneSample
.fetchSample(samples
, 0);
32 return samples
[0] < limit
;