VMG is now working and fixed, however, it feels a bit odd #story[1182]

main
Fan-Wu Yang 8 years ago
parent 7331ad1a20
commit d602c1ec6f

@ -368,9 +368,9 @@ public class MockRace extends Race {
VMG newVMG = NewPolars.setBestVMG(this.getWindDirection(), this.getWindSpeed(), boat.getBearing());
//System.out.println(newVMG);
//If the new vmg improves velocity, use it.
if (improvesVelocity(boat, newVMG)) {
boat.setVMG(newVMG);
}
/*if (improvesVelocity(boat, newVMG)) {
}*/
boat.setVMG(newVMG);
}
}

@ -106,18 +106,25 @@ public class NewPolars {
private static double getBestSpeedInQuadrant(int quad, Map<Double, Double> set){
double min = (quad - 1)* 90;
double max = quad * 90;
System.out.println(quad);
System.out.println(min + " " + max);
//System.out.println(quad);
//System.out.println(min + " " + max);
double maxAngle = 0;
double maxSpeed = 0;
double dupAngle = 0;//index where speed is duplicated
for (Double s: set.keySet()){
if (s >= min && s < max){
if (set.get(s) > maxSpeed){
dupAngle = 0;
maxAngle = s;
maxSpeed = set.get(s);
} else if (set.get(s) == maxSpeed){
dupAngle = s;
}
}
}
}/*
if (dupAngle != 0 ){
return getClosest((dupAngle + maxAngle) / 2, set.keySet());
}*/
return maxAngle;
}
@ -140,14 +147,16 @@ public class NewPolars {
Bearing vmgAngle = Bearing.fromDegrees((bestAngle) % 360);
double boatSpeed = polars.get(closestSpeed).get(bestAngle);
return new VMG(boatSpeed, Bearing.fromDegrees(vmgAngle.degrees() + trueWindAngle.degrees()));
double newAngle = (bestAngle + trueWindAngle.degrees() % 360 + 360) % 360;
return new VMG(boatSpeed, Bearing.fromDegrees(newAngle));
}
public static double calculateSpeed(Bearing trueWindAngle, double trueWindSpeed, Bearing boatAngle){
//speed
double closestSpeed = getClosest(trueWindSpeed, polars.keySet());
double angleDiff = Math.abs(trueWindAngle.degrees() - boatAngle.degrees()) % 180;
double angleDiff = ((boatAngle.degrees() - trueWindAngle.degrees()) % 360 + 360) % 360;
double closestAngle = getClosest(angleDiff, polars.get(closestSpeed).keySet());
double boatSpeed = polars.get(closestSpeed).get(closestAngle);
@ -162,4 +171,16 @@ public class NewPolars {
return polars;
}
private void printOutLinearInterpolated(){
for (double tws: polars.keySet()){
System.out.println("==================================================");
System.out.println("Speed: " + tws);
System.out.println("==================================================");
for (double twa: polars.get(tws).keySet()){
System.out.println("TWA: " + twa + ", Boat Speed: " + polars.get(tws).get(twa));
//System.out.println("--------------------------------------------------");
}
}
}
}

@ -25,6 +25,21 @@ public class NewPolarsTest {
public void setUp(){
PolarParser.parseNewPolars("mock/polars/acc_polars.csv");
NewPolars.linearInterpolatePolars();
Method getPolars = null;
try {
getPolars = NewPolars.class.getDeclaredMethod("printOutLinearInterpolated");
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
getPolars.setAccessible(true);
try {
getPolars.invoke(NewPolars.newPolars);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
@Test
@ -70,9 +85,9 @@ public class NewPolarsTest {
@Test
public void testEdgeSpeeds(){
//just make sure that speeds at certain angles do not throw a null exception and are not negative
double maxTWS = 15;
double maxTWS = 30;
for (double tws = 0; tws < maxTWS; tws += 0.1){
for (double tws = 0; tws < maxTWS; tws += 1){
for (double j = 0; j < 360; j++){
Bearing twa = Bearing.fromDegrees(j);
for (double i = 0; i < 360; i++){
@ -94,14 +109,31 @@ public class NewPolarsTest {
Method getPolars = NewPolars.class.getDeclaredMethod("getPolars");
getPolars.setAccessible(true);
double maxTWS = 15;
double maxTWS = 30;
//only catches for nulls
for (double tws = 0; tws < maxTWS; tws += 0.1){
for (double tws = 0; tws < maxTWS; tws += 1){
Map<Double, TreeMap<Double, Double>> polars = (Map<Double, TreeMap<Double, Double>>) getPolars.invoke(NewPolars.newPolars);
double speed = (double) getClosest.invoke(NewPolars.newPolars, tws, polars.keySet());
assertTrue(speed >= 0);
}
}
@Test
public void testAutoVSCalculated(){
//test that the auto chosen speed is the same speed that is calculated
double maxTWS = 30;
for (double tws = 0; tws < maxTWS; tws ++){
for (double twa = 0; twa < 360; twa ++){
Bearing TW = Bearing.fromDegrees(twa);
for (double ba = 0; ba < 360; ba ++){
Bearing boatBearing = Bearing.fromDegrees(ba);
VMG autoVMG = NewPolars.setBestVMG(TW, tws, boatBearing);
double speed = NewPolars.calculateSpeed(TW, tws, autoVMG.getBearing());
assertTrue(autoVMG.getSpeed() == speed);
}
}
}
}
}

Loading…
Cancel
Save