ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
EkfTimeUpdate.hpp
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16
17#ifndef GNC_NAVIGATION_EKF_EKF_TIME_UPDATE_HPP
18#define GNC_NAVIGATION_EKF_EKF_TIME_UPDATE_HPP
19
20#include "core/Matrix.hpp"
21#include "core/CartesianVector.hpp"
22#include "core/matrixmath.hpp"
23#include "core/vectormath.hpp"
24#include "utils/Rates.hpp"
25#include "utils/Integrator.hpp"
26
27namespace clockwerk {
28
29 /**
30 * @brief Class to perform EKF time update step
31 */
32 template <typename T, unsigned int N>
33 class EkfTimeUpdate {
34 public:
35 /// @brief Function to run a single extended kalman filter time update step
36 /// @param time_prev The time at which the previous state and covariance are known
37 /// @param state_prev The previous state as an N element state vector
38 /// @param cov_prev The previous covariance as an N*N matrix
39 /// @param time_up The time to which the state and covariance will be propagated
40 /// @param state_up The updated state at time time_up
41 /// @param cov_up The updated covariance at time time_up
42 /// @return Error code corresponding to success/failure
43 int runUpdate(T time_prev, const std::array<T, N> &state_prev, const Matrix<T, N, N> &cov_prev,
44 T time_up, std::array<T, N> *state_up, Matrix<T, N, N> *cov_up);
45
46 /// The integrator to be used internally by the EKF stepper.
47 /// This integrator should be pre-configured to use a rates
48 /// function with size N + N*N to propagate dynamics
49 /// In most cases should probably be RK4
50 Integrator<T, N + N*N>* integrator_ptr = nullptr;
51
52 /// @brief Optional return of the phi matrix calculated by EKF
53 Matrix<T, N, N> phi;
54 private:
55 std::array<T, N + N*N> _full_state_initial;
56 std::array<T, N + N*N> _full_state_post;
57 Matrix<T, N, N> _phi_transpose;
58 };
59
60 template<typename T, unsigned int N>
61 int EkfTimeUpdate<T, N>::runUpdate(T time_prev, const std::array<T, N> &state_prev, const Matrix<T, N, N> &cov_prev,
62 T time_up, std::array<T, N> *state_up, Matrix<T, N, N> *cov_up) {
63 // First ensure our rates and integrator are valid
64 if(integrator_ptr == nullptr) {
65 return ERROR_NULLPTR;
66 }
67
68 // Now generate a full state vector including our phi matrix
69 unsigned int one_idx = N;
70 for(unsigned int i = 0; i < N + N*N; i++) {
71 if(i < N) {
72 _full_state_initial[i] = state_prev[i];
73 } else if(i == one_idx) {
74 _full_state_initial[i] = 1.0;
75 one_idx = one_idx + N + 1;
76 } else {
77 _full_state_initial[i] = 0.0;
78 }
79 }
80
81 // Now propagate
82 integrator_ptr->step(time_prev, time_up, _full_state_initial, _full_state_post);
83
84 // Now extract our Phi matrix, then use it to propagate forward covariance
85 phi.setFromArray(&_full_state_post[N]);
86 phi.transpose(_phi_transpose);
87
88 // Finally, set our output state and updated covariance matrix
89 for(unsigned int i = 0; i < N; i++) {
90 (*state_up)[i] = _full_state_post[i];
91 }
92 *cov_up = phi*cov_prev*_phi_transpose;
93
94 return NO_ERROR;
95 }
96
97}
98
99#endif
Class to perform EKF time update step.
Definition EkfTimeUpdate.hpp:33
Matrix< T, N, N > phi
Optional return of the phi matrix calculated by EKF.
Definition EkfTimeUpdate.hpp:53
Integrator< T, N+N *N > * integrator_ptr
The integrator to be used internally by the EKF stepper. This integrator should be pre-configured to ...
Definition EkfTimeUpdate.hpp:50
int runUpdate(T time_prev, const std::array< T, N > &state_prev, const Matrix< T, N, N > &cov_prev, T time_up, std::array< T, N > *state_up, Matrix< T, N, N > *cov_up)
Function to run a single extended kalman filter time update step.
Definition EkfTimeUpdate.hpp:61
This class is a base implementation of the integrator. It defines the basic functions and components ...
Definition Integrator.hpp:37
Matrix math implementation.
Definition Matrix.hpp:54
#define NO_ERROR
Definition clockwerkerrors.h:31
#define ERROR_NULLPTR
Definition clockwerkerrors.h:57