Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/navigation/navigation_pos_estimator.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ void onNewGPSData(void)
static int32_t previousLon;
static int32_t previousAlt;
static bool isFirstGPSUpdate = true;
static bool originAltitudeCorrectionIsActive = true;

gpsLocation_t newLLH;
const timeUs_t currentTimeUs = micros();
Expand Down Expand Up @@ -220,6 +221,15 @@ void onNewGPSData(void)
/* If we were never armed - keep altitude at zero */
geoSetOrigin(&posControl.gpsOrigin, &newLLH, GEO_ORIGIN_RESET_ALTITUDE);
}
else if (ARMING_FLAG(ARMED) && originAltitudeCorrectionIsActive) {
/* Continue updating gps origin altitude after arming if gps epv exceeds max limit
* correcting back to takeoff altitude using estimated altitude */
if (posEstimator.gps.epv >= positionEstimationConfig()->max_eph_epv) {
posControl.gpsOrigin.alt = newLLH.alt - posEstimator.est.pos.z;
} else {
originAltitudeCorrectionIsActive = false;
}
}

if (posControl.gpsOrigin.valid) {
/* Convert LLH position to local coordinates */
Expand Down