-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add DEBUG_POS_EST logging for position residual debugging #11225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: maintenance-9.x
Are you sure you want to change the base?
Add DEBUG_POS_EST logging for position residual debugging #11225
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.
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]
| 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) |
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]
| 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)); |
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