Line | Branch | Exec | Source |
---|---|---|---|
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 | |||
19 | #include "Navigation/Transformations/Units.hpp" | ||
20 | #include "util/Eigen.hpp" | ||
21 | #include "util/Json.hpp" | ||
22 | |||
23 | namespace NAV | ||
24 | { | ||
25 | |||
26 | namespace Units | ||
27 | { | ||
28 | |||
29 | /// Possible units to specify an accelerometer with | ||
30 | enum class ImuAccelerometerUnits : uint8_t | ||
31 | { | ||
32 | m_s2, ///< [m/s^2] | ||
33 | COUNT, ///< Amount of items in the enum | ||
34 | }; | ||
35 | |||
36 | /// Possible units to specify an gyroscope bias with | ||
37 | enum class ImuGyroscopeUnits : uint8_t | ||
38 | { | ||
39 | rad_s, ///< [rad/s] | ||
40 | deg_s, ///< [deg/s] | ||
41 | COUNT, ///< Amount of items in the enum | ||
42 | }; | ||
43 | |||
44 | /// Possible units to specify an accelerometer noise | ||
45 | enum class ImuAccelerometerNoiseUnits : uint8_t | ||
46 | { | ||
47 | m_s2_sqrts, ///< [m/s^2/sqrt(s)] (Standard deviation) | ||
48 | m_s2_sqrth, ///< [m/s^2/sqrt(h)] (Standard deviation) | ||
49 | COUNT, ///< Amount of items in the enum | ||
50 | }; | ||
51 | |||
52 | /// Possible units to specify an gyro noise | ||
53 | enum class ImuGyroscopeNoiseUnits : uint8_t | ||
54 | { | ||
55 | rad_s_sqrts, ///< [rad/s/sqrt(s)] (Standard deviation) | ||
56 | rad_s_sqrth, ///< [rad/s/sqrt(h)] (Standard deviation) | ||
57 | deg_s_sqrts, ///< [deg/s/sqrt(s)] (Standard deviation) | ||
58 | deg_s_sqrth, ///< [deg/s/sqrt(h)] (Standard deviation) | ||
59 | COUNT, ///< Amount of items in the enum | ||
60 | }; | ||
61 | |||
62 | /// Possible units to specify an accelerometer IRW | ||
63 | enum class ImuAccelerometerIRWUnits : uint8_t | ||
64 | { | ||
65 | m_s3_sqrts, ///< [m/s^3/sqrt(s)] (Standard deviation) | ||
66 | m_s3_sqrth, ///< [m/s^3/sqrt(h)] (Standard deviation) | ||
67 | COUNT, ///< Amount of items in the enum | ||
68 | }; | ||
69 | |||
70 | /// Possible units to specify an gyro RW | ||
71 | enum class ImuGyroscopeIRWUnits : uint8_t | ||
72 | { | ||
73 | rad_s2_sqrts, ///< [rad/s^2/sqrt(s)] (Standard deviation) | ||
74 | rad_s2_sqrth, ///< [rad/s^2/sqrt(h)] (Standard deviation) | ||
75 | deg_s2_sqrts, ///< [deg/s^2/sqrt(s)] (Standard deviation) | ||
76 | deg_s2_sqrth, ///< [deg/s^2/sqrt(h)] (Standard deviation) | ||
77 | COUNT, ///< Amount of items in the enum | ||
78 | }; | ||
79 | |||
80 | /// @brief Converts the provided data into a json object | ||
81 | /// @param[out] j Json object which gets filled with the info | ||
82 | /// @param[in] data Data to convert into json | ||
83 | void to_json(json& j, const ImuAccelerometerUnits& data); | ||
84 | /// @brief Converts the provided json object into the data object | ||
85 | /// @param[in] j Json object with the needed values | ||
86 | /// @param[out] data Object to fill from the json | ||
87 | void from_json(const json& j, ImuAccelerometerUnits& data); | ||
88 | |||
89 | /// @brief Converts the provided data into a json object | ||
90 | /// @param[out] j Json object which gets filled with the info | ||
91 | /// @param[in] data Data to convert into json | ||
92 | void to_json(json& j, const ImuGyroscopeUnits& data); | ||
93 | /// @brief Converts the provided json object into the data object | ||
94 | /// @param[in] j Json object with the needed values | ||
95 | /// @param[out] data Object to fill from the json | ||
96 | void from_json(const json& j, ImuGyroscopeUnits& data); | ||
97 | |||
98 | /// @brief Converts the provided data into a json object | ||
99 | /// @param[out] j Json object which gets filled with the info | ||
100 | /// @param[in] data Data to convert into json | ||
101 | void to_json(json& j, const ImuAccelerometerNoiseUnits& data); | ||
102 | /// @brief Converts the provided json object into the data object | ||
103 | /// @param[in] j Json object with the needed values | ||
104 | /// @param[out] data Object to fill from the json | ||
105 | void from_json(const json& j, ImuAccelerometerNoiseUnits& data); | ||
106 | |||
107 | /// @brief Converts the provided data into a json object | ||
108 | /// @param[out] j Json object which gets filled with the info | ||
109 | /// @param[in] data Data to convert into json | ||
110 | void to_json(json& j, const ImuGyroscopeNoiseUnits& data); | ||
111 | /// @brief Converts the provided json object into the data object | ||
112 | /// @param[in] j Json object with the needed values | ||
113 | /// @param[out] data Object to fill from the json | ||
114 | void from_json(const json& j, ImuGyroscopeNoiseUnits& data); | ||
115 | |||
116 | /// @brief Converts the provided data into a json object | ||
117 | /// @param[out] j Json object which gets filled with the info | ||
118 | /// @param[in] data Data to convert into json | ||
119 | void to_json(json& j, const ImuAccelerometerIRWUnits& data); | ||
120 | /// @brief Converts the provided json object into the data object | ||
121 | /// @param[in] j Json object with the needed values | ||
122 | /// @param[out] data Object to fill from the json | ||
123 | void from_json(const json& j, ImuAccelerometerIRWUnits& data); | ||
124 | |||
125 | /// @brief Converts the provided data into a json object | ||
126 | /// @param[out] j Json object which gets filled with the info | ||
127 | /// @param[in] data Data to convert into json | ||
128 | void to_json(json& j, const ImuGyroscopeIRWUnits& data); | ||
129 | /// @brief Converts the provided json object into the data object | ||
130 | /// @param[in] j Json object with the needed values | ||
131 | /// @param[out] data Object to fill from the json | ||
132 | void from_json(const json& j, ImuGyroscopeIRWUnits& data); | ||
133 | |||
134 | } // namespace Units | ||
135 | |||
136 | /// @brief Converts the value depending on the unit provided | ||
137 | /// @param[in] value Value to convert | ||
138 | /// @param[in] unit Unit the value is in | ||
139 | /// @return Value in unit of the first item in the Unit enum | ||
140 | template<typename Derived> | ||
141 | 60019 | [[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuAccelerometerUnits unit) | |
142 | { | ||
143 |
1/3✓ Branch 0 taken 60020 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
60019 | switch (unit) |
144 | { | ||
145 | 60020 | case Units::ImuAccelerometerUnits::m_s2: | |
146 | 60020 | return value; | |
147 | ✗ | case Units::ImuAccelerometerUnits::COUNT: | |
148 | ✗ | break; | |
149 | } | ||
150 | ✗ | return value; | |
151 | } | ||
152 | |||
153 | /// @brief Converts the value depending on the unit provided | ||
154 | /// @param[in] value Value to convert | ||
155 | /// @param[in] unit Unit the value is in | ||
156 | /// @return Value in unit of the first item in the Unit enum | ||
157 | template<typename Derived> | ||
158 | 60003 | [[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuGyroscopeUnits unit) | |
159 | { | ||
160 |
1/4✓ Branch 0 taken 60006 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
60003 | switch (unit) |
161 | { | ||
162 | 60006 | case Units::ImuGyroscopeUnits::rad_s: | |
163 | 60006 | return value; | |
164 | ✗ | case Units::ImuGyroscopeUnits::deg_s: | |
165 | ✗ | return deg2rad(value); | |
166 | ✗ | case Units::ImuGyroscopeUnits::COUNT: | |
167 | ✗ | break; | |
168 | } | ||
169 | ✗ | return value; | |
170 | } | ||
171 | |||
172 | /// @brief Converts the value depending on the unit provided | ||
173 | /// @param[in] value Value to convert | ||
174 | /// @param[in] unit Unit the value is in | ||
175 | /// @return Value in unit of the first item in the Unit enum | ||
176 | template<typename Derived> | ||
177 | 95003 | [[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuAccelerometerNoiseUnits unit) | |
178 | { | ||
179 |
1/4✓ Branch 0 taken 95010 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
95003 | switch (unit) |
180 | { | ||
181 | 95010 | case Units::ImuAccelerometerNoiseUnits::m_s2_sqrts: | |
182 | 95010 | return value; | |
183 | ✗ | case Units::ImuAccelerometerNoiseUnits::m_s2_sqrth: | |
184 | ✗ | return value / 60.0; | |
185 | ✗ | case Units::ImuAccelerometerNoiseUnits::COUNT: | |
186 | ✗ | break; | |
187 | } | ||
188 | ✗ | return value; | |
189 | } | ||
190 | |||
191 | /// @brief Converts the value depending on the unit provided | ||
192 | /// @param[in] value Value to convert | ||
193 | /// @param[in] unit Unit the value is in | ||
194 | /// @return Value in unit of the first item in the Unit enum | ||
195 | template<typename Derived> | ||
196 | 95010 | [[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuGyroscopeNoiseUnits unit) | |
197 | { | ||
198 |
2/6✓ Branch 0 taken 94228 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 786 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
95010 | switch (unit) |
199 | { | ||
200 | 94228 | case Units::ImuGyroscopeNoiseUnits::rad_s_sqrts: | |
201 | 94228 | return value; | |
202 | ✗ | case Units::ImuGyroscopeNoiseUnits::rad_s_sqrth: | |
203 | ✗ | return value / 60.0; | |
204 | 786 | case Units::ImuGyroscopeNoiseUnits::deg_s_sqrts: | |
205 |
2/4✓ Branch 1 taken 786 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 786 times.
✗ Branch 5 not taken.
|
786 | return deg2rad(value); |
206 | ✗ | case Units::ImuGyroscopeNoiseUnits::deg_s_sqrth: | |
207 | ✗ | return deg2rad(value) / 60.0; | |
208 | ✗ | case Units::ImuGyroscopeNoiseUnits::COUNT: | |
209 | ✗ | break; | |
210 | } | ||
211 | ✗ | return value; | |
212 | } | ||
213 | |||
214 | /// @brief Converts the value depending on the unit provided | ||
215 | /// @param[in] value Value to convert | ||
216 | /// @param[in] unit Unit the value is in | ||
217 | /// @return Value in unit of the first item in the Unit enum | ||
218 | template<typename Derived> | ||
219 | 34998 | [[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuAccelerometerIRWUnits unit) | |
220 | { | ||
221 |
1/4✓ Branch 0 taken 35000 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
34998 | switch (unit) |
222 | { | ||
223 | 35000 | case Units::ImuAccelerometerIRWUnits::m_s3_sqrts: | |
224 | 35000 | return value; | |
225 | ✗ | case Units::ImuAccelerometerIRWUnits::m_s3_sqrth: | |
226 | ✗ | return value / 60.0; | |
227 | ✗ | case Units::ImuAccelerometerIRWUnits::COUNT: | |
228 | ✗ | break; | |
229 | } | ||
230 | ✗ | return value; | |
231 | } | ||
232 | |||
233 | /// @brief Converts the value depending on the unit provided | ||
234 | /// @param[in] value Value to convert | ||
235 | /// @param[in] unit Unit the value is in | ||
236 | /// @return Value in unit of the first item in the Unit enum | ||
237 | template<typename Derived> | ||
238 | 35003 | [[nodiscard]] typename Derived::PlainObject convertUnit(const Eigen::MatrixBase<Derived>& value, Units::ImuGyroscopeIRWUnits unit) | |
239 | { | ||
240 |
2/6✓ Branch 0 taken 35002 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
35003 | switch (unit) |
241 | { | ||
242 | 35002 | case Units::ImuGyroscopeIRWUnits::rad_s2_sqrts: | |
243 | 35002 | return value; | |
244 | ✗ | case Units::ImuGyroscopeIRWUnits::rad_s2_sqrth: | |
245 | ✗ | return value / 60.0; | |
246 | ✗ | case Units::ImuGyroscopeIRWUnits::deg_s2_sqrts: | |
247 | ✗ | return deg2rad(value); | |
248 | ✗ | case Units::ImuGyroscopeIRWUnits::deg_s2_sqrth: | |
249 | ✗ | return deg2rad(value) / 60.0; | |
250 | ✗ | case Units::ImuGyroscopeIRWUnits::COUNT: | |
251 | ✗ | break; | |
252 | } | ||
253 | 1 | return value; | |
254 | } | ||
255 | |||
256 | /// @brief Converts the unit into a string | ||
257 | /// @param[in] unit Unit | ||
258 | [[nodiscard]] std::string to_string(Units::ImuAccelerometerUnits unit); | ||
259 | /// @brief Converts the unit into a string | ||
260 | /// @param[in] unit Unit | ||
261 | [[nodiscard]] std::string to_string(Units::ImuGyroscopeUnits unit); | ||
262 | /// @brief Converts the unit into a string | ||
263 | /// @param[in] unit Unit | ||
264 | [[nodiscard]] std::string to_string(Units::ImuAccelerometerNoiseUnits unit); | ||
265 | /// @brief Converts the unit into a string | ||
266 | /// @param[in] unit Unit | ||
267 | [[nodiscard]] std::string to_string(Units::ImuGyroscopeNoiseUnits unit); | ||
268 | /// @brief Converts the unit into a string | ||
269 | /// @param[in] unit Unit | ||
270 | [[nodiscard]] std::string to_string(Units::ImuAccelerometerIRWUnits unit); | ||
271 | /// @brief Converts the unit into a string | ||
272 | /// @param[in] unit Unit | ||
273 | [[nodiscard]] std::string to_string(Units::ImuGyroscopeIRWUnits unit); | ||
274 | |||
275 | } // namespace NAV | ||
276 |