Improve OSD Glide Slope implementation#11615
Conversation
…zzer-ignore-fix dshot beeper ignore list fix
refactor: update comments to reflect changes in glide ratio calculation
…ulation from position samples
|
Hm, not sure why the commit history includes those dshot fixes, that's odd. Might be because I based my branch on master? |
|
Anyway, I currently still need to implement the following:
|
…rameters via cli variables
…ngs for glide slope configuration
…onditions fix: reset glide buffer when glide ratio conditions are not met
…de void parameter
…osdDrawSingleElement function
…otal sample count
fix: update error display in osdDrawSingleElement function
…raw call and make glideslope available for other functions to allow glideTime and glideDistance to use it for their calculations
refactor: enhance glide range calculation with current glide ratio fix: call enableGlideRatioCalculation in all osd elements using it
Review Summary by QodoRefactor OSD glide slope to use linear regression model
WalkthroughsDescription• Refactor glide slope calculation from instantaneous velocity filtering to linear regression model using altitude and distance samples - Implements lazy-allocated circular buffer for position sampling - Adds configurable sample rate (1-4 Hz) and time frame (5-60 seconds) via CLI - Calculates glide ratio using least-squares linear regression for stability • Improve glide-related OSD elements (glide time, glide range, glide slope) to use calculated glide ratio - Updates glide time calculation to use glide ratio and ground speed - Enhances glide range calculation with current glide ratio and altitude - Ensures glide ratio calculation runs when any glide element is enabled • Add validation checks for glide ratio calculation - Validates descent conditions and throttle state before calculating - Resets buffer when conditions become invalid - Requires minimum sample count before providing valid glide ratio • Fix DShot beeper ignore list handling to prevent unwanted beeping Diagramflowchart LR
A["Position Samples<br/>Distance + Altitude"] -->|"Circular Buffer<br/>Lazy Allocated"| B["Linear Regression<br/>Calculation"]
B -->|"Glide Ratio"| C["OSD Elements<br/>Glide Time/Range/Slope"]
D["Validation<br/>Descent + Throttle"] -->|"Valid Data"| B
E["CLI Settings<br/>Sample Rate/TimeFrame"] -->|"Configure"| A
File Changes1. src/main/io/beeper.c
|
Code Review by Qodo
1.
|
|
I've tested this in HITL and it seems to work a lot better than my approach in the old PR. The default values for the osd_glide_sample_time_frame and osd_glide_sample_rate might need adjusting, but they are ultimately preference. One thing of note is that this implementation can eat a bit of ram. In the worst case, the buffer stores 240x4x2 = 1920 Bytes of data, I have no reference frame for how much RAM usage is too much ram usage in iNav so I can't really tell if this is a concern or not. In most cases the cost will be lower though, for instance at default values it is actually just 20x4x2 = 160 Bytes. |
…eaks and return early
… glide ratio calculations and prevent out of bounds array access
|
I'm gonna keep an updated list of things that still need to be tested here and check it off as I go:
|
This PR refactors the original instantaneous velocity based OSD Glide Slope implementation to instead use absolute altitude and total travel distance sampling and a linear regression model to calculate a more reliable and stable glide slope.
This leads to a more stable and consistent reading of glide related OSD elements.
This is a remake of my older PR (#11520) which tried to achieve the same results via filtering on the instantaneous velocity inputs, but that proved insufficient so I went with this approach instead.
For reference, there are two new variables added to the CLI settings:
description: "Glide slope sampling rate in Hz (1-4 Hz). Higher rates give more responsive glide slope calculations but use more CPU."
field: glide_sample_rate
type: uint8_t
min: 1
max: 4
default_value: 2
description: "Glide slope sampling time frame in seconds (5-60 seconds). Longer frames provide more stable glide slope estimates."
field: glide_sample_time_frame
type: uint8_t
min: 5
max: 60
default_value: 10
These values are ultimately user preference, especially the time frame.
Longer time frame = more stable glide slope but slower to react to changes in conditions.
Shorter time frame = more unstable glide slope but faster to react to changes in conditions