fix(telemetry): Inconsistent/wrong GPS distance calculation (#4442)

This commit is contained in:
Michael
2023-12-21 19:16:56 +10:00
committed by GitHub
parent c201f93516
commit 587a14361f
2 changed files with 7 additions and 10 deletions
+3 -3
View File
@@ -161,12 +161,12 @@ void TelemetryItem::setValue(const TelemetrySensor &sensor, int32_t val,
#if defined(INTERNAL_GPS) #if defined(INTERNAL_GPS)
if (gpsData.fix && gpsData.hdop < PILOTPOS_MIN_HDOP) { if (gpsData.fix && gpsData.hdop < PILOTPOS_MIN_HDOP) {
pilotLatitude = gpsData.latitude; pilotLatitude = gpsData.latitude;
distFromEarthAxis = getDistFromEarthAxis(pilotLatitude); gps.pilotDistFromEarthAxis = getDistFromEarthAxis(pilotLatitude);
} }
#endif #endif
if (!pilotLatitude) { if (!pilotLatitude) {
pilotLatitude = newVal; pilotLatitude = newVal;
distFromEarthAxis = getDistFromEarthAxis(newVal); gps.pilotDistFromEarthAxis = getDistFromEarthAxis(newVal);
} }
gps.latitude = newVal; gps.latitude = newVal;
setFresh(); setFresh();
@@ -380,7 +380,7 @@ void TelemetryItem::eval(const TelemetrySensor & sensor)
uint32_t result = dist * dist; uint32_t result = dist * dist;
angle = abs(gpsItem.gps.longitude - gpsItem.pilotLongitude); angle = abs(gpsItem.gps.longitude - gpsItem.pilotLongitude);
dist = uint64_t(gpsItem.distFromEarthAxis) * angle / 1000000; dist = uint64_t(gpsItem.gps.pilotDistFromEarthAxis) * angle / 1000000;
result += dist * dist; result += dist * dist;
// Length on ground (ignoring curvature of the earth) // Length on ground (ignoring curvature of the earth)
+4 -7
View File
@@ -32,10 +32,7 @@ constexpr uint8_t TELEMETRY_SENSOR_TEXT_LENGTH = 16;
class TelemetryItem class TelemetryItem
{ {
public: public:
union { int32_t value; // value, stored as uint32_t but interpreted accordingly to type
int32_t value; // value, stored as uint32_t but interpreted accordingly to type
uint32_t distFromEarthAxis;
};
union { union {
int32_t valueMin; // min store int32_t valueMin; // min store
@@ -72,9 +69,9 @@ class TelemetryItem
struct { struct {
int32_t latitude; int32_t latitude;
int32_t longitude; int32_t longitude;
// pilot longitude is stored in min uint32_t pilotDistFromEarthAxis; // pilot distance from earth axis
// pilot latitude is stored in max // pilot longitude is stored in min
// distFromEarthAxis is stored in value // pilot latitude is stored in max
} gps; } gps;
char text[TELEMETRY_SENSOR_TEXT_LENGTH]; char text[TELEMETRY_SENSOR_TEXT_LENGTH];
}; };