STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
apogee.cpp
Go to the documentation of this file.
1
#include "
apogee.h
"
2
3
#include "
config.h
"
4
5
namespace
{
6
7
float
s_alt
[
ALT_BUF_N
];
8
unsigned
s_pos
= 0;
9
unsigned
s_writes
= 0;
10
unsigned
s_confirm
= 0;
11
12
}
// namespace
13
14
void
apogeeReset
() {
15
s_pos
= 0;
16
s_writes
= 0;
17
s_confirm
= 0;
18
}
19
20
void
apogeePushAltitude
(
float
alt_m) {
21
s_alt
[
s_pos
] = alt_m;
22
s_pos
= (
s_pos
+ 1U) %
ALT_BUF_N
;
23
s_writes
++;
24
if
(
s_writes
<
ALT_BUF_N
)
25
return
;
26
27
float
older = 0.f;
28
float
recent = 0.f;
29
for
(
unsigned
i = 0; i <
ALT_BUF_N
/ 2U; i++)
30
older +=
s_alt
[(
s_pos
+ i) %
ALT_BUF_N
];
31
for
(
unsigned
i = 0; i <
ALT_BUF_N
/ 2U; i++)
32
recent +=
s_alt
[(
s_pos
+
ALT_BUF_N
/ 2U + i) %
ALT_BUF_N
];
33
older /=
static_cast<
float
>
(
ALT_BUF_N
/ 2U);
34
recent /=
static_cast<
float
>
(
ALT_BUF_N
/ 2U);
35
const
float
trend = recent - older;
36
37
if
(trend < -
ALT_TREND_THRESHOLD_M
)
38
s_confirm
++;
39
else
40
s_confirm
= 0;
41
}
42
43
bool
apogeeShouldConfirm
() {
44
return
s_confirm
>=
ALT_TREND_CONFIRM_COUNT
;
45
}
apogeeReset
void apogeeReset()
Definition
apogee.cpp:14
apogeeShouldConfirm
bool apogeeShouldConfirm()
Definition
apogee.cpp:43
apogeePushAltitude
void apogeePushAltitude(float alt_m)
Definition
apogee.cpp:20
apogee.h
config.h
ALT_TREND_CONFIRM_COUNT
static constexpr unsigned ALT_TREND_CONFIRM_COUNT
Definition
config.h:23
ALT_TREND_THRESHOLD_M
static constexpr float ALT_TREND_THRESHOLD_M
Definition
config.h:22
ALT_BUF_N
static constexpr unsigned ALT_BUF_N
Definition
config.h:21
anonymous_namespace{apogee.cpp}::s_confirm
unsigned s_confirm
Definition
apogee.cpp:10
anonymous_namespace{apogee.cpp}::s_writes
unsigned s_writes
Definition
apogee.cpp:9
anonymous_namespace{apogee.cpp}::s_alt
float s_alt[ALT_BUF_N]
Definition
apogee.cpp:7
anonymous_namespace{apogee.cpp}::s_pos
unsigned s_pos
Definition
apogee.cpp:8
firmware
DAN-E Avionics
src
apogee.cpp
Generated by
1.15.0