0.2.0
Loading...
Searching...
No Matches
ImuSimulator.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
18
19#include "util/Eigen.hpp"
25
27
28#include <array>
29
30namespace NAV
31{
33class ImuSimulator : public Imu
34{
35 public:
39 ~ImuSimulator() override;
41 ImuSimulator(const ImuSimulator&) = delete;
48
50 [[nodiscard]] static std::string typeStatic();
51
53 [[nodiscard]] std::string type() const override;
54
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
70 bool resetNode() override;
71
72 private:
73 using Scalar = long double;
74
75 constexpr static size_t INPUT_PORT_INDEX_CSV = 0;
76 constexpr static size_t OUTPUT_PORT_INDEX_IMU_OBS = 0;
77 constexpr static size_t OUTPUT_PORT_INDEX_POS_VEL_ATT = 1;
78
80 bool initialize() override;
81
83 void deinitialize() override;
84
89 [[nodiscard]] std::shared_ptr<const NodeData> pollImuObs(size_t pinIdx, bool peek);
90
95 [[nodiscard]] std::shared_ptr<const NodeData> pollPosVelAtt(size_t pinIdx, bool peek);
96
101 bool checkStopCondition(Scalar time, const Eigen::Vector3<Scalar>& lla_position);
102
103 // ###########################################################################################################
104
106 enum class StartTimeSource
107 {
108 CustomTime,
109 CurrentComputerTime,
110 };
111
113 StartTimeSource _startTimeSource = StartTimeSource::CustomTime;
114
116 gui::widgets::TimeEditFormat _startTimeEditFormat;
117
119 InsTime _startTime{ 2000, 1, 1, 0, 0, 0 };
120
121 // ###########################################################################################################
122
124 double _imuInternalFrequency = 1000;
126 double _imuFrequency = 100;
128 double _gnssFrequency = 5;
129
130 // ###########################################################################################################
131
133 enum class TrajectoryType
134 {
135 Fixed,
136 Linear,
137 Circular,
138 Csv,
139 RoseFigure,
140 COUNT,
141 };
145 static const char* to_string(TrajectoryType value);
146
148 TrajectoryType _trajectoryType = TrajectoryType::Fixed;
149
154 gui::widgets::PositionWithFrame _startPosition;
155
157 Eigen::Vector3d _fixedTrajectoryStartOrientation = Eigen::Vector3d::Zero();
158
160 Eigen::Vector3d _n_linearTrajectoryStartVelocity = Eigen::Vector3d{ 1, 0, 0 };
161
163 int _circularHarmonicFrequency = 0;
164
166 double _circularHarmonicAmplitudeFactor = 0.1;
167
169 enum class Direction
170 {
171 CW,
172 CCW,
173 COUNT,
174 };
178 static const char* to_string(Direction value);
179
181 Direction _trajectoryDirection = Direction::CCW;
182
184 double _trajectoryRotationAngle = 0.0;
185
187 double _trajectoryHorizontalSpeed = 10.0;
188
190 double _trajectoryVerticalSpeed = 0.0;
191
193 double _trajectoryRadius = 50.0;
194
196 int _rosePetNum = 2;
197
199 int _rosePetDenom = 1;
200
202 double _roseStepLengthMax = 0.1;
203
205 double _roseSimDuration = 0.0;
206
207 // ###########################################################################################################
208
210 enum StopCondition
211 {
212 Duration,
213 DistanceOrCirclesOrRoses,
214 };
215
217 StopCondition _simulationStopCondition = StopCondition::Duration;
218
220 double _simulationDuration = 5 * 60;
221
223 Scalar _csvDuration = 0;
224
226 double _linearTrajectoryDistanceForStop = 100;
227
229 double _circularTrajectoryCircleCountForStop = 1.0;
230
232 double _roseTrajectoryCountForStop = 1.0;
233 // ###########################################################################################################
234
236 GravitationModel _gravitationModel = GravitationModel::EGM96;
237
239 bool _coriolisAccelerationEnabled = true;
240
242 bool _centrifgalAccelerationEnabled = true;
243
245 bool _angularRateEarthRotationEnabled = true;
246
248 bool _angularRateTransportRateEnabled = true;
249
250 // ###########################################################################################################
251
256 [[nodiscard]] InsTime getTimeFromCsvLine(const CsvData::CsvLine& line, const std::vector<std::string>& description) const;
257
262 [[nodiscard]] Eigen::Vector3<Scalar> e_getPositionFromCsvLine(const CsvData::CsvLine& line, const std::vector<std::string>& description) const;
263
268 static Eigen::Quaternion<Scalar> n_getAttitudeQuaternionFromCsvLine_b(const CsvData::CsvLine& line, const std::vector<std::string>& description);
269
271 struct
272 {
273 Scalar sampleInterval = 0.03;
280 } _splines;
281
284 bool initializeSplines();
285
287 uint64_t _imuInternalUpdateCnt = 0.0;
289 uint64_t _imuUpdateCnt = 0.0;
291 uint64_t _gnssUpdateCnt = 0.0;
292
294 static constexpr Scalar INTERNAL_LINEAR_UPDATE_FREQUENCY = 1000;
295
297 Scalar _imuLastUpdateTime = 0.0;
299 Scalar _gnssLastUpdateTime = 0.0;
301 Eigen::Vector3<Scalar> _lla_imuLastLinearPosition = Eigen::Vector3<Scalar>::Zero();
303 Eigen::Vector3<Scalar> _lla_gnssLastLinearPosition = Eigen::Vector3<Scalar>::Zero();
305 Eigen::Vector3<Scalar> _p_lastImuAccelerationMeas = Eigen::Vector3<Scalar>::Ones() * std::nan("");
307 Eigen::Vector3<Scalar> _p_lastImuAngularRateMeas = Eigen::Vector3<Scalar>::Ones() * std::nan("");
308
312 [[nodiscard]] std::array<Scalar, 3> calcFlightAngles(Scalar time) const;
313
317 [[nodiscard]] Eigen::Vector3<Scalar> lla_calcPosition(Scalar time) const;
318
323 [[nodiscard]] Eigen::Vector3<Scalar> n_calcVelocity(Scalar time, const Eigen::Quaternion<Scalar>& n_Quat_e) const;
324
331 [[nodiscard]] Eigen::Vector3<Scalar> n_calcTrajectoryAccel(Scalar time, const Eigen::Quaternion<Scalar>& n_Quat_e,
332 const Eigen::Vector3<Scalar>& lla_position, const Eigen::Vector3<Scalar>& n_velocity) const;
333
339 [[nodiscard]] Eigen::Vector3<Scalar> n_calcOmega_nb(Scalar time, const Eigen::Vector3<Scalar>& rollPitchYaw, const Eigen::Quaternion<Scalar>& n_Quat_b) const;
340};
341
342} // namespace NAV
CSV Data container.
Cubic Spline class.
Vector space operations.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
Different Gravity Models.
GravitationModel
Available Gravitation Models.
Definition Gravity.hpp:30
Abstract IMU Class.
The class is responsible for all time-related tasks.
@ COUNT
Amount of items in the enum.
Position Input GUI widgets.
Widget to modify time point values.
std::vector< CsvElement > CsvLine
CSV Line with splitted entries.
Definition CsvData.hpp:34
Cubic Spline class.
Definition CubicSpline.hpp:34
Imu Observation Simulator.
Definition ImuSimulator.hpp:34
void restore(const json &j) override
Restores the node from a json object.
ImuSimulator()
Default constructor.
CubicSpline< Scalar > z
ECEF Z Position [m].
Definition ImuSimulator.hpp:276
static std::string typeStatic()
String representation of the Class Type.
ImuSimulator(ImuSimulator &&)=delete
Move constructor.
json save() const override
Saves the node into a json object.
~ImuSimulator() override
Destructor.
ImuSimulator(const ImuSimulator &)=delete
Copy constructor.
static std::string category()
String representation of the Class Category.
CubicSpline< Scalar > pitch
Pitch angle [rad].
Definition ImuSimulator.hpp:278
void guiConfig() override
ImGui config window which is shown on double click.
bool resetNode() override
Resets the node. Moves the read cursor to the start.
Scalar sampleInterval
Spline sample interval.
Definition ImuSimulator.hpp:273
std::string type() const override
String representation of the Class Type.
ImuSimulator & operator=(const ImuSimulator &)=delete
Copy assignment operator.
CubicSpline< Scalar > yaw
Yaw angle [rad].
Definition ImuSimulator.hpp:279
ImuSimulator & operator=(ImuSimulator &&)=delete
Move assignment operator.
CubicSpline< Scalar > y
ECEF Y Position [m].
Definition ImuSimulator.hpp:275
CubicSpline< Scalar > x
ECEF X Position [m].
Definition ImuSimulator.hpp:274
CubicSpline< Scalar > roll
Roll angle [rad].
Definition ImuSimulator.hpp:277
Abstract IMU Class.
Definition Imu.hpp:24
The class is responsible for all time-related tasks.
Definition InsTime.hpp:667
Time Edit format and system.
Definition TimeEdit.hpp:29