Skip to content

Commit f7e6c28

Browse files
authored
Merge pull request #66 from CURocketEngineering/feature/gle
feat: Add initial implementation of GLE
2 parents 5edfc95 + 4f70fb1 commit f7e6c28

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#ifndef AGL_DETECTOR_H
2+
#define AGL_DETECTOR_H
3+
#include <cstdint>
4+
/*
5+
TWO RULES - 2 input functions, 1 output:
6+
7+
input
8+
Update function: current ASL in meters as a DataPoint type
9+
Launch Dectcted: Call this when launch has happened (MUST BE SURE)
10+
11+
output
12+
GetEGL (estimated ground level), returns a float that represents how many meters above sealevel the rocket was before launch
13+
*/
14+
15+
class GroundLevelEstimator{
16+
public:
17+
/**
18+
* @brief Constructs a GroundLevelEstimator.
19+
*/
20+
GroundLevelEstimator();
21+
22+
/**
23+
* @brief Updates the ground level estimate or converts ASL to AGL.
24+
*
25+
* Before launch: Records altitude samples to estimate ground level.
26+
* After launch: Converts the provided ASL altitude to AGL. *
27+
* @param currentASL_m Current altitude above sea level in meters.
28+
* @return Current altitude above ground level in meters.
29+
*/
30+
float update(float currentASL_m);
31+
32+
/**
33+
* @brief Signals that launch has been detected.
34+
*
35+
* Stops recording ground level measurements and freezes the EGL.
36+
* Should be called once when launch is confirmed.
37+
*/
38+
void launchDeteched();
39+
40+
/**
41+
* @brief Gets the estimated ground level.
42+
*
43+
* @return Altitude above sea level at the launch site in meters.
44+
*/
45+
float getEGL() const;
46+
47+
private:
48+
49+
bool launched = false; //Turned true if launch is detected
50+
float estimatedGroundLevel_m = 0.0F; //EGL in meters
51+
uint32_t sampleCount = 0; //Number of samples used for ground level estimate
52+
53+
};
54+
55+
#endif
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "state_estimation/GroundLevelEstimator.h"
2+
3+
// Constructor
4+
GroundLevelEstimator::GroundLevelEstimator()
5+
: launched(false), estimatedGroundLevel_m(0.0F), sampleCount(0)
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+
11+
// Before launch: accumulate samples to estimate ground level
12+
if (!launched) {
13+
// Running average of ground level samples
14+
estimatedGroundLevel_m = ((estimatedGroundLevel_m * sampleCount) + currentASL_m) / (sampleCount + 1);
15+
sampleCount++;
16+
17+
// Still on ground, so AGL is 0
18+
return 0.0F;
19+
}
20+
21+
// After launch: convert ASL to AGL
22+
return currentASL_m - estimatedGroundLevel_m;
23+
}
24+
25+
// Signal that launch has been detected
26+
void GroundLevelEstimator::launchDeteched() {
27+
launched = true;
28+
// Ground level estimate is now frozen at estimatedGroundLevel_m
29+
}
30+
31+
// Get the estimated ground level
32+
float GroundLevelEstimator::getEGL() const {
33+
return estimatedGroundLevel_m;
34+
}

0 commit comments

Comments
 (0)