Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
LaunchDetector.h
Go to the documentation of this file.
1/*
2 * Simple launch prediction algorithm
3 * Simply, create an instance of this class and update it with
4 * new acceleration data as often as possible.
5 */
6
7#ifndef LAUNCH_DETECTOR_H
8#define LAUNCH_DETECTOR_H
9
13
15constexpr std::size_t CIRCULAR_ARRAY_ALLOCATED_SLOTS = 100; // 100 slots allocated for the circular array (100 * sizeof(DataPoint)) = 800 bytes allocated)
16
17// Potential returns from the update function
18// Positive values are errors
19// Negative values are warnings
23 LP_YOUNGER_TIMESTAMP = -2, // The timestamp is younger than the last timestamp
24 LP_INITIAL_POPULATION = -3, // The window is not full yet
25 LP_DATA_TOO_FAST = -4, // The data came in faster than the desired window
26 LP_WINDOW_DATA_STALE = 1, // The data given makes the window data relatively too old, resets the window
27 LP_WINDOW_TIME_RANGE_TOO_SMALL = -5, // The window is full, but the time difference between the head and the tail is too little
28 LP_WINDOW_TIME_RANGE_TOO_LARGE = -6, // The window is full, but the time difference between the head and the tail is too large
29 LP_WINDOW_NOT_FULL = -7, // The window is not full yet
30 LP_ACL_TOO_LOW = -8, // The acceleration is too low for launch
32};
33
50{
51public:
62 LaunchDetector(float accelerationThreshold_ms2,
63 uint16_t windowSize_ms,
64 uint16_t windowInterval_ms);
65
71 int update(AccelerationTriplet accel);
72 bool isLaunched() {return launched;}
73 uint32_t getLaunchedTime() {return launchedTime_ms;}
74 float getMedianAccelerationSquared() {return median_acceleration_squared;}
75 void reset();
76
77 // --------------
78 // Testing Methods
79 // --------------
80 // Gives a pointer to the window
82 // Gives the threshold in ms^2 squared
83 float getThreshold() {return accelerationThresholdSq_ms2;}
84 // Gives the window interval in ms
85 uint16_t getWindowInterval() {return windowInterval_ms;}
86 uint16_t getAcceptableTimeDifference() {return acceptableTimeDifference_ms;}
87
88
89private:
90 // The threshold for acceleration to be considered a launch squared
91 float accelerationThresholdSq_ms2;
92 uint16_t windowInterval_ms;
93
94 // Min and max window sizes calculated as +- 10% of the window size
95 uint16_t min_window_size_ms = 0; // If the calculated time range is less than this, don't try to detect launch
96 uint16_t max_window_size_ms = 0; // If the calculated time range is greater than this, don't try to detect launch
97
98 uint16_t acceptableTimeDifference_ms;
99 // The window holding the acceleration magnitude squared b/c sqrt is expensive
101 bool launched;
102 uint32_t launchedTime_ms;
103
104 float median_acceleration_squared;
105};
106
107#endif
constexpr std::size_t CIRCULAR_ARRAY_ALLOCATED_SLOTS
LaunchDetectorStatus
@ LP_LAUNCH_DETECTED
@ LP_WINDOW_NOT_FULL
@ LP_ACL_TOO_LOW
@ LP_INITIAL_POPULATION
@ LP_DEFAULT_FAIL
@ LP_DATA_TOO_FAST
@ LP_WINDOW_TIME_RANGE_TOO_LARGE
@ LP_YOUNGER_TIMESTAMP
@ LP_WINDOW_DATA_STALE
@ LP_WINDOW_TIME_RANGE_TOO_SMALL
@ LP_ALREADY_LAUNCHED
constexpr float ACCEPTABLE_PERCENT_DIFFERENCE_WINDOW_INTERVAL
Fixed-size circular buffer with median helper and head tracking.
uint32_t getLaunchedTime()
LaunchDetector(float accelerationThreshold_ms2, uint16_t windowSize_ms, uint16_t windowInterval_ms)
float getMedianAccelerationSquared()
uint16_t getAcceptableTimeDifference()
uint16_t getWindowInterval()
int update(AccelerationTriplet accel)
CircularArray< DataPoint, CIRCULAR_ARRAY_ALLOCATED_SLOTS > * getWindowPtr()