0.2.0
Loading...
Searching...
No Matches
KalmanFilter.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
14
15#pragma once
16
17#include <array>
18#include <set>
19
25
26#include "util/Eigen.hpp"
27
28namespace NAV::SPP
29{
30
32class KalmanFilter // NOLINT(clang-analyzer-optin.performance.Padding)
33{
34 public:
36 void reset();
37
42
45
47 [[nodiscard]] bool isInitialized() const { return _initialized; }
48
53 void predict(const double& dt, const Eigen::Vector3d& lla_pos, const std::string& nameId);
54
61 void update(const std::vector<Meas::MeasKeyTypes>& measKeys,
65 const std::string& nameId);
66
73 SatelliteSystem updateInterSystemTimeDifferences(const std::set<SatelliteSystem>& usedSatSystems,
74 SatelliteSystem oldRefSys,
75 SatelliteSystem newRefSys,
76 const std::string& nameId);
77
81
88 calcProcessNoiseMatrixGroves(double dt, const Eigen::Vector3d& lla_pos, const std::string& nameId) const;
89
98 bool ShowGuiWidgets(const char* id, bool useDoppler, bool multiConstellation, bool estimateInterFrequencyBiases, float itemWidth, float unitWidth);
99
102 void setClockBiasErrorCovariance(double clkPhaseDrift);
103
105 [[nodiscard]] const std::vector<SPP::States::StateKeyTypes>& getStateKeys() const;
106
108 [[nodiscard]] const KeyedVectorXd<States::StateKeyTypes>& getState() const;
109
112
113 private:
115 KeyedKalmanFilterD<SPP::States::StateKeyTypes, SPP::Meas::MeasKeyTypes> _kalmanFilter{ SPP::States::PosVelRecvClk, {} };
116
118 bool _initialized = false;
119
120 // ###########################################################################################################
121 // GUI settings
122 // ###########################################################################################################
123
125 enum class QCalculationAlgorithm
126 {
127 VanLoan,
128 Taylor1,
129 };
131 QCalculationAlgorithm _qCalculationAlgorithm = QCalculationAlgorithm::VanLoan;
132
133 // ###########################################################################################################
134
136 enum class CovarianceAccelUnits
137 {
138 m_sqrts3,
139 m2_s3,
140 };
142 CovarianceAccelUnits _gui_covarianceAccelUnit = CovarianceAccelUnits::m_sqrts3;
143
146 std::array<double, 2> _gui_covarianceAccel = { 3.0, 1.5 } /* [ m / √(s^3) ] */;
148 std::array<double, 2> _covarianceAccel = { 3.0, 1.5 };
149
150 // ###########################################################################################################
151
153 enum class CovarianceClkPhaseDriftUnits
154 {
155 m_sqrts,
156 m2_s,
157 };
159 CovarianceClkPhaseDriftUnits _gui_covarianceClkPhaseDriftUnit = CovarianceClkPhaseDriftUnits::m2_s;
160
162 double _gui_covarianceClkPhaseDrift = 0.01 /*[ m^2 / s ] */;
164 double _covarianceClkPhaseDrift = 0.01;
165
166 // ###########################################################################################################
167
169 enum class CovarianceClkFrequencyDriftUnits
170 {
171 m_sqrts3,
172 m2_s3,
173 };
175 CovarianceClkFrequencyDriftUnits _gui_covarianceClkFrequencyDriftUnit = CovarianceClkFrequencyDriftUnits::m2_s3;
176
178 double _gui_covarianceClkFrequencyDrift = 0.04 /* [ m^2 / s^3 ] */;
180 double _covarianceClkFrequencyDrift = 0.04;
181
182 // ###########################################################################################################
183
185 CovarianceClkPhaseDriftUnits _gui_covarianceInterSysClkPhaseDriftUnit = CovarianceClkPhaseDriftUnits::m2_s;
186
188 double _gui_covarianceInterSysClkPhaseDrift = 0.01 /* [m²/s] */;
190 double _covarianceInterSysClkPhaseDrift = 0.01;
191
192 // ###########################################################################################################
193
195 CovarianceClkFrequencyDriftUnits _gui_covarianceInterSysClkFrequencyDriftUnit = CovarianceClkFrequencyDriftUnits::m2_s3;
196
198 double _gui_covarianceInterSysClkFrequencyDrift = 0.04 /* [m²/s³] */;
200 double _covarianceInterSysClkFrequencyDrift = 0.04;
201
202 // ###########################################################################################################
203
205 CovarianceClkPhaseDriftUnits _gui_covarianceInterFrequencyBiasUnit = CovarianceClkPhaseDriftUnits::m2_s;
206
208 double _gui_covarianceInterFrequencyBias = 1e-6 /* [m²/s] */;
210 double _covarianceInterFrequencyBias = 1e-6;
211
212 // ###########################################################################################################
213 // ###########################################################################################################
214
216 enum class InitCovarianceVelocityUnits
217 {
218 m_s,
219 m2_s2,
220 };
222 InitCovarianceVelocityUnits _gui_initCovarianceVelocityUnit = InitCovarianceVelocityUnits::m_s;
223
225 double _gui_initCovarianceVelocity = 10 /* [ m / s ] */;
227 double _initCovarianceVelocity = 100;
228
229 // ###########################################################################################################
230
232 enum class InitCovarianceClockDriftUnits
233 {
234 m_s,
235 s_s,
236 m2_s2,
237 s2_s2,
238 };
240 InitCovarianceClockDriftUnits _gui_initCovarianceClockDriftUnit = InitCovarianceClockDriftUnits::s_s;
241
243 double _gui_initCovarianceClockDrift = 1e-6 /* [ s / s ] */;
245 double _initCovarianceClockDrift = std::pow(1e-6 * InsConst<>::C, 2);
246
247 // ###########################################################################################################
248
250 InitCovarianceClockDriftUnits _gui_initCovarianceInterSysClockDriftUnit = InitCovarianceClockDriftUnits::s_s;
251
253 double _gui_initCovarianceInterSysClockDrift = 1e-6 /* [ s / s ] */;
255 double _initCovarianceInterSysClockDrift = std::pow(1e-6 * InsConst<>::C, 2);
256
257 // ###########################################################################################################
258 // ###########################################################################################################
259
260 friend void to_json(json& j, const KalmanFilter& data);
261 friend void from_json(const json& j, KalmanFilter& data);
262};
263
267void to_json(json& j, const KalmanFilter& data);
271void from_json(const json& j, KalmanFilter& data);
272
273} // namespace NAV::SPP
Holds all Constants.
Vector space operations.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
The class is responsible for all time-related tasks.
Kalman Filter with keyed states.
Keys for the SPP algorithm for use inside the KeyedMatrices.
Structs identifying a unique satellite.
Frequency definition for different satellite systems.
Definition Frequency.hpp:59
static constexpr Scalar C
Speed of light [m/s].
Definition Constants.hpp:35
Keyed Kalman Filter class.
Definition KeyedKalmanFilter.hpp:37
Dynamic sized KeyedMatrix.
Definition KeyedMatrix.hpp:2055
Dynamic sized KeyedVector.
Definition KeyedMatrix.hpp:1569
The Spp Kalman Filter related options.
Definition KalmanFilter.hpp:33
const std::vector< SPP::States::StateKeyTypes > & getStateKeys() const
Get the States in the Kalman Filter.
void deinitialize()
Deinitialize the KF (can be used to reinitialize the Filter when results seem strange)
void setClockBiasErrorCovariance(double clkPhaseDrift)
Set the P matrix entry for the covariance of the clock phase drift.
const KeyedMatrixXd< States::StateKeyTypes, States::StateKeyTypes > & getErrorCovarianceMatrix() const
Returns the Error covariance matrix 𝐏
SatelliteSystem updateInterSystemTimeDifferences(const std::set< SatelliteSystem > &usedSatSystems, SatelliteSystem oldRefSys, SatelliteSystem newRefSys, const std::string &nameId)
Adds the inter system time difference bias and drift.
void predict(const double &dt, const Eigen::Vector3d &lla_pos, const std::string &nameId)
Does the Kalman Filter prediction.
const KeyedVectorXd< States::StateKeyTypes > & getState() const
Returns the State vector x̂
void addInterFrequencyBias(const Frequency &freq)
Adds the frequency as inter-frequency bias state.
void update(const std::vector< Meas::MeasKeyTypes > &measKeys, const KeyedMatrixXd< Meas::MeasKeyTypes, States::StateKeyTypes > &H, const KeyedMatrixXd< Meas::MeasKeyTypes, Meas::MeasKeyTypes > &R, const KeyedVectorXd< Meas::MeasKeyTypes > &dz, const std::string &nameId)
Does the Kalman Filter update.
friend void to_json(json &j, const KalmanFilter &data)
Converts the provided data into a json object.
KeyedMatrixXd< States::StateKeyTypes, States::StateKeyTypes > calcProcessNoiseMatrixGroves(double dt, const Eigen::Vector3d &lla_pos, const std::string &nameId) const
Calculates the process noise matrix Q.
friend void from_json(const json &j, KalmanFilter &data)
Converts the provided json object into the data object.
void reset()
Resets the filter.
void initialize(const KeyedVectorXd< States::StateKeyTypes > &states, const KeyedMatrixXd< States::StateKeyTypes, States::StateKeyTypes > &variance)
Initialize the filter.
bool ShowGuiWidgets(const char *id, bool useDoppler, bool multiConstellation, bool estimateInterFrequencyBiases, float itemWidth, float unitWidth)
Shows the GUI input to select the options.
bool isInitialized() const
Checks wether the Kalman filter is initialized.
Definition KalmanFilter.hpp:47
Satellite System type.
Definition SatelliteSystem.hpp:43