2
3
4
5
6
7
8
9
10
11
12
13
14
15
17#ifndef GNC_NAVIGATION_EKF_EKF_MEASUREMENT_UPDATE_HPP
18#define GNC_NAVIGATION_EKF_EKF_MEASUREMENT_UPDATE_HPP
20#include "core/Matrix.hpp"
21#include "core/CartesianVector.hpp"
22#include "core/matrixmath.hpp"
23#include "core/vectormath.hpp"
24#include "utils/Measurements.hpp"
25#include "utils/Integrator.hpp"
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 template <
typename T,
unsigned int N,
unsigned int M,
unsigned int O>
73 const std::array<T, N> &state_minus,
const Matrix<T, N, N> &cov_minus,
74 const Matrix<T, M, M> &meas_cov, std::array<T, N> *state_plus,
75 Matrix<T, N, N> *cov_plus);
84 const Matrix<T, M, M> &meas_cov,
Matrix<T, M, M> *residual_cov);
95 std::array<T, M> _est_meas;
98 std::array<T, M*N> _tmp_H_array;
113 template<
typename T,
unsigned int N,
unsigned int M,
unsigned int O>
122 if(residual ==
nullptr || H ==
nullptr) {
127 int err =
measurement_ptr->calculateMeasurements(T(), state, obs_state, _est_meas);
128 if(err) {
return err;}
130 err =
H_ptr->calculateMeasurements(T(), state, obs_state, _tmp_H_array);
132 if(err) {
return err;}
133 H->setFromArray(&_tmp_H_array[0]);
136 for(
unsigned int i = 0; i < M; i++) {
137 (*residual)[i] = measurement[i] - _est_meas[i];
143 template<
typename T,
unsigned int N,
unsigned int M,
unsigned int O>
145 const std::array<T, N> &state_minus,
const Matrix<T, N, N> &cov_minus,
146 const Matrix<T, M, M> &meas_cov, std::array<T, N> *state_plus,
147 Matrix<T, N, N> *cov_plus) {
149 if(state_plus ==
nullptr || cov_plus ==
nullptr) {
154 H.transpose(_H_tspose);
157 _tmp = H*cov_minus*_H_tspose + meas_cov;
158 int err = _tmp.inverse(_tmp_inv);
if(err) {
return err;}
159 _K = cov_minus*_H_tspose*_tmp_inv;
162 _update = _K*residual;
163 for(
unsigned int i = 0; i < N; i++) {
164 (*state_plus)[i] = state_minus[i] + _update[i];
169 _tmp_cov = _tmp_cov - _K*H;
170 (*cov_plus) = _tmp_cov*cov_minus*_tmp_cov.transpose();
175 template<
typename T,
unsigned int N,
unsigned int M,
unsigned int O>
177 const Matrix<T, M, M> &meas_cov,
Matrix<T, M, M> *residual_cov) {
179 H.transpose(_H_tspose);
180 *residual_cov = H*state_cov*_H_tspose + meas_cov;
Standard vector class derived from Matrix.
Definition CartesianVector.hpp:39
Generic, templated EKF measurement update class.
Definition EkfMeasurementUpdate.hpp:50
int calculateMeasurementCovariance(const Matrix< T, M, N > &H, const Matrix< T, N, N > &state_cov, const Matrix< T, M, M > &meas_cov, Matrix< T, M, M > *residual_cov)
Function to generate covariance for measurement update evaluation.
Definition EkfMeasurementUpdate.hpp:176
int generateResidualHMatrix(const std::array< T, N > &state, const std::array< T, O > &obs_state, const std::array< T, M > &measurement, CartesianVector< T, M > *residual, Matrix< T, M, N > *H)
Function to generate residual and H matrix from current state.
Definition EkfMeasurementUpdate.hpp:114
Measurements< T, N, M, O > * measurement_ptr
Pointer to the measurement class to calculate the estimated measurement given the current state of th...
Definition EkfMeasurementUpdate.hpp:88
Measurements< T, N, M *N, O > * H_ptr
Pointer to the measurement class to calculate the H matrix from the estimated spacecraft state.
Definition EkfMeasurementUpdate.hpp:92
int updateState(const CartesianVector< T, M > &residual, const Matrix< T, M, N > &H, const std::array< T, N > &state_minus, const Matrix< T, N, N > &cov_minus, const Matrix< T, M, M > &meas_cov, std::array< T, N > *state_plus, Matrix< T, N, N > *cov_plus)
Function to perform state measurement update in EKF.
Definition EkfMeasurementUpdate.hpp:144
Matrix math implementation.
Definition Matrix.hpp:54
Definition Measurements.hpp:39
#define NO_ERROR
Definition clockwerkerrors.h:31
#define ERROR_NULLPTR
Definition clockwerkerrors.h:57