updated the race class to set heading based on the vmg not just the end of a leg

-race class now stores the boundary
-updatePositions now checks if the boat is with the course
-update positions now sets heading and speed based on the vmg
-updated azimuth to now accept a start and finish gps rather that finding it itself
-added a calculatebearingtodestination method that finds the azimuth to the dest from the boat
-updated boat tests to use the new azimuth method
 #story[873]
main
hba56 9 years ago
parent 04fdeaf2e2
commit dd1308808a

@ -42,11 +42,9 @@ public class Boat {
* *
* @return the direction that the boat is heading towards in degrees (-180 to 180). * @return the direction that the boat is heading towards in degrees (-180 to 180).
*/ */
public double calculateAzimuth() { public double calculateAzimuth(GPSCoordinate start, GPSCoordinate end) {
GeodeticCalculator calc = new GeodeticCalculator(); GeodeticCalculator calc = new GeodeticCalculator();
GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate();
GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate();
calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude()); calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude());
calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude()); calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude());
@ -59,7 +57,23 @@ public class Boat {
* @return The azimuth value which is greater than 0 * @return The azimuth value which is greater than 0
*/ */
public double calculateHeading() { public double calculateHeading() {
double azimuth = this.calculateAzimuth(); double azimuth = this.calculateAzimuth(currentLeg.getStartMarker().getAverageGPSCoordinate(),
currentLeg.getEndMarker().getAverageGPSCoordinate());
if (azimuth >= 0) {
return azimuth;
} else {
return azimuth + 360;
}
}
/**
* Calculate the heding depending on the calculated azimuth value
* @return The azimuth value which is greater than 0
*/
public double calculateBearingToDestination() {
double azimuth = this.calculateAzimuth(this.currentPosition,
currentLeg.getEndMarker().getAverageGPSCoordinate());
if (azimuth >= 0) { if (azimuth >= 0) {
return azimuth; return azimuth;

@ -41,6 +41,7 @@ public class Race implements Runnable {
private MockOutput mockOutput; private MockOutput mockOutput;
private static int boatOffset = 0; private static int boatOffset = 0;
private int finished = 0; private int finished = 0;
private List<GPSCoordinate> boundary;
/** /**
@ -50,7 +51,7 @@ public class Race implements Runnable {
* @param legs Number of marks in order that the boats pass in order to complete the race. * @param legs Number of marks in order that the boats pass in order to complete the race.
* @param scaleFactor for race * @param scaleFactor for race
*/ */
public Race(List<Boat> boats, List<Leg> legs, int raceID, int scaleFactor, MockOutput mockOutput) { public Race(List<Boat> boats, List<Leg> legs, int raceID, int scaleFactor, MockOutput mockOutput, List<GPSCoordinate> boundary) {
this.startingBoats = FXCollections.observableArrayList(boats); this.startingBoats = FXCollections.observableArrayList(boats);
this.legs = legs; this.legs = legs;
@ -58,6 +59,7 @@ public class Race implements Runnable {
this.raceId = raceID; this.raceId = raceID;
this.scaleFactor = scaleFactor; this.scaleFactor = scaleFactor;
this.mockOutput = mockOutput; this.mockOutput = mockOutput;
this.boundary = boundary;
//TODO refactor //TODO refactor
this.startTime = System.currentTimeMillis() + (this.PRERACE_TIME / this.scaleFactor); this.startTime = System.currentTimeMillis() + (this.PRERACE_TIME / this.scaleFactor);
@ -69,7 +71,7 @@ public class Race implements Runnable {
} }
public Race(RaceDataSource raceData, int scaleFactor, MockOutput mockOutput) { public Race(RaceDataSource raceData, int scaleFactor, MockOutput mockOutput) {
this(raceData.getBoats(), raceData.getLegs(), raceData.getRaceId(), scaleFactor, mockOutput); this(raceData.getBoats(), raceData.getLegs(), raceData.getRaceId(), scaleFactor, mockOutput, raceData.getBoundary());
} }
/** /**
@ -298,12 +300,21 @@ public class Race implements Runnable {
boolean finish = boat.getCurrentLeg().getName().equals("Finish"); boolean finish = boat.getCurrentLeg().getName().equals("Finish");
if (!finish) { if (!finish) {
boat.setHeading(boat.calculateHeading()); if(!GPSCoordinate.isInsideBoundary(boat.getCurrentPosition(), this.boundary)){
//update boat's distance travelled //todo - find the acceptable values for direction
boat.setDistanceTravelledInLeg(totalDistanceTravelled); } else{
//Calculate boat's new position by adding the distance travelled onto the start point of the leg VMG newHeading = boat.getPolars().calculateVMG(180, 30,
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(), boat.calculateBearingToDestination());//todo - get the wind speed from somewhere
totalDistanceTravelled, boat.calculateAzimuth())); boat.setHeading(newHeading.bearing);
boat.setVelocity(newHeading.speed);
// boat.setHeading(boat.calculateHeading());
//update boat's distance travelled
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
totalDistanceTravelled, boat.getHeading()));
}
} }
} }

@ -22,7 +22,7 @@ public class BoatTest {
Marker endMarker = new Marker(new GPSCoordinate(50, 0)); Marker endMarker = new Marker(new GPSCoordinate(50, 0));
Leg start = new Leg("Start", startMarker, endMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8); assertEquals(TEST_BOAT.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()), 0, 1e-8);
} }
@Test @Test
@ -31,7 +31,7 @@ public class BoatTest {
Marker endMarker = new Marker(new GPSCoordinate(-50, 0)); Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
Leg start = new Leg("Start", startMarker, endMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8); assertEquals(TEST_BOAT.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()), 180, 1e-8);
} }
@ -42,7 +42,7 @@ public class BoatTest {
Marker endMarker = new Marker(new GPSCoordinate(0, 50)); Marker endMarker = new Marker(new GPSCoordinate(0, 50));
Leg start = new Leg("Start", startMarker, endMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8); assertEquals(TEST_BOAT.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()), 90, 1e-8);
} }
@ -52,7 +52,7 @@ public class BoatTest {
Marker endMarker = new Marker(new GPSCoordinate(0, -50)); Marker endMarker = new Marker(new GPSCoordinate(0, -50));
Leg start = new Leg("Start", startMarker, endMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8); assertEquals(TEST_BOAT.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()), -90, 1e-8);
} }

Loading…
Cancel
Save