-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAutonomousCarController.java
More file actions
118 lines (100 loc) · 4.54 KB
/
AutonomousCarController.java
File metadata and controls
118 lines (100 loc) · 4.54 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.util.ArrayList;
public class AutonomousCarController {
private NavigationSystemInterface navigationSystemInterface;
private AutoSystemInterface autoSystemInterface;
private TrafficSignalSystemInterface trafficSignalSystemInterface;
private SurroundSensingSystemInterface surroundSensingSystemInterface;
private RoadSignReadingSystem roadSignReadingSystem;
private StartStrategy startStrategy;
private StopStrategy stopStrategy;
public void setDependencies(NavigationSystemInterface navigationSystemInterface,
AutoSystemInterface autoSystemInterface,
TrafficSignalSystemInterface trafficSignalSystemInterface,
SurroundSensingSystemInterface surroundSensingSystemInterface,
RoadSignReadingSystem roadSignReadingSystem){
this.navigationSystemInterface = navigationSystemInterface;
this.autoSystemInterface = autoSystemInterface;
this.trafficSignalSystemInterface = trafficSignalSystemInterface;
this.surroundSensingSystemInterface = surroundSensingSystemInterface;
this.roadSignReadingSystem = roadSignReadingSystem ;
}
public void start() {
System.out.println("Starting the car");
autoSystemInterface.startEngine();
navigationSystemInterface.startNavigation();
}
public void stop() {
System.out.println("Destination reached, stopping the car");
}
public void startVehicle() {
if (startStrategy != null) {
startStrategy.start();
}
else {
System.out.println("No start strategy set");
}
}
public void stopVehicle() {
if (stopStrategy != null) {
stopStrategy.stop();
}
else {
System.out.println("No stop strategy set");
}
}
public void setStartStrategy(StartStrategy strategy) {
this.startStrategy = strategy;
}
public void setStopStrategy(StopStrategy strategy) {
this.stopStrategy = strategy;
}
public void turnLeft(Double afterDistance) {
System.out.println("Checking signal, surroundings and road signs");
System.out.println("Checking signal, surroundings and road signs");
if (trafficSignalSystemInterface.getSignalToTurnLeft()
&& surroundSensingSystemInterface.checkForLeftTurn()
&& roadSignReadingSystem.isClearToTurnLeft()) {
autoSystemInterface.signalLeft();
autoSystemInterface.turnLeft(afterDistance);
}
}
public void turnRight(Double afterDistance) {
System.out.println("Checking signal, surroundings and road signs");
if (trafficSignalSystemInterface.getSignalToTurnRight()
&& surroundSensingSystemInterface.checkForRightTurn()
&& roadSignReadingSystem.isClearToTurnRight()) {
autoSystemInterface.signalRight();
autoSystemInterface.turnRight(afterDistance);
}
}
public void slightLeft(Double afterDistance) {
System.out.println("Checking signal, surroundings and road signs");
if (trafficSignalSystemInterface.getSignalToTurnLeft()
&& surroundSensingSystemInterface.checkForLeftTurn()
&& roadSignReadingSystem.isClearToTurnLeft()) {
autoSystemInterface.signalLeft();
autoSystemInterface.slightLeft(afterDistance);
}
}
public void slightRight(Double afterDistance) {
System.out.println("Checking signal, surroundings and road signs");
if (trafficSignalSystemInterface.getSignalToTurnRight()
&& surroundSensingSystemInterface.checkForRightTurn()
&& roadSignReadingSystem.isClearToTurnRight()) {
autoSystemInterface.signalRight();
autoSystemInterface.slightRight(afterDistance);
}
}
public void trip(GeoPoint startLoc, GeoPoint endLoc) {
navigationSystemInterface.directions(startLoc, endLoc);
}
public void handleAlert(Alert alert) {
String deviceId = alert.getDeviceId();
switch (deviceId) {
case "LeftSensor", "RightSensor" -> new SurroundSensingAlertHandler().processAlert(alert.getSeverity());
case "TrafficSensor" -> new TrafficSignalAlertHandler().processAlert(alert.getSeverity());
case "RoadSignSensor" -> new NavigationAlertHandler().processAlert(alert.getSeverity());
default -> System.out.println("Unknown sensor alert received");
}
}
}