Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
FastLaunchDetector.cpp
Go to the documentation of this file.
1
#include "
state_estimation/FastLaunchDetector.h
"
2
3
// #define DEBUG
4
#ifdef DEBUG
5
#include "
ArduinoHAL.h
"
6
#endif
7
8
FastLaunchDetector::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
15
int
FastLaunchDetector::update
(
AccelerationTriplet
accel){
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
29
return
FLD_ALREADY_LAUNCHED
;
30
}
31
32
//if accel higher than threshold, launch detected
33
if
(aclMagSq > accelerationThresholdSq_ms2){
34
launched =
true
;
35
launchedTime_ms = time_ms;
36
return
FLD_LAUNCH_DETECTED
;
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
50
void
FastLaunchDetector::reset
(){
51
launched =
false
;
52
launchedTime_ms = 0;
53
}
ArduinoHAL.h
FastLaunchDetector.h
FLD_ACL_TOO_LOW
@ FLD_ACL_TOO_LOW
Definition
FastLaunchDetector.h:14
FLD_LAUNCH_DETECTED
@ FLD_LAUNCH_DETECTED
Definition
FastLaunchDetector.h:12
FLD_ALREADY_LAUNCHED
@ FLD_ALREADY_LAUNCHED
Definition
FastLaunchDetector.h:13
FLD_DEFAULT_FAIL
@ FLD_DEFAULT_FAIL
Definition
FastLaunchDetector.h:15
DataPoint::data
float data
Definition
DataPoint.h:14
DataPoint::timestamp_ms
uint32_t timestamp_ms
Definition
DataPoint.h:13
FastLaunchDetector::update
int update(AccelerationTriplet accel)
Definition
FastLaunchDetector.cpp:15
FastLaunchDetector::reset
void reset()
Definition
FastLaunchDetector.cpp:50
FastLaunchDetector::FastLaunchDetector
FastLaunchDetector(float accelerationThreshold, uint32_t confirmationWindow_ms=500)
Definition
FastLaunchDetector.cpp:8
Serial
MockSerial Serial
AccelerationTriplet
Definition
StateEstimationTypes.h:6
AccelerationTriplet::z
DataPoint z
Definition
StateEstimationTypes.h:9
AccelerationTriplet::y
DataPoint y
Definition
StateEstimationTypes.h:8
AccelerationTriplet::x
DataPoint x
Definition
StateEstimationTypes.h:7
src
state_estimation
FastLaunchDetector.cpp
Generated by
1.16.1