Add DEBUG_POS_EST logging for position residual debugging#11225
Open
sensei-hacker wants to merge 1 commit intoiNavFlight:maintenance-9.xfrom
Open
Add DEBUG_POS_EST logging for position residual debugging#11225sensei-hacker wants to merge 1 commit intoiNavFlight:maintenance-9.xfrom
sensei-hacker wants to merge 1 commit intoiNavFlight:maintenance-9.xfrom
Conversation
Enables comprehensive GPS update debugging for Issue iNavFlight#11202 investigation. When debug_mode = 76 (DEBUG_POS_EST), captures during GPS updates (~5Hz): - debug[0]: GPS EPH from receiver (cm × 100) - debug[1]: Unfiltered EPH input = MAX(GPS_eph, residual) (cm × 100) - debug[2]: Position residual magnitude (cm × 100) - debug[3]: GPS position weight × 10000 - debug[4]: Position residual X component (cm) - debug[5]: Position residual Y component (cm) - debug[6]: Current estimated EPH before update (cm × 100) - debug[7]: New EPH after filtering (cm × 100) This provides direct measurement of: 1. How far position estimate diverges from GPS (residual) 2. How much GPS is trusted during updates (weight) 3. Unfiltered vs filtered EPH values Critical for understanding position estimator behavior during high-G maneuvers where ~2m position divergence was observed.
Contributor
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
Comment on lines
+705
to
+706
| DEBUG_SET(DEBUG_POS_EST, 4, (int32_t)(gpsPosXResidual)); // Position residual X (cm) | ||
| DEBUG_SET(DEBUG_POS_EST, 5, (int32_t)(gpsPosYResidual)); // Position residual Y (cm) |
Contributor
There was a problem hiding this comment.
Suggestion: To ensure consistency with the comment indicating centimeters, multiply gpsPosXResidual and gpsPosYResidual by 100 before casting them for the debug output. [possible issue, importance: 7]
Suggested change
| DEBUG_SET(DEBUG_POS_EST, 4, (int32_t)(gpsPosXResidual)); // Position residual X (cm) | |
| DEBUG_SET(DEBUG_POS_EST, 5, (int32_t)(gpsPosYResidual)); // Position residual Y (cm) | |
| DEBUG_SET(DEBUG_POS_EST, 4, (int32_t)(gpsPosXResidual * 100)); // Position residual X (cm) | |
| DEBUG_SET(DEBUG_POS_EST, 5, (int32_t)(gpsPosYResidual * 100)); // Position residual Y (cm) |
Comment on lines
+701
to
+708
| DEBUG_SET(DEBUG_POS_EST, 0, (int32_t)(posEstimator.gps.eph * 100)); // GPS EPH from receiver (cm) | ||
| DEBUG_SET(DEBUG_POS_EST, 1, (int32_t)(gps_eph_input * 100)); // Unfiltered EPH input = MAX(GPS_eph, residual) (cm) | ||
| DEBUG_SET(DEBUG_POS_EST, 2, (int32_t)(gpsPosResidualMag * 100)); // Position residual magnitude (cm) | ||
| DEBUG_SET(DEBUG_POS_EST, 3, (int32_t)(w_xy_gps_p * 10000)); // GPS position weight × 10000 | ||
| DEBUG_SET(DEBUG_POS_EST, 4, (int32_t)(gpsPosXResidual)); // Position residual X (cm) | ||
| DEBUG_SET(DEBUG_POS_EST, 5, (int32_t)(gpsPosYResidual)); // Position residual Y (cm) | ||
| DEBUG_SET(DEBUG_POS_EST, 6, (int32_t)(posEstimator.est.eph * 100)); // Current estimated EPH before update (cm) | ||
| DEBUG_SET(DEBUG_POS_EST, 7, (int32_t)(ctx->newEPH * 100)); // New EPH after filtering (cm) |
Contributor
There was a problem hiding this comment.
Suggestion: Protect the debug casts by checking for non-finite values and clamping to int32_t range to avoid undefined/implementation-defined behavior when NaN/Inf or huge values occur. [Learned best practice, importance: 5]
Suggested change
| DEBUG_SET(DEBUG_POS_EST, 0, (int32_t)(posEstimator.gps.eph * 100)); // GPS EPH from receiver (cm) | |
| DEBUG_SET(DEBUG_POS_EST, 1, (int32_t)(gps_eph_input * 100)); // Unfiltered EPH input = MAX(GPS_eph, residual) (cm) | |
| DEBUG_SET(DEBUG_POS_EST, 2, (int32_t)(gpsPosResidualMag * 100)); // Position residual magnitude (cm) | |
| DEBUG_SET(DEBUG_POS_EST, 3, (int32_t)(w_xy_gps_p * 10000)); // GPS position weight × 10000 | |
| DEBUG_SET(DEBUG_POS_EST, 4, (int32_t)(gpsPosXResidual)); // Position residual X (cm) | |
| DEBUG_SET(DEBUG_POS_EST, 5, (int32_t)(gpsPosYResidual)); // Position residual Y (cm) | |
| DEBUG_SET(DEBUG_POS_EST, 6, (int32_t)(posEstimator.est.eph * 100)); // Current estimated EPH before update (cm) | |
| DEBUG_SET(DEBUG_POS_EST, 7, (int32_t)(ctx->newEPH * 100)); // New EPH after filtering (cm) | |
| static inline int32_t debugFloatToI32(const float v) | |
| { | |
| if (!isfinite(v)) { | |
| return 0; | |
| } | |
| if (v > (float)INT32_MAX) { | |
| return INT32_MAX; | |
| } | |
| if (v < (float)INT32_MIN) { | |
| return INT32_MIN; | |
| } | |
| return (int32_t)v; | |
| } | |
| DEBUG_SET(DEBUG_POS_EST, 0, debugFloatToI32(posEstimator.gps.eph * 100.0f)); | |
| DEBUG_SET(DEBUG_POS_EST, 1, debugFloatToI32(gps_eph_input * 100.0f)); | |
| DEBUG_SET(DEBUG_POS_EST, 2, debugFloatToI32(gpsPosResidualMag * 100.0f)); | |
| DEBUG_SET(DEBUG_POS_EST, 3, debugFloatToI32(w_xy_gps_p * 10000.0f)); | |
| DEBUG_SET(DEBUG_POS_EST, 6, debugFloatToI32(posEstimator.est.eph * 100.0f)); | |
| DEBUG_SET(DEBUG_POS_EST, 7, debugFloatToI32(ctx->newEPH * 100.0f)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Summary
Debug build for investigating position estimate divergence during high-G maneuvers.
For debugging #11202
Changes
Adds comprehensive GPS update logging to DEBUG_POS_EST mode (76):
Purpose
Captures critical metrics to understand why position estimate diverges ~2m from GPS during 4.3G maneuvers:
Testing
This is a debug/diagnostic build - not intended for merge to main branch.
Enables test flights to capture position estimator internal state for issue analysis.
Usage
Debug field mapping documented in commit message.
PR Type
Enhancement
Description
Add comprehensive GPS update logging to DEBUG_POS_EST mode
Capture position residual magnitude and components for diagnostics
Log GPS weight and EPH filtering behavior for analysis
Support investigation of position estimate divergence during high-G maneuvers
Diagram Walkthrough
File Walkthrough
navigation_pos_estimator.c
Add GPS update debug logging for position estimatorsrc/main/navigation/navigation_pos_estimator.c
gps_eph_inputcalculation into variable for clarity and reuseestimation
filtered EPH