From 8a9869b4fd695ffe5a8e3ff6171ab0623d3fe87d Mon Sep 17 00:00:00 2001 From: s0up Date: Thu, 7 Jun 2018 08:53:28 -0700 Subject: [PATCH 1/4] always set offset when not armed. OSD should never show > 0 values when not armed --- src/main/flight/position.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/flight/position.c b/src/main/flight/position.c index 8d510e7f1..758acc206 100644 --- a/src/main/flight/position.c +++ b/src/main/flight/position.c @@ -49,7 +49,6 @@ void calculateEstimatedAltitude(timeUs_t currentTimeUs) static timeUs_t previousTimeUs = 0; static int32_t baroAltOffset = 0; static int32_t gpsAltOffset = 0; - static bool altitudeOffsetSet = false; const uint32_t dTime = currentTimeUs - previousTimeUs; if (dTime < BARO_UPDATE_FREQUENCY_40HZ) { @@ -87,13 +86,11 @@ if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) { } #endif - if (ARMING_FLAG(ARMED) && !altitudeOffsetSet) { + if (!ARMING_FLAG(ARMED)) { baroAltOffset = baroAlt; gpsAltOffset = gpsAlt; - altitudeOffsetSet = true; - } else if (!ARMING_FLAG(ARMED) && altitudeOffsetSet) { - altitudeOffsetSet = false; } + baroAlt -= baroAltOffset; gpsAlt -= gpsAltOffset; From 96692af0f8895f3aa3490346ab6be8d94cbdb3f7 Mon Sep 17 00:00:00 2001 From: s0up Date: Thu, 7 Jun 2018 13:24:42 -0700 Subject: [PATCH 2/4] dont allow idle tasks to run when disarmed, allow altitude to be absolute on the bench vs relative when flying --- src/main/flight/gps_rescue.c | 5 +++++ src/main/flight/position.c | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/flight/gps_rescue.c b/src/main/flight/gps_rescue.c index 0db7c749d..5d6fa1e03 100644 --- a/src/main/flight/gps_rescue.c +++ b/src/main/flight/gps_rescue.c @@ -293,6 +293,11 @@ void rescueStop() // Things that need to run regardless of GPS rescue mode being enabled or not void idleTasks() { + // Do not calculate any of the idle task values when we are not flying + if (!ARMING_FLAG(ARMED)) { + return; + } + gpsRescueAngle[AI_PITCH] = 0; gpsRescueAngle[AI_ROLL] = 0; diff --git a/src/main/flight/position.c b/src/main/flight/position.c index 758acc206..a9b52962d 100644 --- a/src/main/flight/position.c +++ b/src/main/flight/position.c @@ -89,10 +89,10 @@ if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) { if (!ARMING_FLAG(ARMED)) { baroAltOffset = baroAlt; gpsAltOffset = gpsAlt; + } else { + baroAlt -= baroAltOffset; + gpsAlt -= gpsAltOffset; } - - baroAlt -= baroAltOffset; - gpsAlt -= gpsAltOffset; if (haveGpsAlt && haveBaroAlt) { estimatedAltitude = gpsAlt * gpsTrust + baroAlt * (1 - gpsTrust); From 1b1837905c86aa8131d257d1a2ea4239ff01f2ba Mon Sep 17 00:00:00 2001 From: s0up Date: Thu, 7 Jun 2018 13:34:12 -0700 Subject: [PATCH 3/4] revert position.c changes --- src/main/flight/position.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/flight/position.c b/src/main/flight/position.c index a9b52962d..ced9daff3 100644 --- a/src/main/flight/position.c +++ b/src/main/flight/position.c @@ -86,13 +86,15 @@ if (sensors(SENSOR_GPS) && STATE(GPS_FIX)) { } #endif - if (!ARMING_FLAG(ARMED)) { + if (ARMING_FLAG(ARMED) && !altitudeOffsetSet) { baroAltOffset = baroAlt; gpsAltOffset = gpsAlt; - } else { - baroAlt -= baroAltOffset; - gpsAlt -= gpsAltOffset; + altitudeOffsetSet = true; + } else if (!ARMING_FLAG(ARMED) && altitudeOffsetSet) { + altitudeOffsetSet = false; } + baroAlt -= baroAltOffset; + gpsAlt -= gpsAltOffset; if (haveGpsAlt && haveBaroAlt) { estimatedAltitude = gpsAlt * gpsTrust + baroAlt * (1 - gpsTrust); From b240d745d754eaff2ee8843fc6719223f0ff8e68 Mon Sep 17 00:00:00 2001 From: s0up Date: Thu, 7 Jun 2018 13:35:00 -0700 Subject: [PATCH 4/4] more reverting --- src/main/flight/position.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/flight/position.c b/src/main/flight/position.c index ced9daff3..8d510e7f1 100644 --- a/src/main/flight/position.c +++ b/src/main/flight/position.c @@ -49,6 +49,7 @@ void calculateEstimatedAltitude(timeUs_t currentTimeUs) static timeUs_t previousTimeUs = 0; static int32_t baroAltOffset = 0; static int32_t gpsAltOffset = 0; + static bool altitudeOffsetSet = false; const uint32_t dTime = currentTimeUs - previousTimeUs; if (dTime < BARO_UPDATE_FREQUENCY_40HZ) {