ESPHome  2023.11.6
kalman_combinator.h
Go to the documentation of this file.
1 #pragma once
4 #include <cmath>
5 #include <vector>
6 
7 namespace esphome {
8 namespace kalman_combinator {
9 
11  public:
12  KalmanCombinatorComponent() = default;
13 
14  float get_setup_priority() const override { return esphome::setup_priority::DATA; }
15 
16  void dump_config() override;
17  void setup() override;
18 
19  void add_source(Sensor *sensor, std::function<float(float)> const &stddev);
20  void add_source(Sensor *sensor, float stddev);
21  void set_process_std_dev(float process_std_dev) {
22  this->update_variance_value_ = process_std_dev * process_std_dev * 0.001f;
23  }
24  void set_std_dev_sensor(Sensor *sensor) { this->std_dev_sensor_ = sensor; }
25 
26  private:
27  void update_variance_();
28  void correct_(float value, float stddev);
29 
30  // Source sensors and their error functions
31  std::vector<std::pair<Sensor *, std::function<float(float)>>> sensors_;
32 
33  // Optional sensor for publishing the current error
34  sensor::Sensor *std_dev_sensor_{nullptr};
35 
36  // Tick of the last update
37  uint32_t last_update_{0};
38  // Change of the variance, per ms
39  float update_variance_value_{0.f};
40 
41  // Best guess for the state and its variance
42  float state_{NAN};
43  float variance_{INFINITY};
44 };
45 } // namespace kalman_combinator
46 } // namespace esphome
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:18
void add_source(Sensor *sensor, std::function< float(float)> const &stddev)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57