Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
ApogeeDetector.cpp
Go to the documentation of this file.
2#include <cmath>
3
4// Constructor
5ApogeeDetector::ApogeeDetector(float apogeeThreshold_m)
6: apogeeThreshold_m(apogeeThreshold_m)
7{}
8
9// Initialize the filter state
11 apogee_flag = false;
12
13 maxAltitude = initialState.initialAltitude;
14 maxAltitudeTimestamp = initialState.initialTimestamp;
15}
16
17// Update the filter with new sensor data.
18void ApogeeDetector::update(VerticalVelocityEstimator* verticalVelocityEstimator) {
19
20 const float estimated_altitude_meters = verticalVelocityEstimator->getEstimatedAltitude();
21
22 // Update maximum altitude seen so far.
23 if (estimated_altitude_meters > maxAltitude) {
24 maxAltitude = estimated_altitude_meters;
25 maxAltitudeTimestamp = verticalVelocityEstimator->getTimestamp();
26 }
27
28 // Apogee detection: if the current estimated altitude is at least apogeeThreshold_m
29 // below the maximum and the estimated velocity is negative, mark apogee.
30 if (!apogee_flag && ((maxAltitude - estimated_altitude_meters) >= apogeeThreshold_m) && (verticalVelocityEstimator->getEstimatedVelocity() < 0)) {
31 apogee_flag = true;
32 // (Optionally, you could “snap” the altitude to maxAltitude here.)
33 }
34}
35
36// Return true if apogee has been detected.
38 return apogee_flag;
39}
40
41// Get the detected apogee as a DataPoint.
42// If apogee has not been detected, returns a DataPoint with timestamp 0 and altitude 0.
44 if (apogee_flag) {
45 return {maxAltitudeTimestamp, maxAltitude};
46 }
47 return {0, 0.0F};
48}
bool isApogeeDetected() const
Checks if apogee has been detected.
DataPoint getApogee() const
Retrieves the detected apogee.
void update(VerticalVelocityEstimator *verticalVelocityEstimator)
Updates the detector using the latest estimated altitude and vertical velocity.
void init(ApogeeDetectorInitialState initialState)
Initializes the detector with the starting altitude and timestamp.
ApogeeDetector()
Constructs an ApogeeDetector with the default threshold of 1.0 meter.
Timestamped float measurement container.
Definition DataPoint.h:11
1D Kalman filter fusing altimeter and accelerometer data.
virtual uint32_t getTimestamp() const
Represents the initial state for initializing the ApogeeDetector.
float initialAltitude
Initial altitude in meters.
uint32_t initialTimestamp
Initial timestamp in milliseconds.