17#ifndef GNCUTILS_EKF_EKF_MEASUREMENT_UPDATE_HPP
18#define GNCUTILS_EKF_EKF_MEASUREMENT_UPDATE_HPP
48 template <u
int32 N, u
int32 M, u
int32 O>
62 const std::array<floating_point, N> &state_minus,
63 const std::array<floating_point, O> &obs_state,
64 const std::array<floating_point, M> &measurement,
65 std::array<floating_point, M> *residual);
77 const std::array<floating_point, N> &state_minus,
79 const std::array<floating_point, O> &obs_state,
80 const std::array<floating_point, M> &residual,
81 std::array<floating_point, N> *state_plus,
99 std::array<floating_point, M> _est_meas;
102 std::array<floating_point, M*N> _tmp_H_array;
107 std::array<floating_point, M*M> _tmp_R_array;
130 template <u
int32 N, u
int32 M, u
int32 O>
132 : measurement_ref(measurement_ref) {
133 for(
unsigned int i = 0; i < N; i++) {
134 _identity_n_n[i][i] = 1.0;
138 template <u
int32 N, u
int32 M, u
int32 O>
140 const std::array<floating_point, N> &state_minus,
141 const std::array<floating_point, O> &obs_state,
142 const std::array<floating_point, M> &measurement,
143 std::array<floating_point, M> *residual) {
145 if(residual ==
nullptr) {
150 _error = measurement_ref.calculateMeasurements(time, state_minus, obs_state, _est_meas.data());
151 if(_error) {
return _error;}
154 for(uint32 i = 0; i < M; i++) {
155 (*residual)[i] = measurement[i] - _est_meas[i];
161 template <u
int32 N, u
int32 M, u
int32 O>
163 const std::array<floating_point, N> &state_minus,
165 const std::array<floating_point, O> &obs_state,
166 const std::array<floating_point, M> &residual,
167 std::array<floating_point, N> *state_plus,
170 if(state_plus ==
nullptr || cov_plus ==
nullptr) {
176 _error = measurement_ref.calculateMeasurementsMatrix(time, state_minus, obs_state, _tmp_H_array.data());
177 if (_error) {
return _error;}
178 _H.setFromArray(&_tmp_H_array[0]);
179 _H.transpose(_H_tpose);
182 for(uint32 i = 0; i < N; i++) {
183 for(uint32 j = 0; j < N; j++) {
187 _cov_input[i][j] = cov_minus.
get(i, j);
201 _error = _W.inverse(_W_inv);
202 if (_error) {
return _error;}
207 _residual.setFromArray(&residual[0]);
208 multiply(_K, _residual, _update);
209 for(uint32 i = 0; i < N; i++) {
210 (*state_plus)[i] = state_minus[i] + _update.get(i,0);
Matrix math implementation.
Definition Matrix.hpp:55
int16 get(uint32 row, uint32 col, floating_point &result) const
Function to get a single value in the matrix.
Definition Matrix.hpp:394
int16 generateResidual(floating_point time, const std::array< floating_point, N > &state_minus, const std::array< floating_point, O > &obs_state, const std::array< floating_point, M > &measurement, std::array< floating_point, M > *residual)
Function to generate the residual from the current state.
Definition EkfMeasurementUpdate.hpp:139
int16 runUpdate(floating_point time, const std::array< floating_point, N > &state_minus, const clockwerk::Matrix< N, N > &cov_minus, const std::array< floating_point, O > &obs_state, const std::array< floating_point, M > &residual, std::array< floating_point, N > *state_plus, clockwerk::Matrix< N, N > *cov_plus)
Function to perform state measurement update in EKF.
Definition EkfMeasurementUpdate.hpp:162
void setMeasurementNoiseMatrix(const clockwerk::Matrix< M, M > &R)
Set the R matrix for the measurement update.
Definition EkfMeasurementUpdate.hpp:86
EkfMeasurementUpdate(Measurements< N, M, O > &measurement_ref)
Constructor.
Definition EkfMeasurementUpdate.hpp:131
Definition Measurements.hpp:41
#define NO_ERROR
Error code in the case where matrix math executed successfully.
Definition clockwerkerrors.h:34
#define ERROR_NULLPTR
Error code in case of a null pointer.
Definition clockwerkerrors.h:60
void eSubtract(Matrix< R, C > A, Matrix< R, C > B, Matrix< R, C > &result)
Function to subtract B from A, element-wise.
Definition matrixmath.hpp:221
void eAdd(const Matrix< R, C > &A, const Matrix< R, C > &B, Matrix< R, C > &result)
Function to add two matrices element-wise.
Definition matrixmath.hpp:196
void multiply(const Matrix< R1, C1R2 > &A, const Matrix< C1R2, C2 > &B, Matrix< R1, C2 > &result)
Function to multiply two matrices.
Definition matrixmath.hpp:58
Definition DeadReckon.cpp:20
const floating_point MINIMUM_COV_DIAG_EPSILON
Definition EkfMeasurementUpdate.hpp:25