-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoveForward.java
69 lines (58 loc) · 1.41 KB
/
MoveForward.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
import lejos.nxt.LCD;
import lejos.nxt.LightSensor;
import lejos.nxt.UltrasonicSensor;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.robotics.subsumption.Behavior;
public class MoveForward implements Behavior
{
private boolean suppressed = false;
private DifferentialPilot pilot;
private LightSensor lightSensor;
private UltrasonicSensor ultrasonicSensor;
// /**
// * Constructor to set the left and right motor position
// */
// public MoveForward(final DifferentialPilot pilot)
// {
// this.pilot = pilot;
// }
/**
* Constructor to set the left and right motor position
*/
public MoveForward(final DifferentialPilot pilot,
final LightSensor lightSensor,
final UltrasonicSensor ultrasonicSensor)
{
this.pilot = pilot;
this.lightSensor = lightSensor;
this.ultrasonicSensor = ultrasonicSensor;
}
@Override
public boolean takeControl()
{
/*
* always true if we want to keep the bot moving when no obstacle are
* present atm - lowest priority
*/
return true;
}
@Override
public void action()
{
suppressed = false;
LCD.drawInt(lightSensor.getLightValue(), 8, 1);
LCD.drawInt(ultrasonicSensor.getDistance(), 8, 2);
// move forward
pilot.forward();
while (!suppressed)
{
Thread.yield();
}
pilot.stop();
}
@Override
public void suppress()
{
suppressed = true;
}
}