VMG now works however some little bug in the interpolation in some quadrant that is making the speed all the same in the quadrant #story[1182]

This commit is contained in:
Fan-Wu Yang
2017-09-05 19:26:06 +12:00
parent 7aaa880f40
commit 7331ad1a20
5 changed files with 148 additions and 17 deletions
@@ -108,7 +108,6 @@ public class PolarParser {
/**
* Given a filename, this function parses it and generates a Polar object, which can be queried for polar information.
* @param filename The filename to load and read data from (loaded as a resource).
* @return A Polar table containing data from the given file.
*/
public static void parseNewPolars(String filename) throws InvalidPolarFileException {
NewPolars newPolars = new NewPolars();
@@ -209,7 +209,9 @@ public class MockRace extends Race {
boat.setStatus(BoatStatusEnum.PRESTART);
//We set a large time since tack change so that it calculates a new VMG when the simulation starts.
boat.setTimeSinceTackChange(Long.MAX_VALUE);
//boat.setTimeSinceTackChange(Long.MAX_VALUE);
boat.setTimeSinceTackChange(0);
}
}
@@ -353,8 +355,8 @@ public class MockRace extends Race {
private void newOptimalVMG(MockBoat boat) {
long tackPeriod = 1000;
if (boat.getTimeSinceTackChange() > tackPeriod) {
//System.out.println("optim called");
//Calculate the new VMG.
// VMG newVMG = boat.getPolars().calculateVMG(
// this.getWindDirection(),
@@ -364,7 +366,7 @@ public class MockRace extends Race {
// Bearing.fromDegrees(359.99999d));
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 (improvesVelocity(boat, newVMG)) {
boat.setVMG(newVMG);
@@ -31,7 +31,7 @@ public class NewPolars {
}
polars.get(tws).putIfAbsent(twa, bs);
polars.get(tws).putIfAbsent(360d - twa, bs);
System.out.println(String.format("tws %f, twa %f, bs %f", tws, twa, bs));
//System.out.println(String.format("tws %f, twa %f, bs %f", tws, twa, bs));
}
public static void linearInterpolatePolars(){
@@ -69,7 +69,7 @@ public class NewPolars {
double mult = i - previousTWA;
double newSpeed = diff * mult + prevSpeed;
//System.out.println(newSpeed);
System.out.println(String.format("tws %f, twa %f, bs %f", windSpeed, i, newSpeed));
//System.out.println(String.format("tws %f, twa %f, bs %f", windSpeed, i, newSpeed));
tws.put(i, newSpeed);
}
previousTWA = twa;
@@ -104,8 +104,10 @@ public class NewPolars {
}
private static double getBestSpeedInQuadrant(int quad, Map<Double, Double> set){
double min = quad* 90;
double max = (quad + 1) * 90;
double min = (quad - 1)* 90;
double max = quad * 90;
System.out.println(quad);
System.out.println(min + " " + max);
double maxAngle = 0;
double maxSpeed = 0;
for (Double s: set.keySet()){
@@ -116,9 +118,6 @@ public class NewPolars {
}
}
}
if (quad > 2){
maxAngle += 180;
}
return maxAngle;
}
@@ -130,13 +129,12 @@ public class NewPolars {
* @return
*/
public static VMG setBestVMG(Bearing trueWindAngle, double trueWindSpeed, Bearing boatAngle){
//System.out.println("VMG AUTO CALLED");
//speed
double closestSpeed = getClosest(trueWindSpeed, polars.keySet());
//not using true vmg, using general concept
double angle = Math.abs(trueWindAngle.degrees() - boatAngle.degrees());
int quad = getQuadrant(boatAngle.degrees());
double angle = ((boatAngle.degrees() - trueWindAngle.degrees()) % 360 + 360) % 360;
int quad = getQuadrant(angle);
double bestAngle = getBestSpeedInQuadrant(quad, polars.get(closestSpeed));
Bearing vmgAngle = Bearing.fromDegrees((bestAngle) % 360);
@@ -159,4 +157,9 @@ public class NewPolars {
}
private Map<Double, TreeMap<Double, Double>> getPolars(){
//this function is just for testing so therefore it is private
return polars;
}
}