mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-09-11 19:55:14 +02:00
Fix TWD not calculated from TWA in some situations
This commit is contained in:
@@ -532,24 +532,18 @@ bool WindUtils::handleWinds(bool calcWinds)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate AWD if not existing and if possible
|
// calculate AWD if it does not exist yet and AWA is available
|
||||||
if (!awdBVal->valid) {
|
if (!awdBVal->valid) {
|
||||||
if (calcWD(&awaVal, &hdtVal, &awd)) {
|
if (calcWD(&awaVal, &hdtVal, &awd)) {
|
||||||
awdBVal->value = awd;
|
awdBVal->value = awd;
|
||||||
awdBVal->valid = true;
|
awdBVal->valid = true;
|
||||||
} else {
|
} else {
|
||||||
awdBVal->valid = false;
|
awdBVal->valid = false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!calcWinds) { // don't calculate true winds if not set in configuration
|
// calculate TWD if it does not exist yet and TWA is available
|
||||||
return twCalculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate TWD if not existing and if possible
|
|
||||||
if (!twdBVal->valid) {
|
if (!twdBVal->valid) {
|
||||||
// calculate TWD if it does not exist yet and TWA is available
|
|
||||||
if (calcWD(&twaVal, &hdtVal, &twd)) {
|
if (calcWD(&twaVal, &hdtVal, &twd)) {
|
||||||
twdBVal->value = twd;
|
twdBVal->value = twd;
|
||||||
twdBVal->valid = true;
|
twdBVal->valid = true;
|
||||||
@@ -558,6 +552,10 @@ bool WindUtils::handleWinds(bool calcWinds)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!calcWinds) { // don't calculate true winds from apparent winds if not set in configuration
|
||||||
|
return twCalculated;
|
||||||
|
}
|
||||||
|
|
||||||
if (!twaBVal->valid || !twsBVal->valid || !twdBVal->valid) {
|
if (!twaBVal->valid || !twsBVal->valid || !twdBVal->valid) {
|
||||||
// calculate true winds at least one of three true wind values does not exist
|
// calculate true winds at least one of three true wind values does not exist
|
||||||
twCalculated = calcTrueWinds(&awaVal, &awsVal, &awd, &cogVal, &stwVal, &sogVal, &hdtVal, &twa, &tws, &twd);
|
twCalculated = calcTrueWinds(&awaVal, &awsVal, &awd, &cogVal, &stwVal, &sogVal, &hdtVal, &twa, &tws, &twd);
|
||||||
@@ -576,8 +574,6 @@ bool WindUtils::handleWinds(bool calcWinds)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// LOG_DEBUG(GwLog::DEBUG, "WindUtils:handleWinds: twCalculated %d, TWD %.1f, TWA %.1f, TWS %.2f kn, AWD: %.1f", twCalculated, twdBVal->value * RAD_TO_DEG,
|
|
||||||
// twaBVal->value * RAD_TO_DEG, twsBVal->value * 3.6 / 1.852, awdBVal->value * RAD_TO_DEG);
|
|
||||||
|
|
||||||
return twCalculated;
|
return twCalculated;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ public:
|
|||||||
static double toPI(double a);
|
static double toPI(double a);
|
||||||
static double to360(double a);
|
static double to360(double a);
|
||||||
static double to180(double a);
|
static double to180(double a);
|
||||||
|
|
||||||
void toCart(const double* phi, const double* r, double* x, double* y);
|
void toCart(const double* phi, const double* r, double* x, double* y);
|
||||||
void toPol(const double* x, const double* y, double* phi, double* r);
|
void toPol(const double* x, const double* y, double* phi, double* r);
|
||||||
void addPolar(const double* phi1, const double* r1,
|
void addPolar(const double* phi1, const double* r1,
|
||||||
|
|||||||
Reference in New Issue
Block a user