0.3.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
30
31#include "util/Eigen.hpp"
32
33namespace NAV::SPP
34{
35
37class KalmanFilter // NOLINT(clang-analyzer-optin.performance.Padding)
38{
39 public:
42 void reset(const std::vector<SatelliteSystem>& satelliteSystems);
43
48
51
53 [[nodiscard]] bool isInitialized() const { return _initialized; }
54
59 void predict(const double& dt, const Eigen::Vector3d& lla_pos, const std::string& nameId);
60
67 void update(const std::vector<Meas::MeasKeyTypes>& measKeys,
71 const std::string& nameId);
72
76
85 bool ShowGuiWidgets(const char* id, bool useDoppler, bool multiConstellation, bool estimateInterFrequencyBiases, float itemWidth, float unitWidth);
86
89 void setClockBiasErrorCovariance(double clkPhaseDrift);
90
92 [[nodiscard]] const std::vector<SPP::States::StateKeyType>& getStateKeys() const;
93
95 [[nodiscard]] const KeyedVectorXd<States::StateKeyType>& getState() const;
96
99
100 private:
101 // /// @brief All position keys
102 // const std::vector<SPP::States::StateKeyType>& PosKey = Keys::Pos<SPP::States::StateKeyType>;
103
105 const std::array<SPP::States::StateKeyType, 3>& VelKey = Keys::Vel<SPP::States::StateKeyType>;
107 const std::array<SPP::States::StateKeyType, 6>& PosVelKey = Keys::PosVel<SPP::States::StateKeyType>;
108
111
113 bool _initialized = false;
114
119
120 // ###########################################################################################################
121
123 enum class InitCovarianceVelocityUnits : uint8_t
124 {
127 };
128
130
132 double _gui_initCovarianceVelocity = 10 /* [ m / s ] */;
135
136 // ###########################################################################################################
137
139 enum class InitCovarianceClockDriftUnits : uint8_t
140 {
145 };
146
148
150 double _gui_initCovarianceClockDrift = 1e-6 /* [ s / s ] */;
152 double _initCovarianceClockDrift = std::pow(1e-6 * InsConst::C, 2);
153
154 // ###########################################################################################################
155
158
160 double _gui_initCovarianceInterSysClockDrift = 1e-6 /* [ s / s ] */;
162 double _initCovarianceInterSysClockDrift = std::pow(1e-6 * InsConst::C, 2);
163
164 // ###########################################################################################################
165 // ###########################################################################################################
166
167 friend void to_json(json& j, const KalmanFilter& data);
168 friend void from_json(const json& j, KalmanFilter& data);
169};
170
174void to_json(json& j, const KalmanFilter& data);
178void from_json(const json& j, KalmanFilter& data);
179
180} // namespace NAV::SPP
void to_json(json &j, const Algorithm &obj)
Converts the provided object into json.
void from_json(const json &j, Algorithm &obj)
Converts the provided json object into a node object.
Holds all Constants.
Vector space operations.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
Keys for the SPP algorithm for use inside the KeyedMatrices.
The class is responsible for all time-related tasks.
Inter Frequency Bias System Model.
Kalman Filter with keyed states.
KeyedKalmanFilter< double, StateKeyType, MeasKeyType > KeyedKalmanFilterD
Keyed Kalman Filter class with double as type.
Definition KeyedKalmanFilter.hpp:584
Motion System Model.
constexpr std::array< StateKeyType, 6 > PosVel
Vector with all position and velocity keys.
Definition MotionModel.hpp:66
constexpr std::array< StateKeyType, 3 > Vel
All velocity keys.
Definition MotionModel.hpp:59
Receiver Clock System Model.
Structs identifying a unique satellite.
GNSS Satellite System.
System Model.
SystemModelCalcAlgorithm
Algorithms to calculate the system model with.
Definition SystemModel.hpp:23
@ Taylor1
Taylor.
Definition SystemModel.hpp:25
Frequency definition for different satellite systems.
Definition Frequency.hpp:59
static constexpr double C
Speed of light [m/s].
Definition Constants.hpp:34
Inter Frequency Bias System Model.
Definition InterFrequencyBiasModel.hpp:48
Motion System Model.
Definition MotionModel.hpp:79
Receiver Clock System Model.
Definition ReceiverClockModel.hpp:59
The Spp Kalman Filter related options.
Definition KalmanFilter.hpp:38
MotionModel< SPP::States::StateKeyType > _motionModel
Motion Model.
Definition KalmanFilter.hpp:116
InitCovarianceClockDriftUnits _gui_initCovarianceClockDriftUnit
Gui selection for the Unit of the P matrix initialization clock drift uncertainty.
Definition KalmanFilter.hpp:147
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 std::vector< SPP::States::StateKeyType > & getStateKeys() const
Get the States in the Kalman Filter.
const std::array< SPP::States::StateKeyType, 6 > & PosVelKey
All position and velocity keys.
Definition KalmanFilter.hpp:107
void reset(const std::vector< SatelliteSystem > &satelliteSystems)
Resets the filter.
void predict(const double &dt, const Eigen::Vector3d &lla_pos, const std::string &nameId)
Does the Kalman Filter prediction.
void update(const std::vector< Meas::MeasKeyTypes > &measKeys, const KeyedMatrixXd< Meas::MeasKeyTypes, States::StateKeyType > &H, const KeyedMatrixXd< Meas::MeasKeyTypes, Meas::MeasKeyTypes > &R, const KeyedVectorXd< Meas::MeasKeyTypes > &dz, const std::string &nameId)
Does the Kalman Filter update.
InitCovarianceVelocityUnits
Possible Units for the P matrix initialization velocity uncertainty.
Definition KalmanFilter.hpp:124
@ m_s
[ m / s ]
Definition KalmanFilter.hpp:125
@ m2_s2
[ m^2 / s^2 ]
Definition KalmanFilter.hpp:126
ReceiverClockModel< SPP::States::StateKeyType > _receiverClockModel
Receiver clock Model.
Definition KalmanFilter.hpp:117
double _initCovarianceClockDrift
Covariance of the P matrix initialization clock drift uncertainty [m²/s²].
Definition KalmanFilter.hpp:152
void initialize(const KeyedVectorXd< States::StateKeyType > &states, const KeyedMatrixXd< States::StateKeyType, States::StateKeyType > &variance)
Initialize the filter.
double _initCovarianceInterSysClockDrift
Covariance of the P matrix initialization inter system clock drift uncertainty [m²/s²].
Definition KalmanFilter.hpp:162
void addInterFrequencyBias(const Frequency &freq)
Adds the frequency as inter-frequency bias state.
InitCovarianceClockDriftUnits _gui_initCovarianceInterSysClockDriftUnit
Gui selection for the Unit of the P matrix initialization inter system clock drift uncertainty.
Definition KalmanFilter.hpp:157
SystemModelCalcAlgorithm _systemModelCalcAlgorithm
Algorithm to calculate the system models with.
Definition KalmanFilter.hpp:115
friend void to_json(json &j, const KalmanFilter &data)
Converts the provided data into a json object.
InterFrequencyBiasModel< SPP::States::StateKeyType > _interFrequencyBiasModel
Inter-frequency bias Model.
Definition KalmanFilter.hpp:118
const KeyedVectorXd< States::StateKeyType > & getState() const
Returns the State vector x̂
InitCovarianceVelocityUnits _gui_initCovarianceVelocityUnit
Gui selection for the Unit of the P matrix initialization velocity uncertainty.
Definition KalmanFilter.hpp:129
double _gui_initCovarianceVelocity
GUI selection for the P matrix initialization velocity uncertainty.
Definition KalmanFilter.hpp:132
KeyedKalmanFilterD< SPP::States::StateKeyType, SPP::Meas::MeasKeyTypes > _kalmanFilter
Kalman Filter representation.
Definition KalmanFilter.hpp:110
friend void from_json(const json &j, KalmanFilter &data)
Converts the provided json object into the data object.
double _gui_initCovarianceClockDrift
GUI selection for the P matrix initialization clock drift uncertainty.
Definition KalmanFilter.hpp:150
const std::array< SPP::States::StateKeyType, 3 > & VelKey
All velocity keys.
Definition KalmanFilter.hpp:105
double _initCovarianceVelocity
Covariance of the P matrix initialization velocity uncertainty [m²/s²].
Definition KalmanFilter.hpp:134
bool _initialized
Boolean that determines, if Kalman Filter is initialized (from weighted LSE solution)
Definition KalmanFilter.hpp:113
double _gui_initCovarianceInterSysClockDrift
GUI selection for the P matrix initialization inter system clock drift uncertainty.
Definition KalmanFilter.hpp:160
bool ShowGuiWidgets(const char *id, bool useDoppler, bool multiConstellation, bool estimateInterFrequencyBiases, float itemWidth, float unitWidth)
Shows the GUI input to select the options.
InitCovarianceClockDriftUnits
Possible Units for the P matrix initialization clock drift uncertainty.
Definition KalmanFilter.hpp:140
@ s2_s2
[ s^2 / s^2 ]
Definition KalmanFilter.hpp:144
@ s_s
[ s / s ]
Definition KalmanFilter.hpp:142
bool isInitialized() const
Checks wether the Kalman filter is initialized.
Definition KalmanFilter.hpp:53
const KeyedMatrixXd< States::StateKeyType, States::StateKeyType > & getErrorCovarianceMatrix() const
Returns the Error covariance matrix 𝐏
KeyedVectorX< double, RowKeyType > KeyedVectorXd
Dynamic size KeyedVector with double types.
Definition KeyedMatrix.hpp:2348
KeyedMatrixX< double, RowKeyType, ColKeyType > KeyedMatrixXd
Dynamic size KeyedMatrix with double types.
Definition KeyedMatrix.hpp:2313