i lost track of incremental changes 4 hours ago
This commit is contained in:
parent
9fff530e77
commit
66c80162ed
10 changed files with 116 additions and 23 deletions
6
.classpath
Normal file
6
.classpath
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="output" path=""/>
|
||||
</classpath>
|
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
/Climate$fanLevels.class
|
||||
/Climate.class
|
||||
/Destination.class
|
||||
/Entertainment.class
|
||||
/HelperFunctions.class
|
||||
/RoadSensor.class
|
||||
/Route.class
|
||||
/SelfDrivingRoadtrip.class
|
||||
/Vehicle.class
|
17
.project
Normal file
17
.project
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Code Implementation</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,6 +1,10 @@
|
|||
public class Destination {
|
||||
private String destinationAddress;
|
||||
private double[] coordinates; //stores lat/long as terms in the array
|
||||
private double[] coordinates = new double[2]; //stores lat/long as terms in the array
|
||||
|
||||
public Destination() {
|
||||
|
||||
}
|
||||
|
||||
public Destination(String inputAddress) { //constructor takes address, validates, then retrieves GPS coordinates and stores them
|
||||
setDestinationAddress(inputAddress);
|
||||
|
@ -24,7 +28,6 @@ public class Destination {
|
|||
public void setDestinationAddress(String newAddress) {
|
||||
if (validateAddress()) {
|
||||
destinationAddress = newAddress;
|
||||
setCoordsForAddress();
|
||||
} else {
|
||||
//prompt error message
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ LEFT;3.0;45;0.00
|
|||
RIGHT;2.3;50;0.00
|
||||
LEFT;0.3;50;0.00
|
||||
STRAIGHT;9.6;70;0.00
|
||||
RIGHT;0.3;50;0.00
|
||||
STRAIGHT;0.3;50;0.00
|
||||
RIGHT;0.2;35;0.00
|
||||
LEFT;0.2;35;0.00
|
||||
LEFT;0.4;35;0.00
|
||||
|
|
|
@ -23,7 +23,7 @@ public class HelperFunctions {
|
|||
return returnArray;
|
||||
}
|
||||
|
||||
public Object[] routingAPI(double[] startCoords, double[] destinationCoords, Boolean tollsFlag, Boolean hwyFlag) {
|
||||
public Vector<String[]> routingAPI(double[] startCoords, String destinationAddress, Boolean tollsFlag, Boolean hwyFlag) {
|
||||
//method simulates a call to translate two pairs of coords into a driving route
|
||||
//for demo purposes returns a pregenerated set of move instructions
|
||||
//located in DrivingRoute.txt as semicolon delimited strings for direction, distance, and speedLimit
|
||||
|
@ -41,7 +41,7 @@ public class HelperFunctions {
|
|||
}
|
||||
|
||||
}
|
||||
return routeArray.toArray();
|
||||
return routeArray;
|
||||
}
|
||||
|
||||
public int[] internalTempSensors() {
|
||||
|
|
|
@ -26,7 +26,16 @@ public class RoadSensor {
|
|||
//pedestrian on roadway
|
||||
//stationary object on roadway
|
||||
//for testing, this function will return 0 to signal no hazard detected
|
||||
return 0;
|
||||
//for testing purposes, this function will roll a 1/100 chance of detecting a hazard
|
||||
double detection = Math.floor(Math.random()*100);
|
||||
if (detection == 1) { return 1; }
|
||||
else { return 0; }
|
||||
}
|
||||
|
||||
public int detectTrafficLight() { //rolls a 1 in 5 that a traffic light will be detected when approaching an intersection
|
||||
double detection = Math.floor(Math.random()*5);
|
||||
if (detection == 1) { return 1; }
|
||||
else { return 0; }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
28
Route.java
28
Route.java
|
@ -8,7 +8,21 @@ public class Route {
|
|||
private boolean hwyFlag; //stores user preference for whether to avoid major highways
|
||||
public Vector<Double> timeEstimate; //time estimate in seconds
|
||||
public Vector<Double> tollsAmount; //stores toll amount if toll roads are used
|
||||
public Destination currentDestination; //uses user-created class Destination
|
||||
private Destination currentDestination = new Destination();
|
||||
|
||||
public Route() {
|
||||
this.routeSequences = new Vector<Vector<String[]>>();
|
||||
this.timeEstimate = new Vector<Double>();
|
||||
this.tollsAmount = new Vector<Double>();
|
||||
}
|
||||
|
||||
public Route(String destination) {
|
||||
setRouteDestination(destination);
|
||||
this.timeEstimate = new Vector<Double>();
|
||||
this.tollsAmount = new Vector<Double>();
|
||||
tollsFlag = false;
|
||||
hwyFlag = false;
|
||||
}
|
||||
|
||||
private void updateCurrentLocation() {
|
||||
//execute api call out to GPS service to obtain current location
|
||||
|
@ -21,18 +35,19 @@ public class Route {
|
|||
//execute api call out to routing service to get route info
|
||||
//ideally a query would go out using multiple pathfiding algorithms to get route options
|
||||
//here the same call is made for demo purposes
|
||||
this.routeSequences = new Vector<Vector<String[]>>();
|
||||
updateCurrentLocation();
|
||||
HelperFunctions apiCallToRouting = new HelperFunctions();
|
||||
//route option 1
|
||||
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag));
|
||||
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationAddress(), tollsFlag, hwyFlag));
|
||||
timeEstimate.add(estimateTime(routeSequences.get(0)));
|
||||
tollsAmount.add(estimateTolls(routeSequences.get(0)));
|
||||
//route option 2
|
||||
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag));
|
||||
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationAddress(), tollsFlag, hwyFlag));
|
||||
timeEstimate.add(estimateTime(routeSequences.get(1)));
|
||||
tollsAmount.add(estimateTolls(routeSequences.get(1)));
|
||||
//route option 3
|
||||
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationCoordinates(), tollsFlag, hwyFlag));
|
||||
routeSequences.add(apiCallToRouting.routingAPI(currentLocation, currentDestination.getDestinationAddress(), tollsFlag, hwyFlag));
|
||||
timeEstimate.add(estimateTime(routeSequences.get(2)));
|
||||
tollsAmount.add(estimateTolls(routeSequences.get(2)));
|
||||
}
|
||||
|
@ -68,6 +83,11 @@ public class Route {
|
|||
return runningTime;
|
||||
}
|
||||
|
||||
public void setRouteDestination(String destination) {
|
||||
currentDestination.setDestinationAddress(destination);
|
||||
calculateRoutes();
|
||||
}
|
||||
|
||||
public void setHwyFlag(boolean flag) {hwyFlag = flag;}
|
||||
public void setTollsFlag(boolean flag) {tollsFlag = flag;}
|
||||
public boolean getHwyFlag() {return hwyFlag;}
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
import java.util.Scanner;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class SelfDrivingRoadtrip {
|
||||
public static void main(String[] args) {
|
||||
Vehicle myVehicle = new Vehicle();
|
||||
Scanner userInput = new Scanner(System.in);
|
||||
|
||||
myVehicle.currentRoute.setRouteDestination("250 Community College Pkwy SE, Palm Bay, FL 32909");
|
||||
System.out.println("Number of available routes: " + myVehicle.currentRoute.enumRoutes());
|
||||
int tmp = userInput.nextInt();
|
||||
myVehicle.currentRoute.selectRoute(tmp);
|
||||
myVehicle.navigateRoute();
|
||||
}
|
||||
}
|
||||
|
|
47
Vehicle.java
47
Vehicle.java
|
@ -1,11 +1,11 @@
|
|||
import java.util.concurrent.*;
|
||||
|
||||
public class Vehicle implements Runnable{
|
||||
private int currentSpeed;
|
||||
private int targetSpeed;
|
||||
private Integer currentSpeed;
|
||||
private Integer targetSpeed;
|
||||
private double fuelLevel;
|
||||
private int distanceRemaining;
|
||||
Route currentRoute;
|
||||
private double distanceRemaining;
|
||||
public Route currentRoute = new Route();
|
||||
|
||||
public void run() {
|
||||
navigateRoute();
|
||||
|
@ -14,6 +14,7 @@ public class Vehicle implements Runnable{
|
|||
public Vehicle() {
|
||||
fuelLevel = getFuelLevel();
|
||||
currentSpeed = 0;
|
||||
currentRoute.setRouteDestination("250 Community College Pkwy SE, Palm Bay, FL 32909");
|
||||
}
|
||||
|
||||
public void setTargetSpeed(int newSpeed) {targetSpeed = newSpeed;}
|
||||
|
@ -26,9 +27,24 @@ public class Vehicle implements Runnable{
|
|||
|
||||
public void navigateRoute() {
|
||||
System.out.println("Start navigation");
|
||||
boolean turnCompleted = false;
|
||||
|
||||
for (String[] el : currentRoute.getSelectedRouteSteps()) {
|
||||
boolean turnCompleted = false; //flag to validate completion of moveset instruction
|
||||
RoadSensor trafficSensor = new RoadSensor();
|
||||
if (targetSpeed > 20 && trafficSensor.detectTrafficLight() == 1 && el[0] != "STRAIGHT") {
|
||||
//simulates stopping at traffic lights on major roadways
|
||||
//for demo purposes, the spherical cow in a vacuum is that this only happens at turns
|
||||
long sleepTime = Double.valueOf(Math.floor(Math.random()*15)).longValue();
|
||||
while (sleepTime > 0) {
|
||||
System.out.println("Traffic light detected, waiting...");
|
||||
try {TimeUnit.SECONDS.sleep(1);} //sleep for 1-15 second to simulate traffic light
|
||||
catch (InterruptedException e) {System.err.println("Sleep interrupted");}
|
||||
}
|
||||
System.out.println("Resuming navigation");
|
||||
}
|
||||
|
||||
turnCompleted = false; //flag to validate completion of moveset instruction
|
||||
distanceRemaining = Double.parseDouble(el[1]);
|
||||
targetSpeed = Integer.parseInt(el[2]);
|
||||
while (!turnCompleted) {
|
||||
if (currentSpeed < 15 || el[0] == "STRAIGHT") {
|
||||
|
@ -39,14 +55,16 @@ public class Vehicle implements Runnable{
|
|||
}
|
||||
}
|
||||
|
||||
while (distanceRemaining > 0.2) {
|
||||
System.out.println(distanceRemaining + " to next instruction");
|
||||
distanceRemaining -= (currentSpeed/3600); //travel distance in one second
|
||||
while (distanceRemaining > 0) {
|
||||
System.out.printf("%.2f miles to next instruction\n", distanceRemaining);
|
||||
System.out.println("Current Speed: " + currentSpeed + " MPH");
|
||||
controlThrottle();
|
||||
try {TimeUnit.MINUTES.sleep(1);} //sleep action for 1 second to simulate continuous movement
|
||||
distanceRemaining = distanceRemaining - (Double.valueOf(currentSpeed)/3600); //travel distance in one second
|
||||
try {TimeUnit.SECONDS.sleep(1);} //sleep action for 1 second to simulate continuous movement
|
||||
catch (InterruptedException e) {System.err.println("Sleep interrupted");}
|
||||
}
|
||||
}
|
||||
System.out.println("Navigation complete, destination reached.");
|
||||
}
|
||||
|
||||
public void changeDirection(String direction) {
|
||||
|
@ -65,15 +83,18 @@ public class Vehicle implements Runnable{
|
|||
|
||||
public void controlThrottle() {
|
||||
if (currentSpeed < targetSpeed && (targetSpeed - currentSpeed) > 6) { //normal acceleration
|
||||
currentSpeed += 6;
|
||||
} else if (currentSpeed < targetSpeed && (targetSpeed - currentSpeed) < 6) { //partial acceleration to reach speed limit
|
||||
currentSpeed += (currentSpeed - targetSpeed);
|
||||
currentSpeed = currentSpeed + 6;
|
||||
} else if (currentSpeed < targetSpeed && (targetSpeed - currentSpeed) <= 6) { //partial acceleration to reach speed limit
|
||||
currentSpeed = currentSpeed + (targetSpeed - currentSpeed);
|
||||
} else if (currentSpeed > targetSpeed) { //deceleration by coasting
|
||||
currentSpeed -= 1;
|
||||
currentSpeed--;
|
||||
} else if (currentSpeed == targetSpeed) {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
|
||||
public void applyBrakes() {
|
||||
System.out.println("Applying brakes");
|
||||
if (currentSpeed >= 10) {currentSpeed -= 10;}
|
||||
else if (currentSpeed < 10) {currentSpeed = 0;}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue