VMG is now working and fixed, however, it feels a bit odd #story[1182]
This commit is contained in:
@@ -368,11 +368,11 @@ public class MockRace extends Race {
|
|||||||
VMG newVMG = NewPolars.setBestVMG(this.getWindDirection(), this.getWindSpeed(), boat.getBearing());
|
VMG newVMG = NewPolars.setBestVMG(this.getWindDirection(), this.getWindSpeed(), boat.getBearing());
|
||||||
//System.out.println(newVMG);
|
//System.out.println(newVMG);
|
||||||
//If the new vmg improves velocity, use it.
|
//If the new vmg improves velocity, use it.
|
||||||
if (improvesVelocity(boat, newVMG)) {
|
/*if (improvesVelocity(boat, newVMG)) {
|
||||||
|
}*/
|
||||||
boat.setVMG(newVMG);
|
boat.setVMG(newVMG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void setBoatSpeed(MockBoat boat) {
|
private void setBoatSpeed(MockBoat boat) {
|
||||||
// VMG vmg = boat.getPolars().calculateVMG(
|
// VMG vmg = boat.getPolars().calculateVMG(
|
||||||
|
|||||||
@@ -106,18 +106,25 @@ public class NewPolars {
|
|||||||
private static double getBestSpeedInQuadrant(int quad, Map<Double, Double> set){
|
private static double getBestSpeedInQuadrant(int quad, Map<Double, Double> set){
|
||||||
double min = (quad - 1)* 90;
|
double min = (quad - 1)* 90;
|
||||||
double max = quad * 90;
|
double max = quad * 90;
|
||||||
System.out.println(quad);
|
//System.out.println(quad);
|
||||||
System.out.println(min + " " + max);
|
//System.out.println(min + " " + max);
|
||||||
double maxAngle = 0;
|
double maxAngle = 0;
|
||||||
double maxSpeed = 0;
|
double maxSpeed = 0;
|
||||||
|
double dupAngle = 0;//index where speed is duplicated
|
||||||
for (Double s: set.keySet()){
|
for (Double s: set.keySet()){
|
||||||
if (s >= min && s < max){
|
if (s >= min && s < max){
|
||||||
if (set.get(s) > maxSpeed){
|
if (set.get(s) > maxSpeed){
|
||||||
|
dupAngle = 0;
|
||||||
maxAngle = s;
|
maxAngle = s;
|
||||||
maxSpeed = set.get(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;
|
return maxAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,14 +147,16 @@ public class NewPolars {
|
|||||||
Bearing vmgAngle = Bearing.fromDegrees((bestAngle) % 360);
|
Bearing vmgAngle = Bearing.fromDegrees((bestAngle) % 360);
|
||||||
double boatSpeed = polars.get(closestSpeed).get(bestAngle);
|
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){
|
public static double calculateSpeed(Bearing trueWindAngle, double trueWindSpeed, Bearing boatAngle){
|
||||||
//speed
|
//speed
|
||||||
double closestSpeed = getClosest(trueWindSpeed, polars.keySet());
|
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 closestAngle = getClosest(angleDiff, polars.get(closestSpeed).keySet());
|
||||||
|
|
||||||
double boatSpeed = polars.get(closestSpeed).get(closestAngle);
|
double boatSpeed = polars.get(closestSpeed).get(closestAngle);
|
||||||
@@ -162,4 +171,16 @@ public class NewPolars {
|
|||||||
return polars;
|
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(){
|
public void setUp(){
|
||||||
PolarParser.parseNewPolars("mock/polars/acc_polars.csv");
|
PolarParser.parseNewPolars("mock/polars/acc_polars.csv");
|
||||||
NewPolars.linearInterpolatePolars();
|
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
|
@Test
|
||||||
@@ -70,9 +85,9 @@ public class NewPolarsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testEdgeSpeeds(){
|
public void testEdgeSpeeds(){
|
||||||
//just make sure that speeds at certain angles do not throw a null exception and are not negative
|
//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++){
|
for (double j = 0; j < 360; j++){
|
||||||
Bearing twa = Bearing.fromDegrees(j);
|
Bearing twa = Bearing.fromDegrees(j);
|
||||||
for (double i = 0; i < 360; i++){
|
for (double i = 0; i < 360; i++){
|
||||||
@@ -94,14 +109,31 @@ public class NewPolarsTest {
|
|||||||
Method getPolars = NewPolars.class.getDeclaredMethod("getPolars");
|
Method getPolars = NewPolars.class.getDeclaredMethod("getPolars");
|
||||||
getPolars.setAccessible(true);
|
getPolars.setAccessible(true);
|
||||||
|
|
||||||
double maxTWS = 15;
|
double maxTWS = 30;
|
||||||
|
|
||||||
//only catches for nulls
|
//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);
|
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());
|
double speed = (double) getClosest.invoke(NewPolars.newPolars, tws, polars.keySet());
|
||||||
assertTrue(speed >= 0);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user