From 15c101efe495490a9732506ce847f43a433d30d2 Mon Sep 17 00:00:00 2001
From: James Turner <zakalawe@mac.com>
Date: Fri, 20 Sep 2019 23:08:22 +0100
Subject: [PATCH] GPS detects being repositioned
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Avoid screwing up the derived / trend data when we are repositioned;
detect instantaneous position changes and don’t update the trend
data in this case.
---
 src/Instrumentation/gps.cxx | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/Instrumentation/gps.cxx b/src/Instrumentation/gps.cxx
index bd4a10967..ec286d756 100644
--- a/src/Instrumentation/gps.cxx
+++ b/src/Instrumentation/gps.cxx
@@ -498,6 +498,14 @@ GPS::updateBasicData(double dt)
   double track2_deg;
   SGGeodesy::inverse(_last_pos, _indicated_pos, _last_true_track, track2_deg, distance_m );
     
+// detect repositions
+// setting this value high enough hypersonic aircraft but not spaceships
+  if ((distance_m / dt) > 100000.0) {
+    SG_LOG(SG_INSTR, SG_DEBUG, "GPS detected reposition, resetting data");
+    _dataValid = false;
+    return;
+  }
+    
   double speed_kt = ((distance_m * SG_METER_TO_NM) * ((1 / dt) * 3600.0));
   double vertical_speed_mpm = ((_indicated_pos.getElevationM() - _last_pos.getElevationM()) * 60 / dt);
   _last_vertical_speed = vertical_speed_mpm * SG_METER_TO_FEET;