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
15
16// Potential returns from the update function
17// Positive values are errors
18// Negative values are warnings
22 LP_YOUNGER_TIMESTAMP = -2, // The timestamp is younger than the last timestamp
23 LP_INITIAL_POPULATION = -3, // The window is not full yet
24 LP_DATA_TOO_FAST = -4, // The data came in faster than the desired window
25 LP_WINDOW_DATA_STALE = 1, // The data given makes the window data relatively too old, resets the window
26 LP_WINDOW_TIME_RANGE_TOO_SMALL = -5, // The window is full, but the time difference between the head and the tail is too little
27 LP_WINDOW_TIME_RANGE_TOO_LARGE = -6, // The window is full, but the time difference between the head and the tail is too large
28 LP_WINDOW_NOT_FULL = -7, // The window is not full yet
29 LP_ACL_TOO_LOW = -8, // The acceleration is too low for launch
31};
32
49{
50public:
61 LaunchDetector(float accelerationThreshold_ms2,
62 uint16_t windowSize_ms,
63 uint16_t windowInterval_ms);
64
70 int update(AccelerationTriplet accel);
71 bool isLaunched() {return launched;}
72 uint32_t getLaunchedTime() {return launchedTime_ms;}
73 float getMedianAccelerationSquared() {return median_acceleration_squared;}
74 void reset();
75
76 // --------------
77 // Testing Methods
78 // --------------
79 // Gives a pointer to the window
80 CircularArray<DataPoint>* getWindowPtr() {return &AclMagSqWindow_ms2;}
81 // Gives the threshold in ms^2 squared
82 float getThreshold() {return accelerationThresholdSq_ms2;}
83 // Gives the window interval in ms
84 uint16_t getWindowInterval() {return windowInterval_ms;}
85 uint16_t getAcceptableTimeDifference() {return acceptableTimeDifference_ms;}
86
87
88private:
89 // The threshold for acceleration to be considered a launch squared
90 float accelerationThresholdSq_ms2;
91 uint16_t windowInterval_ms;
92
93 // Min and max window sizes calculated as +- 10% of the window size
94 uint16_t min_window_size_ms = 0; // If the calculated time range is less than this, don't try to detect launch
95 uint16_t max_window_size_ms = 0; // If the calculated time range is greater than this, don't try to detect launch
96
97 uint16_t acceptableTimeDifference_ms;
98 // The window holding the acceleration magnitude squared b/c sqrt is expensive
99 CircularArray<DataPoint> AclMagSqWindow_ms2;
100 bool launched;
101 uint32_t launchedTime_ms;
102
103 float median_acceleration_squared;
104};
105
106#endif
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()
CircularArray< DataPoint > * getWindowPtr()
int update(AccelerationTriplet accel)