STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
PtSmoothing.hpp
Go to the documentation of this file.
1#pragma once
2/**
3 * Output smoothing for calibrated PT pressure, per sensor uid (ESP32 and LabJack T7 alike).
4 *
5 * An exponential moving average seeded with the sensor's FIRST reading. It used to live in a
6 * plain std::unordered_map<uint16_t, double> read through operator[], which default-inserts 0.0:
7 * the "not yet set" test (isfinite) then passed on the very first sample, and every PT ramped up
8 * from 0 psi over its first handful of readings (a 300 psi tank archived a 68 psi minimum).
9 */
10#include <cmath>
11#include <cstdint>
12#include <unordered_map>
13
14namespace fsw::calibration {
15
17public:
18 /** 0.25 → roughly a 4-sample effective window. */
19 explicit PtSmoother(double alpha = 0.25) : alpha_(alpha) {
20 }
21
22 /** Feed one reading; returns the smoothed value. The first reading, or the first after a
23 * non-finite one, is passed through unchanged and seeds the average. */
24 double step(uint16_t uid, double value) {
25 auto it = state_.find(uid);
26 if (it == state_.end() || !std::isfinite(it->second)) {
27 state_[uid] = value;
28 return value;
29 }
30 it->second = alpha_ * value + (1.0 - alpha_) * it->second;
31 return it->second;
32 }
33
34 void reset(uint16_t uid) {
35 state_.erase(uid);
36 }
37
38private:
39 double alpha_;
40 std::unordered_map<uint16_t, double> state_;
41};
42
43} // namespace fsw::calibration
std::unordered_map< uint16_t, double > state_
double step(uint16_t uid, double value)
Feed one reading; returns the smoothed value.
PtSmoother(double alpha=0.25)
0.25 → roughly a 4-sample effective window.
Output smoothing for calibrated PT pressure, per sensor uid (ESP32 and LabJack T7 alike).