Implemented a fairly simple auto pilot setting for the yacht, on update if the boat is set to autopilot it will adjust the heading towards the desired heading. Needs some refinement.

#story[1105]
This commit is contained in:
alistairjmcintyre
2017-08-10 02:04:51 +12:00
parent 43788bd153
commit 9d02d2fbea
2 changed files with 22 additions and 2 deletions
+1 -1
View File
@@ -23,5 +23,5 @@ Haoming Yin <hyi25@uclive.ac.nz> <haoming.y@icloud.com>
Peter Galloway <ptg19@uclive.ac.nz> Peter <ptg19@uclive.ac.nz>
Zhi You Tan <zyt10@uclive.ac.nz> zyt10 <zyt10@uclive.ac.nz>
Zhi You Tan <zyt10@uclive.ac.nz> Ryan Tan <ryan_zhiyou@hotmail.com>
Alistair McIntyre <ajm412@uclive.ac.nz> alistairjmcintyre <alistairjmcintyre@gmail.com>
Alistair McIntyre <ajm412@uclive.ac.nz> <alistairjmcintyre@gmail.com>
Calum <cir27@uclive.ac.nz> cir27 <cir27@uclive.ac.nz>
+21 -1
View File
@@ -54,6 +54,9 @@ public class Yacht {
private GeoPoint location;
private Integer boatStatus;
private Double velocity;
private Boolean isAuto;
private Double autoHeading;
//MARK ROUNDING INFO
private GeoPoint lastLocation; //For purposes of mark rounding calculations
private Boolean hasEnteredRoundingZone; //The distance that the boat must be from the mark to round
@@ -78,6 +81,7 @@ public class Yacht {
this.boatName = boatName;
this.country = country;
this.sailIn = false;
this.isAuto = false;
this.location = new GeoPoint(57.670341, 11.826856);
this.lastLocation = location;
this.heading = 120.0; //In degrees
@@ -121,6 +125,13 @@ public class Yacht {
}
}
if (isAuto) {
turnTowardsHeading(autoHeading);
if (Math.abs(heading - autoHeading) <= 5) {
isAuto = false;
}
}
//UPDATE BOAT LOCATION
location = GeoUtility.getGeoCoordinate(location, heading, velocity * secondsElapsed);
@@ -159,9 +170,18 @@ public class Yacht {
heading = (double) Math.floorMod(newVal.longValue(), 360L);
}
/**
* Should tell boat to auto pilot towards the autopilot heading.
*/
public void tackGybe(Double windDirection) {
Double normalizedHeading = normalizeHeading();
adjustHeading(-2 * normalizedHeading);
setAutoPilot(-2 * normalizedHeading);
}
private void setAutoPilot(Double thisHeading) {
isAuto = true;
Double newVal = heading + thisHeading;
autoHeading = (double) Math.floorMod(newVal.longValue(), 360L);
}
public void toggleSailIn() {