FastLED 3.9.15
Loading...
Searching...
No Matches
kalman_filter_impl.h
Go to the documentation of this file.
1#pragma once
2
3namespace fl {
4namespace detail {
5
6template <typename T>
8 public:
9 KalmanFilterImpl(T process_noise, T measurement_noise, T initial = T(0))
10 : mQ(process_noise), mR(measurement_noise),
11 mX(initial), mP(T(1.0f)), mLastValue(initial) {}
12
13 T update(T measurement) {
14 mP = mP + mQ;
15 T k = mP / (mP + mR);
16 mX = mX + k * (measurement - mX);
17 mP = (T(1.0f) - k) * mP;
18 mLastValue = mX;
19 return mX;
20 }
21
22 T value() const { return mLastValue; }
23
24 void reset(T initial = T(0)) {
25 mX = initial;
26 mP = T(1.0f);
27 mLastValue = initial;
28 }
29
30 private:
31 T mQ;
32 T mR;
33 T mX;
34 T mP;
36};
37
38} // namespace detail
39} // namespace fl
KalmanFilterImpl(T process_noise, T measurement_noise, T initial=T(0))
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_traits.h:48
Base definition for an LED controller.
Definition crgb.hpp:179