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
5namespace {
6
8unsigned s_pos = 0;
9unsigned s_writes = 0;
10unsigned s_confirm = 0;
11
12} // namespace
13
15 s_pos = 0;
16 s_writes = 0;
17 s_confirm = 0;
18}
19
20void 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
void apogeeReset()
Definition apogee.cpp:14
bool apogeeShouldConfirm()
Definition apogee.cpp:43
void apogeePushAltitude(float alt_m)
Definition apogee.cpp:20
static constexpr unsigned ALT_TREND_CONFIRM_COUNT
Definition config.h:23
static constexpr float ALT_TREND_THRESHOLD_M
Definition config.h:22
static constexpr unsigned ALT_BUF_N
Definition config.h:21