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 kCircularArrayAllocatedSlots = 100; // 100 slots allocated for the circular array (100 * sizeof(DataPoint)) = 800 bytes allocated)
17 "LaunchDetector window allocation must fit CircularArray's uint8_t max size");
18
19// Potential returns from the update function
20// Positive values are errors
21// Negative values are warnings
25 LP_YOUNGER_TIMESTAMP = -2, // The timestamp is younger than the last timestamp
26 LP_INITIAL_POPULATION = -3, // The window is not full yet
27 LP_DATA_TOO_FAST = -4, // The data came in faster than the desired window
28 LP_WINDOW_DATA_STALE = 1, // The data given makes the window data relatively too old, resets the window
29 LP_WINDOW_TIME_RANGE_TOO_SMALL = -5, // The window is full, but the time difference between the head and the tail is too little
30 LP_WINDOW_TIME_RANGE_TOO_LARGE = -6, // The window is full, but the time difference between the head and the tail is too large
31 LP_WINDOW_NOT_FULL = -7, // The window is not full yet
32 LP_ACL_TOO_LOW = -8, // The acceleration is too low for launch
34};
35
52{
53public:
64 LaunchDetector(float accelerationThreshold_ms2,
65 uint16_t windowSize_ms,
66 uint16_t windowInterval_ms);
67
73 int update(AccelerationTriplet accel);
74 bool isLaunched() {return launched_;}
75 uint32_t getLaunchedTime() {return launchedTime_ms_;}
76 float getMedianAccelerationSquared() {return medianAccelerationSquared_;}
77 void reset();
78
79 // --------------
80 // Testing Methods
81 // --------------
82 // Gives a pointer to the window
84 // Gives the threshold in ms^2 squared
85 float getThreshold() {return accelerationThresholdSq_ms2_;}
86 // Gives the window interval in ms
87 uint16_t getWindowInterval() {return windowInterval_ms_;}
88 uint16_t getAcceptableTimeDifference() {return acceptableTimeDifference_ms_;}
89
90
91private:
92 // The threshold for acceleration to be considered a launch squared
93 float accelerationThresholdSq_ms2_;
94 uint16_t windowInterval_ms_;
95
96 // Min and max window sizes calculated based on the window interval and the acceptable time difference
97 uint16_t minWindowSize_ms_ = 0; // If the calculated time range is less than this, don't try to detect launch
98 uint16_t maxWindowSize_ms_ = 0; // If the calculated time range is greater than this, don't try to detect launch
99
100 uint16_t acceptableTimeDifference_ms_;
101 // The window holding the acceleration magnitude squared b/c sqrt is expensive
103 bool launched_;
104 uint32_t launchedTime_ms_;
105
106 float medianAccelerationSquared_;
107};
108
109#endif
constexpr std::size_t kMaxCircularArrayCapacity
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 std::size_t kCircularArrayAllocatedSlots
constexpr float kAcceptablePercentDifferenceWindowInterval
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, kCircularArrayAllocatedSlots > * getWindowPtr()