updated lcd printer and better low object avoidance behaviour
[des2015.git] / mart / ev3 / ex1 / nl / ru / des / AvoidHighObjectBehaviour.java
1 package nl.ru.des;
2
3 import lejos.hardware.Button;
4 import lejos.hardware.motor.EV3LargeRegulatedMotor;
5 import lejos.hardware.sensor.EV3UltrasonicSensor;
6 import lejos.robotics.SampleProvider;
7
8 public class AvoidHighObjectBehaviour extends AvoidBehaviour {
9 private SampleProvider ultrasoneSample;
10 private float[] samples;
11 private float limit;
12
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()];
18 calibrate();
19 }
20
21 private void calibrate(){
22 LCDPrinter.print("Calibrate ultrasone, place object in the turn radius...");
23 Button.waitForAnyPress();
24 ultrasoneSample.fetchSample(samples, 0);
25 limit = samples[0];
26 LCDPrinter.print("Limit: " + limit);
27 }
28
29 @Override
30 public boolean takeControl() {
31 ultrasoneSample.fetchSample(samples, 0);
32 return samples[0] < limit;
33 }
34 }