0.3.0
Loading...
Searching...
No Matches
Units.cpp
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
9#include "Units.hpp"
10
11#include "util/Logger.hpp"
12
13namespace NAV::Units
14{
15
16void to_json(json& j, const ImuAccelerometerUnits& data)
17{
18 j = to_string(data);
19}
21{
22 if (!j.is_string())
23 {
24 LOG_WARN("Could not parse '{}' into ImuAccelerometerUnits. Consider resaving the flow", j.dump());
25 return;
26 }
27 std::string str = j.get<std::string>();
28 for (size_t i = 0; i < static_cast<size_t>(ImuAccelerometerUnits::COUNT); i++)
29 {
30 auto enumItem = static_cast<ImuAccelerometerUnits>(i);
31 if (str == to_string(enumItem))
32 {
33 data = enumItem;
34 return;
35 }
36 }
37}
38
39void to_json(json& j, const ImuGyroscopeUnits& data)
40{
41 j = to_string(data);
42}
43void from_json(const json& j, ImuGyroscopeUnits& data)
44{
45 if (!j.is_string())
46 {
47 LOG_WARN("Could not parse '{}' into ImuGyroscopeUnits. Consider resaving the flow", j.dump());
48 return;
49 }
50 std::string str = j.get<std::string>();
51 for (size_t i = 0; i < static_cast<size_t>(ImuGyroscopeUnits::COUNT); i++)
52 {
53 auto enumItem = static_cast<ImuGyroscopeUnits>(i);
54 if (str == to_string(enumItem))
55 {
56 data = enumItem;
57 return;
58 }
59 }
60}
61
63{
64 j = to_string(data);
65}
67{
68 if (!j.is_string())
69 {
70 LOG_WARN("Could not parse '{}' into ImuAccelerometerNoiseUnits. Consider resaving the flow", j.dump());
71 return;
72 }
73 std::string str = j.get<std::string>();
74 for (size_t i = 0; i < static_cast<size_t>(ImuAccelerometerNoiseUnits::COUNT); i++)
75 {
76 auto enumItem = static_cast<ImuAccelerometerNoiseUnits>(i);
77 if (str == to_string(enumItem))
78 {
79 data = enumItem;
80 return;
81 }
82 }
83}
84
85void to_json(json& j, const ImuGyroscopeNoiseUnits& data)
86{
87 j = to_string(data);
88}
90{
91 if (!j.is_string())
92 {
93 LOG_WARN("Could not parse '{}' into ImuGyroscopeNoiseUnits. Consider resaving the flow", j.dump());
94 return;
95 }
96 std::string str = j.get<std::string>();
97 for (size_t i = 0; i < static_cast<size_t>(ImuGyroscopeNoiseUnits::COUNT); i++)
98 {
99 auto enumItem = static_cast<ImuGyroscopeNoiseUnits>(i);
100 if (str == to_string(enumItem))
101 {
102 data = enumItem;
103 return;
104 }
105 }
106}
107
109{
110 j = to_string(data);
111}
113{
114 if (!j.is_string())
115 {
116 LOG_WARN("Could not parse '{}' into ImuAccelerometerIRWUnits. Consider resaving the flow", j.dump());
117 return;
118 }
119 std::string str = j.get<std::string>();
120 for (size_t i = 0; i < static_cast<size_t>(ImuAccelerometerIRWUnits::COUNT); i++)
121 {
122 auto enumItem = static_cast<ImuAccelerometerIRWUnits>(i);
123 if (str == to_string(enumItem))
124 {
125 data = enumItem;
126 return;
127 }
128 }
129}
130
131void to_json(json& j, const ImuGyroscopeIRWUnits& data)
132{
133 j = to_string(data);
134}
136{
137 if (!j.is_string())
138 {
139 LOG_WARN("Could not parse '{}' into ImuGyroscopeIRWUnits. Consider resaving the flow", j.dump());
140 return;
141 }
142 std::string str = j.get<std::string>();
143 for (size_t i = 0; i < static_cast<size_t>(ImuGyroscopeIRWUnits::COUNT); i++)
144 {
145 auto enumItem = static_cast<ImuGyroscopeIRWUnits>(i);
146 if (str == to_string(enumItem))
147 {
148 data = enumItem;
149 return;
150 }
151 }
152}
153
155{
156 j = to_string(data);
157}
159{
160 if (!j.is_string())
161 {
162 LOG_WARN("Could not parse '{}' into ImuAccelerometerFilterNoiseUnits. Consider resaving the flow", j.dump());
163 return;
164 }
165 std::string str = j.get<std::string>();
166 for (size_t i = 0; i < static_cast<size_t>(ImuAccelerometerFilterNoiseUnits::COUNT); i++)
167 {
168 auto enumItem = static_cast<ImuAccelerometerFilterNoiseUnits>(i);
169 if (str == to_string(enumItem))
170 {
171 data = enumItem;
172 return;
173 }
174 }
175}
176
178{
179 j = to_string(data);
180}
182{
183 if (!j.is_string())
184 {
185 LOG_WARN("Could not parse '{}' into ImuGyroscopeFilterNoiseUnits. Consider resaving the flow", j.dump());
186 return;
187 }
188 std::string str = j.get<std::string>();
189 for (size_t i = 0; i < static_cast<size_t>(ImuGyroscopeFilterNoiseUnits::COUNT); i++)
190 {
191 auto enumItem = static_cast<ImuGyroscopeFilterNoiseUnits>(i);
192 if (str == to_string(enumItem))
193 {
194 data = enumItem;
195 return;
196 }
197 }
198}
199
201{
202 j = to_string(data);
203}
205{
206 if (!j.is_string())
207 {
208 LOG_WARN("Could not parse '{}' into ImuAccelerometerFilterBiasUnits. Consider resaving the flow", j.dump());
209 return;
210 }
211 std::string str = j.get<std::string>();
212 for (size_t i = 0; i < static_cast<size_t>(ImuAccelerometerFilterBiasUnits::COUNT); i++)
213 {
214 auto enumItem = static_cast<ImuAccelerometerFilterBiasUnits>(i);
215 if (str == to_string(enumItem))
216 {
217 data = enumItem;
218 return;
219 }
220 }
221}
222
224{
225 j = to_string(data);
226}
228{
229 if (!j.is_string())
230 {
231 LOG_WARN("Could not parse '{}' into ImuGyroscopeFilterBiasUnits. Consider resaving the flow", j.dump());
232 return;
233 }
234 std::string str = j.get<std::string>();
235 for (size_t i = 0; i < static_cast<size_t>(ImuGyroscopeFilterBiasUnits::COUNT); i++)
236 {
237 auto enumItem = static_cast<ImuGyroscopeFilterBiasUnits>(i);
238 if (str == to_string(enumItem))
239 {
240 data = enumItem;
241 return;
242 }
243 }
244}
245
246} // namespace NAV::Units
247
249{
250 switch (unit)
251 {
253 return "m/s^2";
255 return "g";
257 break;
258 }
259 return "";
260}
261
263{
264 switch (unit)
265 {
267 return "rad/s";
269 return "deg/s";
271 break;
272 }
273 return "";
274}
275
277{
278 switch (unit)
279 {
281 return "m/s^2/√(s)";
283 return "m/s^2/√(h)";
285 break;
286 }
287 return "";
288}
289
291{
292 switch (unit)
293 {
295 return "rad/s/√(s)";
297 return "rad/s/√(h)";
299 return "deg/s/√(s)";
301 return "deg/s/√(h)";
303 break;
304 }
305 return "";
306}
307
309{
310 switch (unit)
311 {
313 return "m/s^3/√(s)";
315 return "m/s^3/√(h)";
317 break;
318 }
319 return "";
320}
321
323{
324 switch (unit)
325 {
327 return "rad/s^2/√(s)";
329 return "rad/s^2/√(h)";
331 return "deg/s^2/√(s)";
333 return "deg/s^2/√(h)";
335 break;
336 }
337 return "";
338}
339
341{
342 switch (unit)
343 {
345 return "m/s^2/√(Hz)";
347 return "mg/√(Hz)";
349 break;
350 }
351 return "";
352}
353
355{
356 switch (unit)
357 {
359 return "rad/s/√(Hz)";
361 return "rad/hr/√(Hz)";
363 return "deg/s/√(Hz)";
365 return "deg/hr/√(Hz)";
367 break;
368 }
369 return "";
370}
371
373{
374 switch (unit)
375 {
377 return "m/s^2";
379 return "µg";
381 break;
382 }
383 return "";
384}
385
387{
388 switch (unit)
389 {
391 return "1/s";
393 return "1/h";
395 return "°/s";
397 return "°/h";
399 break;
400 }
401 return "";
402}
nlohmann::json json
json namespace
Units used by INS.
Utility class for logging to console and file.
#define LOG_WARN
Error occurred, but a fallback option exists and program continues to work normally.
Definition Logger.hpp:71
void to_json(json &j, const PositionUncertaintyUnits &data)
Converts the provided data into a json object.
Definition Units.cpp:18
ImuGyroscopeUnits
Possible units to specify an gyroscope bias with.
Definition Units.hpp:40
@ COUNT
Amount of items in the enum.
Definition Units.hpp:43
ImuAccelerometerIRWUnits
Possible units to specify an accelerometer IRW.
Definition Units.hpp:66
@ COUNT
Amount of items in the enum.
Definition Units.hpp:69
@ m_s3_sqrth
[m/s^3/sqrt(h)] (Standard deviation)
Definition Units.hpp:68
@ m_s3_sqrts
[m/s^3/sqrt(s)] (Standard deviation)
Definition Units.hpp:67
ImuAccelerometerNoiseUnits
Possible units to specify an accelerometer noise.
Definition Units.hpp:48
@ m_s2_sqrts
[m/s^2/sqrt(s)] (Standard deviation)
Definition Units.hpp:49
@ COUNT
Amount of items in the enum.
Definition Units.hpp:51
@ m_s2_sqrth
[m/s^2/sqrt(h)] (Standard deviation)
Definition Units.hpp:50
ImuAccelerometerFilterNoiseUnits
Possible units to specify an accelerometer noise in a filter.
Definition Units.hpp:84
@ COUNT
Amount of items in the enum.
Definition Units.hpp:87
ImuAccelerometerFilterBiasUnits
Possible units for the accelerometer dynamic bias.
Definition Units.hpp:102
@ COUNT
Amount of items in the enum.
Definition Units.hpp:105
ImuGyroscopeFilterBiasUnits
Possible units for the gyroscope dynamic bias.
Definition Units.hpp:110
@ COUNT
Amount of items in the enum.
Definition Units.hpp:115
ImuGyroscopeFilterNoiseUnits
Possible units to specify an gyro noise in a filter.
Definition Units.hpp:92
@ deg_hr_sqrtHz
[deg / hr /√(Hz)]
Definition Units.hpp:96
@ COUNT
Amount of items in the enum.
Definition Units.hpp:97
@ rad_hr_sqrtHz
[rad / hr /√(Hz)]
Definition Units.hpp:94
void from_json(const json &j, PositionUncertaintyUnits &data)
Converts the provided json object into the data object.
Definition Units.cpp:22
ImuGyroscopeIRWUnits
Possible units to specify an gyro RW.
Definition Units.hpp:74
@ rad_s2_sqrth
[rad/s^2/sqrt(h)] (Standard deviation)
Definition Units.hpp:76
@ COUNT
Amount of items in the enum.
Definition Units.hpp:79
@ deg_s2_sqrth
[deg/s^2/sqrt(h)] (Standard deviation)
Definition Units.hpp:78
@ deg_s2_sqrts
[deg/s^2/sqrt(s)] (Standard deviation)
Definition Units.hpp:77
@ rad_s2_sqrts
[rad/s^2/sqrt(s)] (Standard deviation)
Definition Units.hpp:75
ImuGyroscopeNoiseUnits
Possible units to specify an gyro noise.
Definition Units.hpp:56
@ deg_s_sqrth
[deg/s/sqrt(h)] (Standard deviation)
Definition Units.hpp:60
@ COUNT
Amount of items in the enum.
Definition Units.hpp:61
@ rad_s_sqrts
[rad/s/sqrt(s)] (Standard deviation)
Definition Units.hpp:57
@ rad_s_sqrth
[rad/s/sqrt(h)] (Standard deviation)
Definition Units.hpp:58
@ deg_s_sqrts
[deg/s/sqrt(s)] (Standard deviation)
Definition Units.hpp:59
ImuAccelerometerUnits
Possible units to specify an accelerometer with.
Definition Units.hpp:32
@ COUNT
Amount of items in the enum.
Definition Units.hpp:35
const char * to_string(gui::widgets::PositionWithFrame::ReferenceFrame refFrame)
Converts the enum to a string.