Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
GroundLevelEstimator.cpp
Go to the documentation of this file.
1
#include "
state_estimation/GroundLevelEstimator.h
"
2
3
// Constructor
4
GroundLevelEstimator::GroundLevelEstimator
()
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
9
float
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
30
void
GroundLevelEstimator::launchDetected
() {
31
launched =
true
;
32
// Ground level estimate is now frozen at estimatedGroundLevel_m
33
}
34
35
// Get the estimated ground level
36
float
GroundLevelEstimator::getEGL
()
const
{
37
return
estimatedGroundLevel_m;
38
}
GroundLevelEstimator.h
GroundLevelEstimator::GroundLevelEstimator
GroundLevelEstimator()
Constructs a GroundLevelEstimator.
Definition
GroundLevelEstimator.cpp:4
GroundLevelEstimator::launchDetected
void launchDetected()
Signals that launch has been detected.
Definition
GroundLevelEstimator.cpp:30
GroundLevelEstimator::getEGL
float getEGL() const
Gets the estimated ground level.
Definition
GroundLevelEstimator.cpp:36
GroundLevelEstimator::update
float update(float currentASL_m)
Updates the ground level estimate or converts ASL to AGL.
Definition
GroundLevelEstimator.cpp:9
src
state_estimation
GroundLevelEstimator.cpp
Generated by
1.16.1