WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
EkfTimeUpdate.hpp
Go to the documentation of this file.
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"
22#include "core/matrixmath.hpp"
23#include "core/vectormath.hpp"
26
27namespace warpos {
28
32 template <uint32 N>
34 public:
35 EkfTimeUpdate(Integrator<N + N*N>& integ) : _integrator(integ) {}
36
45 int runUpdate(floating_point time_prev, const std::array<floating_point, N> &state_prev, const clockwerk::Matrix<N, N> &cov_prev,
46 floating_point time_up, std::array<floating_point, N> *state_up, clockwerk::Matrix<N, N> *cov_up);
47
49 private:
50 std::array<floating_point, N + N*N> _full_state_initial;
51 std::array<floating_point, N + N*N> _full_state_post;
52
53 // STM
55 clockwerk::Matrix<N, N> _phi_transpose;
56
57 // Temporary calculation variables
60
65 Integrator<N + N*N>& _integrator;
66 };
67
68 template<uint32 N>
69 int EkfTimeUpdate<N>::runUpdate(floating_point time_prev, const std::array<floating_point, N> &state_prev, const clockwerk::Matrix<N, N> &cov_prev,
70 floating_point time_up, std::array<floating_point, N> *state_up, clockwerk::Matrix<N, N> *cov_up) {
71 // Now generate a full state vector including our phi matrix
72 unsigned int one_idx = N;
73 for(unsigned int i = 0; i < N + N*N; i++) {
74 if(i < N) {
75 _full_state_initial[i] = state_prev[i];
76 } else if(i == one_idx) {
77 _full_state_initial[i] = 1.0;
78 one_idx = one_idx + N + 1;
79 } else {
80 _full_state_initial[i] = 0.0;
81 }
82 }
83
84 // Now propagate
85 int16 err = _integrator.step(time_prev, time_up, _full_state_initial, _full_state_post);
86 if(err > 0) {
87 return err;
88 }
89
90 // Now extract our Phi matrix, then use it to propagate forward covariance
91 _phi.setFromArray(&_full_state_post[N]);
92 _phi.transpose(_phi_transpose);
93
94 // Finally, set our output state and updated covariance matrix
95 for(unsigned int i = 0; i < N; i++) {
96 (*state_up)[i] = _full_state_post[i];
97 }
98 multiply(_phi, cov_prev, _tmp_1);
99 multiply(_tmp_1, _phi_transpose, _tmp_2);
100 multiply(time_up - time_prev, Q, _tmp_1);
101 eAdd(_tmp_2, _tmp_1, *cov_up);
102
103 return NO_ERROR;
104 }
105
106}
107
108#endif
Matrix math implementation.
Definition Matrix.hpp:55
int runUpdate(floating_point time_prev, const std::array< floating_point, N > &state_prev, const clockwerk::Matrix< N, N > &cov_prev, floating_point time_up, std::array< floating_point, N > *state_up, clockwerk::Matrix< N, N > *cov_up)
Function to run a single extended kalman filter time update step.
Definition EkfTimeUpdate.hpp:69
clockwerk::Matrix< N, N > Q
Process noise matrix.
Definition EkfTimeUpdate.hpp:48
EkfTimeUpdate(Integrator< N+N *N > &integ)
Definition EkfTimeUpdate.hpp:35
Definition Integrator.hpp:37
virtual int16 step(floating_point start_time, floating_point end_time, const std::array< floating_point, N > &start_state, std::array< floating_point, N > &out_state)
Definition Integrator.hpp:49
#define NO_ERROR
Error code in the case where matrix math executed successfully.
Definition clockwerkerrors.h:34
Definition DeadReckon.cpp:20