-
Notifications
You must be signed in to change notification settings - Fork 0
/
LegoRunner.java
65 lines (58 loc) · 1.7 KB
/
LegoRunner.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
import lejos.nxt.LCD;
import lejos.nxt.LightSensor;
import lejos.nxt.Motor;
import lejos.nxt.SensorPort;
import lejos.nxt.TouchSensor;
import lejos.nxt.UltrasonicSensor;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.robotics.subsumption.Arbitrator;
import lejos.robotics.subsumption.Behavior;
public class LegoRunner
{
public void move()
{
TouchSensor bump = new TouchSensor(SensorPort.S2);
UltrasonicSensor ultrasonicSensor = new UltrasonicSensor(SensorPort.S1);
LightSensor lightSensor = new LightSensor(SensorPort.S4);
DifferentialPilot pilot = new DifferentialPilot(5.6, 11, Motor.C,
Motor.B);
LCD.drawString(ultrasonicSensor.getUnits(), 8, 7);
//behavors
Behavior moveForward = new MoveForward(pilot, lightSensor,
ultrasonicSensor);
Behavior changeDirection = new ChangeDirection(pilot, lightSensor);
Behavior reverseRight = new ReverseRight(pilot, bump);
Behavior[] behaviorzz = { moveForward, changeDirection, reverseRight };
Arbitrator arbitrator = new Arbitrator(behaviorzz);
arbitrator.start();
// while (true)
// {
// LCD.drawInt(lightSensor.getLightValue(), 8, 1);
// LCD.drawInt(lightSensor.getHigh(), 8, 2);
// LCD.drawInt(lightSensor.getLow(), 8, 3);
//
// pilot.forward();
//
// int lightValue = lightSensor.getLightValue();
// if(lightValue < 30 )
// {
// pilot.steer(30, 20);
// }
// else if(lightValue >= 30 )
// {
// pilot.steer(-20, -20);
// }
//
// if (bump.isPressed())
// {
// pilot.travel(-5);
// pilot.rotate(-90);
// }
// }
}
public static void main(String[] args)
{
LegoRunner runner = new LegoRunner();
runner.move();
}
}