0.2.0
Loading...
Searching...
No Matches
TightlyCoupledKF.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
13
14#pragma once
15
29
31#include "Navigation/Transformations/Units.hpp"
32
33namespace NAV
34{
36class TightlyCoupledKF : public Node
37{
38 public:
52 [[nodiscard]] static std::string typeStatic();
54 [[nodiscard]] std::string type() const override;
56 [[nodiscard]] static std::string category();
57
60 void guiConfig() override;
61
63 [[nodiscard]] json save() const override;
64
67 void restore(const json& j) override;
68
69 private:
70 constexpr static size_t INPUT_PORT_INDEX_IMU = 0;
71 constexpr static size_t INPUT_PORT_INDEX_GNSS_OBS = 1;
72 constexpr static size_t INPUT_PORT_INDEX_POS_VEL_ATT_INIT = 2;
73 constexpr static size_t INPUT_PORT_INDEX_GNSS_NAV_INFO = 2;
74 constexpr static size_t OUTPUT_PORT_INDEX_SOLUTION = 0;
75 constexpr static size_t OUTPUT_PORT_INDEX_x = 1;
76 constexpr static size_t OUTPUT_PORT_INDEX_P = 2;
77 constexpr static size_t OUTPUT_PORT_INDEX_Phi = 3;
78 constexpr static size_t OUTPUT_PORT_INDEX_Q = 4;
79 constexpr static size_t OUTPUT_PORT_INDEX_z = 5;
80 constexpr static size_t OUTPUT_PORT_INDEX_H = 6;
81 constexpr static size_t OUTPUT_PORT_INDEX_R = 7;
82 constexpr static size_t OUTPUT_PORT_INDEX_K = 8;
83
85 bool initialize() override;
86
88 void deinitialize() override;
89
92 void invokeCallbackWithPosVelAtt(const PosVelAtt& posVelAtt);
93
97 void recvImuObservation(InputPin::NodeDataQueue& queue, size_t pinIdx);
98
102 void recvGnssObs(InputPin::NodeDataQueue& queue, size_t pinIdx);
103
107 void recvPosVelAttInit(InputPin::NodeDataQueue& queue, size_t pinIdx);
108
113 void tightlyCoupledPrediction(const std::shared_ptr<const PosVelAtt>& inertialNavSol, double tau_i, const ImuPos& imuPos);
114
117 void tightlyCoupledUpdate(const std::shared_ptr<const GnssObs>& gnssObservation);
118
120 void addKalmanMatricesPins();
121
123 void removeKalmanMatricesPins();
124
126 void updateExternalPvaInitPin();
127
129 int _dragAndDropPinIndex = -1;
131 size_t _nNavInfoPins = 1;
133 void updateNumberOfInputPins();
134
136 InertialIntegrator _inertialIntegrator;
138 bool _preferAccelerationOverDeltaMeasurements = false;
139
141 std::shared_ptr<const ImuObs> _lastImuObs = nullptr;
142
144 std::array<double, 3> _initalRollPitchYaw{};
146 bool _initializeStateOverExternalPin{};
148 InsTime _externalInitTime;
149
151 ReceiverClock _recvClk;
152
154 Frequency _filterFreq = G01;
156 Code _filterCode = Code_Default;
158 std::vector<SatId> _excludedSatellites;
160 double _elevationMask = static_cast<double>(15.0_deg);
161
163 IonosphereModel _ionosphereModel = IonosphereModel::Klobuchar;
164
166 TroposphereModelSelection _troposphereModels;
167
169 std::vector<SPP::States::StateKeyTypes> _interSysErrs{};
172 std::vector<SPP::States::StateKeyTypes> _interSysDrifts{};
173
175 InsTime _lastEpochTime; // TODO: Remove?
176
178 KalmanFilter _kalmanFilter{ 17, 8 };
179
180 // ###########################################################################################################
181 // GUI Settings
182 // ###########################################################################################################
183
185 bool _showKalmanFilterOutputPins = false;
186
188 bool _checkKalmanMatricesRanks = true;
189
190 // ###########################################################################################################
191 // Parameters
192 // ###########################################################################################################
193
195 Eigen::Vector3d _b_leverArm_InsGnss{ 0.0, 0.0, 0.0 };
196
197 // ###########################################################################################################
198
200 enum class StdevAccelNoiseUnits
201 {
202 mg_sqrtHz,
203 m_s2_sqrtHz,
204 };
206 StdevAccelNoiseUnits _stdevAccelNoiseUnits = StdevAccelNoiseUnits::mg_sqrtHz;
207
210 Eigen::Vector3d _stdev_ra = 0.04 /* [mg/√(Hz)] */ * Eigen::Vector3d::Ones();
211
212 // ###########################################################################################################
213
215 enum class StdevGyroNoiseUnits
216 {
217 deg_hr_sqrtHz,
218 rad_s_sqrtHz,
219 };
221 StdevGyroNoiseUnits _stdevGyroNoiseUnits = StdevGyroNoiseUnits::deg_hr_sqrtHz;
222
225 Eigen::Vector3d _stdev_rg = 5 /* [deg/hr/√(Hz)]^2 */ * Eigen::Vector3d::Ones();
226
227 // ###########################################################################################################
228
230 enum class StdevAccelBiasUnits
231 {
232 microg,
233 m_s2,
234 };
236 StdevAccelBiasUnits _stdevAccelBiasUnits = StdevAccelBiasUnits::microg;
237
240 Eigen::Vector3d _stdev_bad = 10 /* [µg] */ * Eigen::Vector3d::Ones();
241
243 Eigen::Vector3d _tau_bad = 0.1 * Eigen::Vector3d::Ones();
244
245 // ###########################################################################################################
246
248 enum class StdevGyroBiasUnits
249 {
250 deg_h,
251 rad_s,
252 };
254 StdevGyroBiasUnits _stdevGyroBiasUnits = StdevGyroBiasUnits::deg_h;
255
258 Eigen::Vector3d _stdev_bgd = 1 /* [°/h] */ * Eigen::Vector3d::Ones();
259
261 Eigen::Vector3d _tau_bgd = 0.1 * Eigen::Vector3d::Ones();
262
263 // ###########################################################################################################
264
266 enum class StdevClockPhaseUnits
267 {
268 m_sqrtHz,
269 };
271 StdevClockPhaseUnits _stdevClockPhaseUnits = StdevClockPhaseUnits::m_sqrtHz;
272
275 double _stdev_cp = 0 /* [m / √(Hz)] */;
276
277 // ###########################################################################################################
278
280 enum class StdevClockFreqUnits
281 {
282 m_s_sqrtHz,
283 };
285 StdevClockFreqUnits _stdevClockFreqUnits = StdevClockFreqUnits::m_s_sqrtHz;
286
289 double _stdev_cf = 5 /* [m / s / √(Hz)] */;
290
291 // ###########################################################################################################
292
293 // TODO: Replace with GNSS Measurement Error Model (see SPP node)
294 // /// Possible Units for the Standard deviation of the pseudorange measurement
295 // enum class GnssMeasurementUncertaintyPseudorangeUnit
296 // {
297 // meter2, ///< Variance [m²]
298 // meter, ///< Standard deviation [m]
299 // };
300 // /// Gui selection for the Unit of the input gnssMeasurementUncertaintyPseudorangeUnit parameter
301 // GnssMeasurementUncertaintyPseudorangeUnit _gnssMeasurementUncertaintyPseudorangeUnit = GnssMeasurementUncertaintyPseudorangeUnit::meter;
302
303 // /// @brief GUI selection of the GNSS pseudorange measurement uncertainty (standard deviation σ or Variance σ²).
304 // double _gnssMeasurementUncertaintyPseudorange = 5 /* [m] */;
305
306 // // ###########################################################################################################
307
308 // /// Possible Units for the Standard deviation of the pseudorange-rate measurement
309 // enum class GnssMeasurementUncertaintyPseudorangeRateUnit
310 // {
311 // m2_s2, ///< Variance [m²/s²]
312 // m_s, ///< Standard deviation [m/s]
313 // };
314 // /// Gui selection for the Unit of the input gnssMeasurementUncertaintyPseudorangeRateUnit parameter
315 // GnssMeasurementUncertaintyPseudorangeRateUnit _gnssMeasurementUncertaintyPseudorangeRateUnit = GnssMeasurementUncertaintyPseudorangeRateUnit::m_s;
316
317 // /// @brief GUI selection of the GNSS pseudorange-rate measurement uncertainty (standard deviation σ or Variance σ²).
318 // double _gnssMeasurementUncertaintyPseudorangeRate = 5 /* [m/s] */;
319
320 // ###########################################################################################################
321
323 enum class RandomProcess
324 {
325 // WhiteNoise, ///< White noise
326 // RandomConstant, ///< Random constant
327
328 RandomWalk,
329 GaussMarkov1,
330
331 // GaussMarkov2, ///< Gauss-Markov 2nd Order
332 // GaussMarkov3, ///< Gauss-Markov 3rd Order
333 };
334
336 RandomProcess _randomProcessAccel = RandomProcess::RandomWalk;
338 RandomProcess _randomProcessGyro = RandomProcess::RandomWalk;
339
340 // ###########################################################################################################
341
343 enum class InitCovarianceClockPhaseUnit
344 {
345 m2,
346 s2,
347 m,
348 s
349 };
351 InitCovarianceClockPhaseUnit _initCovariancePhaseUnit = InitCovarianceClockPhaseUnit::m;
352
354 double _initCovariancePhase{ 5 };
355
356 // ###########################################################################################################
357
359 enum class InitCovarianceClockFreqUnit
360 {
361 m2_s2,
362 m_s,
363 };
365 InitCovarianceClockFreqUnit _initCovarianceFreqUnit = InitCovarianceClockFreqUnit::m_s;
366
368 double _initCovarianceFreq{ 5 };
369
370 // ###########################################################################################################
371
373 enum class InitCovariancePositionUnit
374 {
375 rad2_rad2_m2,
376 rad_rad_m,
377 meter2,
378 meter,
379 };
381 InitCovariancePositionUnit _initCovariancePositionUnit = InitCovariancePositionUnit::meter;
382
384 Eigen::Vector3d _initCovariancePosition{ 100, 100, 100 };
385
386 // ###########################################################################################################
387
389 enum class InitCovarianceVelocityUnit
390 {
391 m2_s2,
392 m_s,
393 };
395 InitCovarianceVelocityUnit _initCovarianceVelocityUnit = InitCovarianceVelocityUnit::m_s;
396
398 Eigen::Vector3d _initCovarianceVelocity{ 10, 10, 10 };
399
400 // ###########################################################################################################
401
403 enum class InitCovarianceAttitudeAnglesUnit
404 {
405 rad2,
406 deg2,
407 rad,
408 deg,
409 };
411 InitCovarianceAttitudeAnglesUnit _initCovarianceAttitudeAnglesUnit = InitCovarianceAttitudeAnglesUnit::deg;
412
414 Eigen::Vector3d _initCovarianceAttitudeAngles{ 10, 10, 10 };
415
416 // ###########################################################################################################
417
419 enum class InitCovarianceBiasAccelUnit
420 {
421 m2_s4,
422 m_s2,
423 };
425 InitCovarianceBiasAccelUnit _initCovarianceBiasAccelUnit = InitCovarianceBiasAccelUnit::m_s2;
426
428 Eigen::Vector3d _initCovarianceBiasAccel{ 1, 1, 1 };
429
430 // ###########################################################################################################
431
433 enum class InitCovarianceBiasGyroUnit
434 {
435 rad2_s2,
436 deg2_s2,
437 rad_s,
438 deg_s,
439 };
441 InitCovarianceBiasGyroUnit _initCovarianceBiasGyroUnit = InitCovarianceBiasGyroUnit::deg_s;
442
444 Eigen::Vector3d _initCovarianceBiasGyro{ 0.5, 0.5, 0.5 };
445
446 // ###########################################################################################################
447
449 enum class PhiCalculationAlgorithm
450 {
451 Exponential,
452 Taylor,
453 };
455 PhiCalculationAlgorithm _phiCalculationAlgorithm = PhiCalculationAlgorithm::Taylor;
456
458 int _phiCalculationTaylorOrder = 2;
459
461 enum class QCalculationAlgorithm
462 {
463 VanLoan,
464 Taylor1,
465 };
467 QCalculationAlgorithm _qCalculationAlgorithm = QCalculationAlgorithm::Taylor1;
468
469 // ###########################################################################################################
470
472 enum class InitBiasAccelUnit
473 {
474 m_s2,
475 };
477 InitBiasAccelUnit _initBiasAccelUnit = InitBiasAccelUnit::m_s2;
478
480 Eigen::Vector3d _initBiasAccel{ 0.0, 0.0, 0.0 };
481
482 // ###########################################################################################################
483
485 enum class InitBiasGyroUnit
486 {
487 rad_s,
488 deg_s,
489 };
491 InitBiasGyroUnit _initBiasGyroUnit = InitBiasGyroUnit::deg_s;
492
494 Eigen::Vector3d _initBiasGyro{ 0.0, 0.0, 0.0 };
495
496 // ###########################################################################################################
497 // Prediction
498 // ###########################################################################################################
499
500 // ------------------------------------------- System matrix 𝐅 ----------------------------------------------
501
515 [[nodiscard]] Eigen::Matrix<double, 17, 17> n_systemMatrix_F(const Eigen::Quaterniond& n_Quat_b,
516 const Eigen::Vector3d& b_specForce_ib,
517 const Eigen::Vector3d& n_omega_in,
518 const Eigen::Vector3d& n_velocity,
519 const Eigen::Vector3d& lla_position,
520 double R_N,
521 double R_E,
522 double g_0,
523 double r_eS_e,
524 const Eigen::Vector3d& tau_bad,
525 const Eigen::Vector3d& tau_bgd) const;
526
537 [[nodiscard]] Eigen::Matrix<double, 17, 17> e_systemMatrix_F(const Eigen::Quaterniond& e_Quat_b,
538 const Eigen::Vector3d& b_specForce_ib,
539 const Eigen::Vector3d& e_position,
540 const Eigen::Vector3d& e_gravitation,
541 double r_eS_e,
542 const Eigen::Vector3d& e_omega_ie,
543 const Eigen::Vector3d& tau_bad,
544 const Eigen::Vector3d& tau_bgd) const;
545
546 // ----------------------------- Noise input matrix 𝐆 & Noise scale matrix 𝐖 -------------------------------
547 // ----------------------------------- System noise covariance matrix 𝐐 -------------------------------------
548
552 [[nodiscard]] static Eigen::Matrix<double, 17, 14> noiseInputMatrix_G(const Eigen::Quaterniond& ien_Quat_b);
553
564 [[nodiscard]] Eigen::Matrix<double, 14, 14> noiseScaleMatrix_W(const Eigen::Vector3d& sigma2_ra, const Eigen::Vector3d& sigma2_rg,
565 const Eigen::Vector3d& sigma2_bad, const Eigen::Vector3d& sigma2_bgd,
566 const Eigen::Vector3d& tau_bad, const Eigen::Vector3d& tau_bgd,
567 const double& sigma2_cPhi, const double& sigma2_cf);
568
583 [[nodiscard]] static Eigen::Matrix<double, 17, 17> n_systemNoiseCovarianceMatrix_Q(const Eigen::Vector3d& sigma2_ra, const Eigen::Vector3d& sigma2_rg,
584 const Eigen::Vector3d& sigma2_bad, const Eigen::Vector3d& sigma2_bgd,
585 const Eigen::Vector3d& tau_bad, const Eigen::Vector3d& tau_bgd,
586 const double& sigma2_cPhi, const double& sigma2_cf,
587 const Eigen::Matrix3d& n_F_21, const Eigen::Matrix3d& T_rn_p,
588 const Eigen::Matrix3d& n_Dcm_b, const double& tau_s);
589
603 [[nodiscard]] static Eigen::Matrix<double, 17, 17> e_systemNoiseCovarianceMatrix_Q(const Eigen::Vector3d& sigma2_ra, const Eigen::Vector3d& sigma2_rg,
604 const Eigen::Vector3d& sigma2_bad, const Eigen::Vector3d& sigma2_bgd,
605 const Eigen::Vector3d& tau_bad, const Eigen::Vector3d& tau_bgd,
606 const double& sigma2_cPhi, const double& sigma2_cf,
607 const Eigen::Matrix3d& e_F_21,
608 const Eigen::Matrix3d& e_Dcm_b, const double& tau_s);
609
610 // --------------------------------------- Error covariance matrix P -----------------------------------------
611
621 [[nodiscard]] Eigen::Matrix<double, 17, 17> initialErrorCovarianceMatrix_P0(const Eigen::Vector3d& variance_angles,
622 const Eigen::Vector3d& variance_vel,
623 const Eigen::Vector3d& variance_pos,
624 const Eigen::Vector3d& variance_accelBias,
625 const Eigen::Vector3d& variance_gyroBias,
626 const double& variance_clkPhase,
627 const double& variance_clkFreq) const;
628
629 // ###########################################################################################################
630 // Update
631 // ###########################################################################################################
632
640 [[nodiscard]] static Eigen::MatrixXd n_measurementMatrix_H(const double& R_N,
641 const double& R_E,
642 const Eigen::Vector3d& lla_position,
643 const std::vector<Eigen::Vector3d>& n_lineOfSightUnitVectors,
644 std::vector<double>& pseudoRangeRateObservations);
645
651 [[nodiscard]] static Eigen::MatrixXd measurementNoiseCovariance_R(const double& sigma_rhoZ,
652 const double& sigma_rZ,
653 const std::vector<double>& satElevation);
654
663 [[nodiscard]] static double sigma2(const double& satElevation,
664 const double& sigma_Z,
665 const double& sigma_C,
666 const double& sigma_A,
667 const double& CN0,
668 const double& rangeAccel);
669
676 [[nodiscard]] static Eigen::MatrixXd measurementInnovation_dz(const std::vector<double>& pseudoRangeObservations,
677 const std::vector<double>& pseudoRangeEstimates,
678 const std::vector<double>& pseudoRangeRateObservations,
679 const std::vector<double>& pseudoRangeRateEstimates);
680};
681
682} // namespace NAV
Single Point Positioning Algorithm.
Code definitions.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
Frequency definition for different satellite systems.
GNSS Observation messages.
Parent Class for all IMU Observations.
Inertial Measurement Integrator.
Tightly-coupled Kalman Filter INS/GNSS errors.
The class is responsible for all time-related tasks.
Ionosphere Models.
Generalized Kalman Filter class.
Node Class.
Position, Velocity and Attitude Storage Class.
Receiver Clock information.
Troposphere Models.
IMU Position.
Definition ImuPos.hpp:26
Inertial Measurement Integrator.
Definition InertialIntegrator.hpp:37
Abstract parent class for all nodes.
Definition Node.hpp:86
Position, Velocity and Attitude Storage Class.
Definition PosVelAtt.hpp:25
Tightly-coupled Kalman Filter for INS/GNSS integration.
Definition TightlyCoupledKF.hpp:37
void restore(const json &j) override
Restores the node from a json object.
static std::string typeStatic()
String representation of the class type.
json save() const override
Saves the node into a json object.
std::string type() const override
String representation of the class type.
TightlyCoupledKF()
Default constructor.
TightlyCoupledKF(const TightlyCoupledKF &)=delete
Copy constructor.
TightlyCoupledKF & operator=(TightlyCoupledKF &&)=delete
Move assignment operator.
static std::string category()
String representation of the class category.
TightlyCoupledKF & operator=(const TightlyCoupledKF &)=delete
Copy assignment operator.
void guiConfig() override
ImGui config window which is shown on double click.
TightlyCoupledKF(TightlyCoupledKF &&)=delete
Move constructor.
~TightlyCoupledKF() override
Destructor.