Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
GroundLevelEstimator.cpp
Go to the documentation of this file.
2
3// Constructor
5: launched(false), estimatedGroundLevel_m(0.0F), sampleCount(0), alpha(0.1F)
6{}
7
8// Update the ground level estimate or convert ASL to AGL - Altitude ABOVE ground level
9float GroundLevelEstimator::update(float currentASL_m) {
10 // Before launch: accumulate samples to estimate ground level
11 if (!launched) {
12 if (sampleCount == 0) {
13 // Initialize with first sample
14 estimatedGroundLevel_m = currentASL_m;
15 } else {
16 // Exponential moving average: EMA = alpha * newValue + (1 - alpha) * oldEMA
17 estimatedGroundLevel_m = (alpha * currentASL_m) + ((1.0F - alpha) * estimatedGroundLevel_m);
18 }
19 sampleCount++;
20
21 // Still on ground, so AGL is 0
22 return 0.0F;
23 }
24
25 // After launch: convert ASL to AGL
26 return currentASL_m - estimatedGroundLevel_m;
27}
28
29// Signal that launch has been detected
31 launched = true;
32 // Ground level estimate is now frozen at estimatedGroundLevel_m
33}
34
35// Get the estimated ground level
37 return estimatedGroundLevel_m;
38}
GroundLevelEstimator()
Constructs a GroundLevelEstimator.
void launchDetected()
Signals that launch has been detected.
float getEGL() const
Gets the estimated ground level.
float update(float currentASL_m)
Updates the ground level estimate or converts ASL to AGL.