0.4.1
Loading...
Searching...
No Matches
Units.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
9/// @file Units.hpp
10/// @brief Units used by INS
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2024-10-21
13
14#pragma once
15
16#include <cstddef>
17#include <string>
18
21#include "util/Eigen.hpp"
22#include "util/Json.hpp"
23
24namespace NAV
25{
26
27namespace Units
28{
29
30/// Possible units to specify an accelerometer with
31enum class ImuAccelerometerUnits : uint8_t
32{
33 m_s2, ///< [m/s^2]
34 g, ///< [g]
35 COUNT, ///< Amount of items in the enum
36};
37
38/// Possible units to specify an gyroscope bias with
39enum class ImuGyroscopeUnits : uint8_t
40{
41 rad_s, ///< [rad/s]
42 deg_s, ///< [deg/s]
43 COUNT, ///< Amount of items in the enum
44};
45
46/// Possible units to specify an accelerometer noise
47enum class ImuAccelerometerNoiseUnits : uint8_t
48{
49 m_s2_sqrts, ///< [m/s^2/sqrt(s)] (Standard deviation)
50 m_s2_sqrth, ///< [m/s^2/sqrt(h)] (Standard deviation)
51 COUNT, ///< Amount of items in the enum
52};
53
54/// Possible units to specify an gyro noise
55enum class ImuGyroscopeNoiseUnits : uint8_t
56{
57 rad_s_sqrts, ///< [rad/s/sqrt(s)] (Standard deviation)
58 rad_s_sqrth, ///< [rad/s/sqrt(h)] (Standard deviation)
59 deg_s_sqrts, ///< [deg/s/sqrt(s)] (Standard deviation)
60 deg_s_sqrth, ///< [deg/s/sqrt(h)] (Standard deviation)
61 COUNT, ///< Amount of items in the enum
62};
63
64/// Possible units to specify an accelerometer IRW
65enum class ImuAccelerometerIRWUnits : uint8_t
66{
67 m_s3_sqrts, ///< [m/s^3/sqrt(s)] (Standard deviation)
68 m_s3_sqrth, ///< [m/s^3/sqrt(h)] (Standard deviation)
69 COUNT, ///< Amount of items in the enum
70};
71
72/// Possible units to specify an gyro RW
73enum class ImuGyroscopeIRWUnits : uint8_t
74{
75 rad_s2_sqrts, ///< [rad/s^2/sqrt(s)] (Standard deviation)
76 rad_s2_sqrth, ///< [rad/s^2/sqrt(h)] (Standard deviation)
77 deg_s2_sqrts, ///< [deg/s^2/sqrt(s)] (Standard deviation)
78 deg_s2_sqrth, ///< [deg/s^2/sqrt(h)] (Standard deviation)
79 COUNT, ///< Amount of items in the enum
80};
81
82/// Possible units to specify an accelerometer noise in a filter
84{
85 m_s2_sqrtHz, ///< [m / s^2 / √(Hz)]
86 mg_sqrtHz, ///< [mg / √(Hz)]
87 COUNT, ///< Amount of items in the enum
88};
89
90/// Possible units to specify an gyro noise in a filter
91enum class ImuGyroscopeFilterNoiseUnits : uint8_t
92{
93 rad_s_sqrtHz, ///< [rad / s /√(Hz)]
94 rad_hr_sqrtHz, ///< [rad / hr /√(Hz)]
95 deg_s_sqrtHz, ///< [deg / s /√(Hz)]
96 deg_hr_sqrtHz, ///< [deg / hr /√(Hz)]
97 COUNT, ///< Amount of items in the enum
98};
99
100/// Possible units for the accelerometer dynamic bias
102{
103 m_s2, ///< [m / s^2]
104 microg, ///< [µg]
105 COUNT, ///< Amount of items in the enum
106};
107
108/// Possible units for the gyroscope dynamic bias
109enum class ImuGyroscopeFilterBiasUnits : uint8_t
110{
111 rad_s, ///< [1/s]
112 rad_h, ///< [1/h]
113 deg_s, ///< [°/s]
114 deg_h, ///< [°/h]
115 COUNT, ///< Amount of items in the enum
116};
117
118/// @brief Converts the provided data into a json object
119/// @param[out] j Json object which gets filled with the info
120/// @param[in] data Data to convert into json
121void to_json(json& j, const ImuAccelerometerUnits& data);
122/// @brief Converts the provided json object into the data object
123/// @param[in] j Json object with the needed values
124/// @param[out] data Object to fill from the json
125void from_json(const json& j, ImuAccelerometerUnits& data);
126
127/// @brief Converts the provided data into a json object
128/// @param[out] j Json object which gets filled with the info
129/// @param[in] data Data to convert into json
130void to_json(json& j, const ImuGyroscopeUnits& data);
131/// @brief Converts the provided json object into the data object
132/// @param[in] j Json object with the needed values
133/// @param[out] data Object to fill from the json
134void from_json(const json& j, ImuGyroscopeUnits& data);
135
136/// @brief Converts the provided data into a json object
137/// @param[out] j Json object which gets filled with the info
138/// @param[in] data Data to convert into json
139void to_json(json& j, const ImuAccelerometerNoiseUnits& data);
140/// @brief Converts the provided json object into the data object
141/// @param[in] j Json object with the needed values
142/// @param[out] data Object to fill from the json
143void from_json(const json& j, ImuAccelerometerNoiseUnits& data);
144
145/// @brief Converts the provided data into a json object
146/// @param[out] j Json object which gets filled with the info
147/// @param[in] data Data to convert into json
148void to_json(json& j, const ImuGyroscopeNoiseUnits& data);
149/// @brief Converts the provided json object into the data object
150/// @param[in] j Json object with the needed values
151/// @param[out] data Object to fill from the json
152void from_json(const json& j, ImuGyroscopeNoiseUnits& data);
153
154/// @brief Converts the provided data into a json object
155/// @param[out] j Json object which gets filled with the info
156/// @param[in] data Data to convert into json
157void to_json(json& j, const ImuAccelerometerIRWUnits& data);
158/// @brief Converts the provided json object into the data object
159/// @param[in] j Json object with the needed values
160/// @param[out] data Object to fill from the json
161void from_json(const json& j, ImuAccelerometerIRWUnits& data);
162
163/// @brief Converts the provided data into a json object
164/// @param[out] j Json object which gets filled with the info
165/// @param[in] data Data to convert into json
166void to_json(json& j, const ImuGyroscopeIRWUnits& data);
167/// @brief Converts the provided json object into the data object
168/// @param[in] j Json object with the needed values
169/// @param[out] data Object to fill from the json
170void from_json(const json& j, ImuGyroscopeIRWUnits& data);
171
172/// @brief Converts the provided data into a json object
173/// @param[out] j Json object which gets filled with the info
174/// @param[in] data Data to convert into json
175void to_json(json& j, const ImuAccelerometerFilterNoiseUnits& data);
176/// @brief Converts the provided json object into the data object
177/// @param[in] j Json object with the needed values
178/// @param[out] data Object to fill from the json
180
181/// @brief Converts the provided data into a json object
182/// @param[out] j Json object which gets filled with the info
183/// @param[in] data Data to convert into json
184void to_json(json& j, const ImuGyroscopeFilterNoiseUnits& data);
185/// @brief Converts the provided json object into the data object
186/// @param[in] j Json object with the needed values
187/// @param[out] data Object to fill from the json
188void from_json(const json& j, ImuGyroscopeFilterNoiseUnits& data);
189
190/// @brief Converts the provided data into a json object
191/// @param[out] j Json object which gets filled with the info
192/// @param[in] data Data to convert into json
193void to_json(json& j, const ImuAccelerometerFilterBiasUnits& data);
194/// @brief Converts the provided json object into the data object
195/// @param[in] j Json object with the needed values
196/// @param[out] data Object to fill from the json
198
199/// @brief Converts the provided data into a json object
200/// @param[out] j Json object which gets filled with the info
201/// @param[in] data Data to convert into json
202void to_json(json& j, const ImuGyroscopeFilterBiasUnits& data);
203/// @brief Converts the provided json object into the data object
204/// @param[in] j Json object with the needed values
205/// @param[out] data Object to fill from the json
206void from_json(const json& j, ImuGyroscopeFilterBiasUnits& data);
207
208} // namespace Units
209
210/// @brief Converts the value depending on the unit provided
211/// @param[in] value Value to convert
212/// @param[in] unit Unit the value is in
213/// @return Value in unit of the first item in the Unit enum
214template<typename Derived>
215[[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuAccelerometerUnits unit)
216{
217 switch (unit)
218 {
220 return value;
222 return value * InsConst::G_NORM;
224 break;
225 }
226 return value;
227}
228
229/// @brief Converts the value depending on the unit provided
230/// @param[in] value Value to convert
231/// @param[in] unit Unit the value is in
232/// @return Value in unit of the first item in the Unit enum
233template<typename Derived>
234[[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuGyroscopeUnits unit)
235{
236 switch (unit)
237 {
239 return value;
241 return deg2rad(value);
243 break;
244 }
245 return value;
246}
247
248/// @brief Converts the value depending on the unit provided
249/// @param[in] value Value to convert
250/// @param[in] unit Unit the value is in
251/// @return Value in unit of the first item in the Unit enum
252template<typename Derived>
253[[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuAccelerometerNoiseUnits unit)
254{
255 switch (unit)
256 {
258 return value;
260 return value / 60.0;
262 break;
263 }
264 return value;
265}
266
267/// @brief Converts the value depending on the unit provided
268/// @param[in] value Value to convert
269/// @param[in] unit Unit the value is in
270/// @return Value in unit of the first item in the Unit enum
271template<typename Derived>
272[[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuGyroscopeNoiseUnits unit)
273{
274 switch (unit)
275 {
277 return value;
279 return value / 60.0;
281 return deg2rad(value);
283 return deg2rad(value) / 60.0;
285 break;
286 }
287 return value;
288}
289
290/// @brief Converts the value depending on the unit provided
291/// @param[in] value Value to convert
292/// @param[in] unit Unit the value is in
293/// @return Value in unit of the first item in the Unit enum
294template<typename Derived>
295[[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuAccelerometerIRWUnits unit)
296{
297 switch (unit)
298 {
300 return value;
302 return value / 60.0;
304 break;
305 }
306 return value;
307}
308
309/// @brief Converts the value depending on the unit provided
310/// @param[in] value Value to convert
311/// @param[in] unit Unit the value is in
312/// @return Value in unit of the first item in the Unit enum
313template<typename Derived>
314[[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuGyroscopeIRWUnits unit)
315{
316 switch (unit)
317 {
319 return value;
321 return value / 60.0;
323 return deg2rad(value);
325 return deg2rad(value) / 60.0;
327 break;
328 }
329 return value;
330}
331
332/// @brief Converts the value depending on the unit provided
333/// @param[in] value Value to convert
334/// @param[in] unit Unit the value is in
335/// @return Value in unit of the first item in the Unit enum
336template<typename Derived>
337[[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuAccelerometerFilterNoiseUnits unit)
338{
339 switch (unit)
340 {
342 return value;
344 return value * 1e-3 * InsConst::G_NORM;
346 break;
347 }
348 return value;
349}
350
351/// @brief Converts the value depending on the unit provided
352/// @param[in] value Value to convert
353/// @param[in] unit Unit the value is in
354/// @return Value in unit of the first item in the Unit enum
355template<typename Derived>
356[[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuGyroscopeFilterNoiseUnits unit)
357{
358 switch (unit)
359 {
361 return value;
363 return value / 3600.0;
365 return deg2rad(value);
367 return deg2rad(value) / 3600.0;
369 break;
370 }
371 return value;
372}
373
374/// @brief Converts the value depending on the unit provided
375/// @param[in] value Value to convert
376/// @param[in] unit Unit the value is in
377/// @return Value in unit of the first item in the Unit enum
378template<typename Derived>
379[[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuAccelerometerFilterBiasUnits unit)
380{
381 switch (unit)
382 {
384 return value;
386 return value * 1e-6 * InsConst::G_NORM;
388 break;
389 }
390 return value;
391}
392
393/// @brief Converts the value depending on the unit provided
394/// @param[in] value Value to convert
395/// @param[in] unit Unit the value is in
396/// @return Value in unit of the first item in the Unit enum
397template<typename Derived>
398[[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuGyroscopeFilterBiasUnits unit)
399{
400 switch (unit)
401 {
403 return value;
405 return value / 3600.0;
407 return deg2rad(value);
409 return deg2rad(value) / 3600.0;
411 break;
412 }
413 return value;
414}
415
416/// @brief Converts the unit into a string
417/// @param[in] unit Unit
418[[nodiscard]] std::string to_string(Units::ImuAccelerometerUnits unit);
419/// @brief Converts the unit into a string
420/// @param[in] unit Unit
421[[nodiscard]] std::string to_string(Units::ImuGyroscopeUnits unit);
422/// @brief Converts the unit into a string
423/// @param[in] unit Unit
424[[nodiscard]] std::string to_string(Units::ImuAccelerometerNoiseUnits unit);
425/// @brief Converts the unit into a string
426/// @param[in] unit Unit
427[[nodiscard]] std::string to_string(Units::ImuGyroscopeNoiseUnits unit);
428/// @brief Converts the unit into a string
429/// @param[in] unit Unit
430[[nodiscard]] std::string to_string(Units::ImuAccelerometerIRWUnits unit);
431/// @brief Converts the unit into a string
432/// @param[in] unit Unit
433[[nodiscard]] std::string to_string(Units::ImuGyroscopeIRWUnits unit);
434/// @brief Converts the unit into a string
435/// @param[in] unit Unit
436[[nodiscard]] std::string to_string(Units::ImuAccelerometerFilterNoiseUnits unit);
437/// @brief Converts the unit into a string
438/// @param[in] unit Unit
439[[nodiscard]] std::string to_string(Units::ImuGyroscopeFilterNoiseUnits unit);
440/// @brief Converts the unit into a string
441/// @param[in] unit Unit
442[[nodiscard]] std::string to_string(Units::ImuAccelerometerFilterBiasUnits unit);
443/// @brief Converts the unit into a string
444/// @param[in] unit Unit
445[[nodiscard]] std::string to_string(Units::ImuGyroscopeFilterBiasUnits unit);
446
447} // namespace NAV
Holds all Constants.
Vector space operations.
nlohmann::json json
json namespace
Defines how to save certain datatypes to json.
static constexpr double G_NORM
Standard gravity in [m / s^2].
Definition Constants.hpp:40
void to_json(json &j, const PositionUncertaintyUnits &data)
Converts the provided data into a json object.
Definition Units.cpp:18
@ COUNT
Amount of items in the enum.
Definition Units.hpp:33
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.
double convertUnit(const double &value, Units::PositionUncertaintyUnits unit)
Converts the value depending on the unit provided.
Definition Units.cpp:135
constexpr auto deg2rad(const T &deg)
Convert Degree to Radians.
Definition Units.hpp:21