diff --git a/README.md b/README.md index 17bc4f527..87c05ddbc 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ k.noise_observation_r = [] { return kalman::observation_noise_uncertainty{ 25 }; }; -k.update(48.54); +k.observe(48.54); ``` ### Multi-Dimensional @@ -99,12 +99,21 @@ k.noise_observation_r = [] { return kalman::observation_noise_uncertainty{ 400 }; }; -k.predict(kalman::input{ gravitational_acceleration }, delta_time); -k.update(kalman::output{ -32.40 }); -k.predict(kalman::input{ 39.72 }, delta_time); -k.update(kalman::output{ -11.1 }); +k.predict(delta_time, gravitational_acceleration); +k.observe(-32.40 ); +k.predict(delta_time, 39.72); +k.observe(-11.1); ``` +# Motivation + +Kalman filters can be difficult to learn, use, and implement. Users often need fair algebra, domain, and software knowledge. Inadequacy leads to incorrectness, underperformance, and a big ball of mud. + +This package explores what could be a Kalman filter implementation a la standard library. The following concerns and tradeoffs are considered: +- Separation of the application domain. +- Separation of the algebra implementation. +- Generalization of the support. + # Resources Awesome resources to learn about Kalman filters: diff --git a/include/fcarouge/kalman.hpp b/include/fcarouge/kalman.hpp index 258a2bc16..1a2e7e3f6 100644 --- a/include/fcarouge/kalman.hpp +++ b/include/fcarouge/kalman.hpp @@ -102,8 +102,9 @@ class kalman //! @name Public Member Function Objects //! @{ + // Functors could be replaced by variables if data is constant. // Functors could be replaced by the standard general-purpose polymorphic - // function wrapper `std::function` if lambda captures are needed. + // function wrappers `std::function` if lambda captures were needed. observation (*transition_observation_h)() = [] { return observation{ Identity()() }; @@ -137,14 +138,14 @@ class kalman //! @{ template - inline constexpr void update(const Outputs &...output_z) + inline constexpr void observe(const Outputs &...output_z) { auto &x{ state_x }; auto &p{ estimate_uncertainty_p }; const auto h{ transition_observation_h() }; const auto r{ noise_observation_r() }; const auto z{ output{ output_z... } }; - fcarouge::update(x, p, h, r, z); + fcarouge::observe(x, p, h, r, z); } template @@ -160,6 +161,17 @@ class kalman fcarouge::predict(x, p, f, q, g, u); } + inline constexpr void + predict(const PredictionArguments &...arguments) requires( + std::is_same_v) + { + auto &x{ state_x }; + auto &p{ estimate_uncertainty_p }; + const auto f{ transition_state_f(arguments...) }; + const auto q{ noise_process_q(arguments...) }; + fcarouge::predict(x, p, f, q); + } + //! @} }; diff --git a/include/fcarouge/kalman_equation.hpp b/include/fcarouge/kalman_equation.hpp index 17a2001b0..4542af324 100644 --- a/include/fcarouge/kalman_equation.hpp +++ b/include/fcarouge/kalman_equation.hpp @@ -143,8 +143,8 @@ template