VMG works correctly, auto pilot is interupted by a repeated keypress or an upwind/downwind press.

tags: #story[1105]
This commit is contained in:
Alistair McIntyre
2017-08-10 17:46:28 +12:00
parent 430779c943
commit a746191dba
+20 -5
View File
@@ -176,12 +176,15 @@ public class Yacht {
* Swaps the boats direction from one side of the wind to the other. * Swaps the boats direction from one side of the wind to the other.
*/ */
public void tackGybe(Double windDirection) { public void tackGybe(Double windDirection) {
if (isAuto) {
disableAutoPilot();
} else {
Double normalizedHeading = normalizeHeading(); Double normalizedHeading = normalizeHeading();
Double newVal = (-2 * normalizedHeading) + heading; Double newVal = (-2 * normalizedHeading) + heading;
//newVal += heading;
Double newHeading = (double) Math.floorMod(newVal.longValue(), 360L); Double newHeading = (double) Math.floorMod(newVal.longValue(), 360L);
setAutoPilot(newHeading); setAutoPilot(newHeading);
} }
}
/** /**
* Enables the boats auto pilot feature, which will move the boat towards a given heading. * Enables the boats auto pilot feature, which will move the boat towards a given heading.
@@ -220,6 +223,7 @@ public class Yacht {
} }
public void turnUpwind() { public void turnUpwind() {
disableAutoPilot();
Double normalizedHeading = normalizeHeading(); Double normalizedHeading = normalizeHeading();
if (normalizedHeading == 0) { if (normalizedHeading == 0) {
if (lastHeading < 180) { if (lastHeading < 180) {
@@ -241,6 +245,7 @@ public class Yacht {
} }
public void turnDownwind() { public void turnDownwind() {
disableAutoPilot();
Double normalizedHeading = normalizeHeading(); Double normalizedHeading = normalizeHeading();
if (normalizedHeading == 0) { if (normalizedHeading == 0) {
if (lastHeading < 180) { if (lastHeading < 180) {
@@ -261,26 +266,37 @@ public class Yacht {
} }
} }
/**
* Takes the VMG from the polartable for upwind or downwind depending on the boats direction,
* and uses this to calculate a heading to move the yacht towards.
*/
public void turnToVMG() { public void turnToVMG() {
// TODO: 10/08/17 ajm412: The way this works is absolute rubbish. Needs to determine upwind/downwind, then which side of the wind, then move to the correct values. if (isAuto) {
disableAutoPilot();
} else {
Double normalizedHeading = normalizeHeading(); Double normalizedHeading = normalizeHeading();
Double optimalHeading; Double optimalHeading;
HashMap<Double, Double> optimalPolarMap; HashMap<Double, Double> optimalPolarMap;
if (normalizedHeading >= 90 && normalizedHeading <= 270) { // Downwind if (normalizedHeading >= 90 && normalizedHeading <= 270) { // Downwind
optimalPolarMap = PolarTable.getOptimalDownwindVMG(GameState.getWindSpeedKnots()); optimalPolarMap = PolarTable.getOptimalDownwindVMG(GameState.getWindSpeedKnots());
optimalHeading = optimalPolarMap.keySet().iterator().next();
} else { } else {
optimalPolarMap = PolarTable.getOptimalUpwindVMG(GameState.getWindSpeedKnots()); optimalPolarMap = PolarTable.getOptimalUpwindVMG(GameState.getWindSpeedKnots());
}
optimalHeading = optimalPolarMap.keySet().iterator().next(); optimalHeading = optimalPolarMap.keySet().iterator().next();
if (normalizedHeading > 180) {
optimalHeading = 360 - optimalHeading;
} }
// Take optimal heading and turn into a boat heading rather than a wind heading. // Take optimal heading and turn into a boat heading rather than a wind heading.
optimalHeading = optimalHeading =
optimalHeading + (double) Math.floorMod(GameState.getWindDirection().longValue(), 360L); optimalHeading + (double) Math
.floorMod(GameState.getWindDirection().longValue(), 360L);
setAutoPilot(optimalHeading); setAutoPilot(optimalHeading);
} }
}
/** /**
* Takes a given heading and rotates the boat towards that heading. * Takes a given heading and rotates the boat towards that heading.
@@ -290,7 +306,6 @@ public class Yacht {
* @param newHeading The heading to turn the yacht towards. * @param newHeading The heading to turn the yacht towards.
*/ */
private void turnTowardsHeading(Double newHeading) { private void turnTowardsHeading(Double newHeading) {
System.out.println(newHeading);
Double newVal = heading - newHeading; Double newVal = heading - newHeading;
if (Math.floorMod(newVal.longValue(), 360L) > 180) { if (Math.floorMod(newVal.longValue(), 360L) > 180) {
adjustHeading(TURN_STEP); adjustHeading(TURN_STEP);