-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix AGL velocity estimation using squared acceleration weight factor #11255
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?
Fix AGL velocity estimation using squared acceleration weight factor #11255
Conversation
The AGL velocity update was incorrectly using squared acceleration weight factor (sq(accWeightFactor)) while the altitude update uses linear weight. This creates physical inconsistency where position and velocity respond differently to the same acceleration. With accWeightFactor=0.5 (moderate confidence): - Altitude receives 50% of acceleration (correct) - Velocity was receiving 25% of acceleration (wrong - squared) This fix removes sq() from the velocity update to match the altitude update, making both integrations physically consistent with standard kinematic equations. May fix iNavFlight#10314 May be related to iNavFlight#10567
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
| posEstimator.est.aglAlt += posEstimator.est.aglVel * ctx->dt; | ||
| posEstimator.est.aglAlt += posEstimator.imu.accelNEU.z * sq(ctx->dt) / 2.0f * posEstimator.imu.accWeightFactor; | ||
| posEstimator.est.aglVel += posEstimator.imu.accelNEU.z * ctx->dt * sq(posEstimator.imu.accWeightFactor); | ||
| posEstimator.est.aglVel += posEstimator.imu.accelNEU.z * ctx->dt * posEstimator.imu.accWeightFactor; |
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: Clamp the posEstimator.imu.accWeightFactor to a range of 0.0f to 1.0f before its use in the velocity update to prevent potential estimation instability. [general, importance: 6]
| posEstimator.est.aglVel += posEstimator.imu.accelNEU.z * ctx->dt * posEstimator.imu.accWeightFactor; | |
| { | |
| float w = posEstimator.imu.accWeightFactor; | |
| w = fmaxf(0.0f, fminf(1.0f, w)); | |
| posEstimator.est.aglVel += posEstimator.imu.accelNEU.z * ctx->dt * w; | |
| } |
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.
Does the code that sets it allow it to be outside the range of 0.0 - 1.0?
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.
Ask❓
Does the code that sets it allow it to be outside the range of 0.0 - 1.0?
Answer:
Based on the way accWeightFactor is described/used in iNav (and in the linked ticket discussion), the code that computes the accelerometer weight typically constrains the underlying vibration metric and then scales it into a weight range that is ≤ 1.0 (e.g. something like scaling a constrained vibration level [1.0 .. 4.0] into a weight [1.0 .. 0.3]). In that common path, it should not legitimately go outside [0.0, 1.0] (it stays in roughly [0.3, 1.0]).
However, in the diff you’re changing only the use site in estimationCalculateAGL(). There’s nothing here that guarantees posEstimator.imu.accWeightFactor is always bounded—if it can be influenced by:
- an alternative estimator path,
- a config/CLI parameter,
- or any computation that doesn’t clamp (or can produce NaN),
then it could end up outside[0, 1]despite the intended design.
Recommendation: confirm the setter/source of posEstimator.imu.accWeightFactor clamps it (or is derived from a clamped/scaled value). If not, clamping once at the point of computation (preferred) or locally before use (as the bot suggested) would make this update more robust.
User description
Summary
Fixes mathematical inconsistency in AGL velocity estimation where velocity update uses squared acceleration weight factor while altitude update uses linear weight factor.
Problem
In
navigation_pos_estimator_agl.cline 152, the velocity update incorrectly usessq(accWeightFactor)while line 151 (altitude update) correctly uses linearaccWeightFactor. This creates physical inconsistency where position and velocity respond differently to the same acceleration measurement.Impact with accWeightFactor=0.3
Changes
sq()wrapper fromaccWeightFactorin AGL velocity update (line 152)Testing
Code Review
Reviewed with inav-code-review agent - APPROVED. The fix correctly addresses a mathematical inconsistency and makes the kinematic integration physically consistent.
Related Issues
May fix #10314
May be related to #10567
PR Type
Bug fix
Description
Removes squared acceleration weight factor from AGL velocity update
Makes velocity integration consistent with altitude integration
Fixes velocity error during degraded accelerometer conditions
Both altitude and velocity now use linear weight factor scaling
Diagram Walkthrough
File Walkthrough
navigation_pos_estimator_agl.c
Remove squared weight factor from velocity updatesrc/main/navigation/navigation_pos_estimator_agl.c
sq()wrapper fromaccWeightFactorin AGL velocity update atline 152
squared
weight factor
integration