18 #ifndef KALMAN_FILTER__SRCF_CORE_HPP_ 19 #define KALMAN_FILTER__SRCF_CORE_HPP_ 37 namespace kalman_filter
46 template<
int32_t NumStates,
int32_t ProcessNoiseDim>
51 using square_mat_t = Eigen::Matrix<float32_t, NumStates, NumStates>;
69 template<
int32_t ColN1,
int32_t ColN2>
71 Eigen::Matrix<float32_t, NumStates, ColN1> & A,
72 Eigen::Matrix<float32_t, NumStates, ColN2> & B,
79 for (
index_t j = col_start; j < col_end; ++j) {
82 if (fabsf(g) <= std::numeric_limits<decltype(g)>::epsilon()) {
85 }
else if (fabsf(A(row, row)) <= std::numeric_limits<decltype(g)>::epsilon()) {
87 for (
index_t k = row; k < NumStates; ++k) {
88 const float32_t tau = std::copysign(A(k, row), g);
89 A(k, row) = std::copysign(B(k, j), g);
94 const float32_t ir = 1.0F / std::copysign(sqrtf((f * f) + (g * g)), f);
99 for (
index_t k = row; k < NumStates; ++k) {
100 const float32_t tau = (c * B(k, j)) - (s * A(k, row));
101 A(k, row) = (s * B(k, j)) + (c * A(k, row));
117 template<
int32_t NCols2>
120 Eigen::Matrix<float32_t, NumStates, NCols2> & B,
126 zero_row(A, A, i, i + 1, NumStates);
141 template<
typename Derived>
145 const Eigen::MatrixBase<Derived> & h,
156 throw std::domain_error(
"ScrfCore: measurement noise variance must be positive");
160 for (
index_t idx = NumStates - 1; idx < NumStates && idx >= 0; --idx) {
161 const index_t jdx = NumStates - idx;
162 Eigen::Block<square_mat_t> col = C.block(idx, idx, jdx, 1);
165 (h.block(0, idx, 1, jdx) * col)(0, 0);
169 alpha += (sigma * sigma);
170 m_tau.block(0, 0, jdx, 1) = col;
173 col += zetap * m_k.block(idx, 0, jdx, 1);
174 const float32_t etap = sqrtf(beta / alpha);
178 m_k.block(idx, 0, jdx, 1) += sigma * m_tau.block(0, 0, jdx, 1);
185 throw std::runtime_error(
"ScrfCore: invariant broken, kalman gain must be positive");
189 x += del_alpha * m_k;
192 constexpr
float32_t logf2pi = 1.83787706641F;
195 return -0.5F * (logf2pi + logf(alpha) + (del * del_alpha));
201 static_assert(NumStates > 0U,
"must have positive number of states");
202 static_assert(ProcessNoiseDim > 0U,
"must have positive number of process noise dimensions");
208 #endif // KALMAN_FILTER__SRCF_CORE_HPP_ static void right_lower_triangularize_matrices(square_mat_t &A, Eigen::Matrix< float32_t, NumStates, NCols2 > &B, const index_t b_rank=NCols2)
Triangularize the fat partitioned matrix, [A | B] s.t.: [A' | 0] = [A | B] * T, where A' is lower tri...
Definition: srcf_core.hpp:118
DifferentialEquation f
Definition: kinematic_bicycle.snippet.hpp:44
Eigen::Index index_t
Type for matrix indexing.
Definition: srcf_core.hpp:40
float float32_t
Definition: types.hpp:36
This class is an implementation of the carlson-schmidt temporal and observation update for the square...
Definition: srcf_core.hpp:47
This file includes common type definition.
Eigen::Matrix< float32_t, NumStates, NumStates > square_mat_t
Definition: srcf_core.hpp:51
float32_t scalar_update(const float32_t z, const float32_t r, const Eigen::MatrixBase< Derived > &h, square_mat_t &C, state_vec_t &x)
do the Carlson first-order observation update, assumes uncorrelated measurement noise ...
Definition: srcf_core.hpp:142
static void zero_row(Eigen::Matrix< float32_t, NumStates, ColN1 > &A, Eigen::Matrix< float32_t, NumStates, ColN2 > &B, const index_t row, const index_t col_start, const index_t col_end)
Applies the right triangularization operation on a single row, e.g. implicitly applying the givens ro...
Definition: srcf_core.hpp:70
Eigen::Matrix< float32_t, NumStates, 1 > state_vec_t
Definition: srcf_core.hpp:50
IntermediateState beta
Definition: kinematic_bicycle.snippet.hpp:42
DifferentialState x
Definition: kinematic_bicycle.snippet.hpp:28
std::size_t Index
Index type for identifying bins of the hash/lattice.
Definition: spatial_hash_config.hpp:49
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24