0.2.0
Loading...
Searching...
No Matches
ImuFusion.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
18
20
22
24
25#include <deque>
26#include <utility>
27
28namespace NAV
29{
31class ImuFusion : public Imu
32{
33 public:
37 ~ImuFusion() override;
39 ImuFusion(const ImuFusion&) = delete;
41 ImuFusion(ImuFusion&&) = delete;
43 ImuFusion& operator=(const ImuFusion&) = delete;
46
48 [[nodiscard]] static std::string typeStatic();
49
51 [[nodiscard]] std::string type() const override;
52
54 [[nodiscard]] static std::string category();
55
58 void guiConfig() override;
59
61 [[nodiscard]] json save() const override;
62
65 void restore(const json& j) override;
66
67 protected:
70
71 private:
72 constexpr static size_t OUTPUT_PORT_INDEX_COMBINED_SIGNAL = 0;
73 constexpr static size_t OUTPUT_PORT_INDEX_BIASES = 1;
74
76 bool initialize() override;
77
79 void deinitialize() override;
80
82 void updateNumberOfInputPins();
83
85 void initializeMountingAngles();
86
90 void recvSignal(InputPin::NodeDataQueue& queue, size_t pinIdx);
91
100 [[nodiscard]] static Eigen::MatrixXd measurementNoiseMatrix_R_adaptive(double alpha,
101 const Eigen::MatrixXd& R,
102 const Eigen::VectorXd& e,
103 const Eigen::MatrixXd& H,
104 const Eigen::MatrixXd& P);
105
107 InsTime _lastFiltObs{};
108
112 void measurementNoiseMatrix_R(Eigen::MatrixXd& R, size_t pinIndex = 0) const;
113
116 void combineSignals(const std::shared_ptr<const ImuObs>& imuObs);
117
118 // --------------------------------------- Kalman filter config ------------------------------------------
120 size_t _nInputPins = 2;
121
123 const uint8_t _numStatesEstIRWKF = 12;
124
126 const uint8_t _numStatesEstBsplineKF = 18;
127
129 const uint8_t _numBsplines = 9;
130
132 const uint8_t _numStatesPerPin = 6;
133
135 const uint8_t _numMeasurements = 6;
136
138 uint8_t _numStatesEst{};
139
141 uint8_t _numStates = 12;
142
144 KalmanFilter _kalmanFilter{ _numStates, _numMeasurements };
145
146 // ---------------------------------------- Kalman filter init -------------------------------------------
148 double _imuFrequency{ 100 };
149
151 double _averageEndTime{ 1 };
152
154 InsTime _avgEndTime;
155
157 bool _autoInitKF = true;
158
160 bool _imuCharacteristicsIdentical = true;
161
163 bool _imuBiasesIdentical = true;
164
166 std::vector<std::shared_ptr<const NAV::ImuObs>> _cumulatedImuObs;
167
169 std::vector<size_t> _cumulatedPinIds;
170
172 bool _initJerkAngAcc = true;
173
175 bool _kfInitialized = false;
176
177 // -------------------------------------------- Sensor info ----------------------------------------------
179 std::vector<PinData> _pinData;
181 PinDataIRWKF _pinDataIRWKF;
183 PinDataBsplineKF _pinDataBsplineKF;
184
186 Eigen::Vector3d _initCoeffsAngRateTemp{};
188 Eigen::Vector3d _initCoeffsAccelTemp{};
190 Eigen::Vector3d _initCovarianceCoeffsAngRateTemp{};
192 Eigen::Vector3d _initCovarianceCoeffsAccelTemp{};
194 Eigen::Vector3d _procNoiseCoeffsAngRateTemp{};
196 Eigen::Vector3d _procNoiseCoeffsAccelTemp{};
197
199 std::vector<Eigen::Vector3d> _biasCovariances;
201 std::vector<Eigen::VectorXd> _processNoiseVariances;
203 std::vector<Eigen::Vector3d> _measurementNoiseVariances;
204
206 std::vector<Eigen::Matrix3d> _imuRotations_accel;
207
209 std::vector<Eigen::Matrix3d> _imuRotations_gyro;
210
211 // ----------------------------------------------- Time --------------------------------------------------
213 InsTime _latestTimestamp{};
214
216 InsTime _firstTimestamp{};
217
219 double _timeSinceStartup{};
220
222 double _latestKnot{};
223
225 double _splineSpacing = 1.0;
226
227 // ------------------------------------------- Miscellaneous ---------------------------------------------
229 bool _checkKalmanMatricesRanks = false;
230
232 bool _imuPosSet = false;
233
235 enum class ImuFusionType
236 {
237 IRWKF,
238 Bspline,
239 COUNT,
240 };
244 friend constexpr const char* to_string(ImuFusionType value);
245
247 ImuFusionType _imuFusionType = ImuFusionType::Bspline;
248};
249
250constexpr const char* to_string(NAV::ImuFusion::ImuFusionType value)
251{
252 switch (value)
253 {
254 case NAV::ImuFusion::ImuFusionType::IRWKF:
255 return "IRW KF";
256 case NAV::ImuFusion::ImuFusionType::Bspline:
257 return "B-spline KF";
258 case NAV::ImuFusion::ImuFusionType::COUNT:
259 return "";
260 }
261 return "";
262}
263
264} // namespace NAV
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
Parent Class for all IMU Observations.
Abstract IMU Class.
@ COUNT
Amount of items in the enum.
Generalized Kalman Filter class.
Information about a sensor which is connected to a certain pin.
const char * to_string(gui::widgets::PositionWithFrame::ReferenceFrame refFrame)
Converts the enum to a string.
Widget to modify time point values.
Combines signals of sensors that provide the same signal-type to one signal.
Definition ImuFusion.hpp:32
friend constexpr const char * to_string(ImuFusionType value)
Converts the enum to a string.
Definition ImuFusion.hpp:250
std::string type() const override
String representation of the Class Type.
ImuFusion(const ImuFusion &)=delete
Copy constructor.
json save() const override
Saves the node into a json object.
ImuFusion & operator=(const ImuFusion &)=delete
Copy assignment operator.
~ImuFusion() override
Destructor.
ImuPos _imuPos
Position and rotation information for conversion from platform to body frame.
Definition ImuFusion.hpp:69
static std::string typeStatic()
String representation of the Class Type.
void guiConfig() override
ImGui config window which is shown on double click.
ImuFusion()
Default constructor.
void restore(const json &j) override
Restores the node from a json object.
ImuFusion & operator=(ImuFusion &&)=delete
Move assignment operator.
static std::string category()
String representation of the Class Category.
ImuFusion(ImuFusion &&)=delete
Move constructor.
IMU Position.
Definition ImuPos.hpp:26
Abstract IMU Class.
Definition Imu.hpp:24
The class is responsible for all time-related tasks.
Definition InsTime.hpp:667