-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBumperCar.java
45 lines (35 loc) · 1.52 KB
/
BumperCar.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
package lejos.commons.subsumption;
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
import ev3dev.sensors.ev3.EV3IRSensor;
import ev3dev.sensors.ev3.EV3UltrasonicSensor;
import lejos.hardware.port.MotorPort;
import lejos.hardware.port.SensorPort;
import lejos.robotics.RegulatedMotor;
import lejos.robotics.subsumption.Arbitrator;
import lejos.robotics.subsumption.Behavior;
public class BumperCar {
public static void main(String [] args) {
//https://en.wikipedia.org/wiki/Subsumption_architecture
System.out.println("Example using Subsumption architecture");
System.out.println("Starting motor on A");
final RegulatedMotor motorLeft = new EV3LargeRegulatedMotor(MotorPort.A);
System.out.println("Starting motor on B");
final RegulatedMotor motorRight = new EV3LargeRegulatedMotor(MotorPort.B);
final int motorSpeed = 200;
motorLeft.setSpeed(motorSpeed);
motorRight.setSpeed(motorSpeed);
//To Stop the motor in case of pkill java for example
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
motorLeft.stop();
motorRight.stop();
}
}));
EV3IRSensor irSensor = new EV3IRSensor(SensorPort.S1);
Behavior b1 = new DriveForward(motorLeft, motorRight);
Behavior b2 = new HitWall(motorLeft, motorRight, irSensor);
Behavior [] bArray = {b1, b2};
Arbitrator arby = new Arbitrator(bArray);
arby.go();
}
}