-
Notifications
You must be signed in to change notification settings - Fork 0
/
UltraSonicDemo.java
76 lines (51 loc) · 1.81 KB
/
UltraSonicDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package lejos;
import ev3.exercises.library.*;
import lejos.hardware.Button;
import lejos.hardware.Sound;
import lejos.hardware.port.SensorPort;
import lejos.hardware.motor.Motor;
import lejos.robotics.chassis.Chassis;
import lejos.robotics.chassis.Wheel;
import lejos.robotics.chassis.WheeledChassis;
import lejos.robotics.navigation.MovePilot;
import lejos.utility.Delay;
public class UltraSonicDemo {
MovePilot pilot;
public static void main(String[] args) {
float range;
UltraSonicSensor uss = new UltraSonicSensor(SensorPort.S4);
System.out.println("Press any key to start");
Button.LEDPattern(4); // flash green led and
Sound.beepSequenceUp(); // make sound when ready.
Button.waitForAnyPress();
range = uss.getRange();
Lcd.print(7, "range=");
Wheel leftWheel = WheeledChassis.modelWheel(Motor.A,2.8).offset(-10.0);
Wheel rightWheel = WheeledChassis.modelWheel(Motor.B, 2.8).offset(10.0);
Chassis myChassis = new WheeledChassis(new Wheel[] { leftWheel, rightWheel }, WheeledChassis.TYPE_DIFFERENTIAL);
UltraSonicDemo usd = new UltraSonicDemo();
usd.pilot = new MovePilot(myChassis);
while (range > .25 && Button.ESCAPE.isUp()) {
// usd.pilot.setLinearSpeed(20);
if( range> 0.25) {
usd.pilot.travel(10);
range = uss.getRange();
}
range = uss.getRange();
Lcd.print(3, "Press Escape twice to Stop");
Lcd.print(7, 7, "%.3f", range);
while (range < 0.25 && Button.ESCAPE.isUp()) {
usd.pilot.rotate(-35);
range = uss.getRange();
if (range < 0.25 && Button.ESCAPE.isUp()) {
usd.pilot.rotate(70);
range = uss.getRange();
}
}
}
// free up resources.
uss.close();
Sound.beepSequence(); // we are done.
// Button.waitForAnyPress();
}
}