Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
FastLaunchDetector.cpp
Go to the documentation of this file.
2
3// #define DEBUG
4#ifdef DEBUG
5#include "ArduinoHAL.h"
6#endif
7
8FastLaunchDetector::FastLaunchDetector(float accelerationThreshold_ms2, uint32_t confirmationWindow_ms) //NOLINT(bugprone-easily-swappable-parameters)
9 : accelerationThresholdSq_ms2(accelerationThreshold_ms2 * accelerationThreshold_ms2),
10 launched(false),
11 launchedTime_ms(0),
12 confirmationWindow_ms(confirmationWindow_ms)
13{}
14
16
17 // Calculate the magnitude of the acceleration squared
18 const float aclMagSq = accel.x.data * accel.x.data + accel.y.data * accel.y.data + accel.z.data * accel.z.data;
19
20 // Take the average of the timestamps
21 // Ideally these should all be the same
22 const uint32_t time_ms = (accel.x.timestamp_ms + accel.y.timestamp_ms + accel.z.timestamp_ms) / 3;
23
24 //if launch already detected, ignore further data
25 if (launched){
26 #ifdef DEBUG
27 Serial.println("FastLaunchDetector: Data point ignored because already launched");
28 #endif
30 }
31
32 //if accel higher than threshold, launch detected
33 if (aclMagSq > accelerationThresholdSq_ms2){
34 launched = true;
35 launchedTime_ms = time_ms;
37 }
38
39 //if accel lower than threshold, acl too low
40 if (aclMagSq < accelerationThresholdSq_ms2) {
41 #ifdef DEBUG
42 Serial.println("FastLaunchDetector: Acceloration below threshold");
43 #endif
44 return FLD_ACL_TOO_LOW;
45 }
46
47 return FLD_DEFAULT_FAIL;
48}
49
51 launched = false;
52 launchedTime_ms = 0;
53}
@ FLD_ACL_TOO_LOW
@ FLD_LAUNCH_DETECTED
@ FLD_ALREADY_LAUNCHED
@ FLD_DEFAULT_FAIL
float data
Definition DataPoint.h:14
uint32_t timestamp_ms
Definition DataPoint.h:13
int update(AccelerationTriplet accel)
FastLaunchDetector(float accelerationThreshold, uint32_t confirmationWindow_ms=500)
MockSerial Serial