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 <cmath>
12#include "util/Logger.hpp"
14
15namespace NAV::Units
16{
17
18void to_json(json& j, const CovarianceAccelUnits& data)
19{
20 j = to_string(data);
21}
22void from_json(const json& j, CovarianceAccelUnits& data)
23{
24 if (!j.is_string())
25 {
26 LOG_WARN("Could not parse '{}' into CovarianceAccelUnits. Consider resaving the flow", j.dump());
27 return;
28 }
29 std::string str = j.get<std::string>();
30 for (size_t i = 0; i < static_cast<size_t>(CovarianceAccelUnits::COUNT); i++)
31 {
32 auto enumItem = static_cast<CovarianceAccelUnits>(i);
33 if (str == to_string(enumItem))
34 {
35 data = enumItem;
36 return;
37 }
38 }
39}
40
42{
43 j = to_string(data);
44}
46{
47 if (!j.is_string())
48 {
49 LOG_WARN("Could not parse '{}' into CovarianceAngularVelocityUnits. Consider resaving the flow", j.dump());
50 return;
51 }
52 std::string str = j.get<std::string>();
53 for (size_t i = 0; i < static_cast<size_t>(CovarianceAngularVelocityUnits::COUNT); i++)
54 {
55 auto enumItem = static_cast<CovarianceAngularVelocityUnits>(i);
56 if (str == to_string(enumItem))
57 {
58 data = enumItem;
59 return;
60 }
61 }
62}
63
65{
66 j = to_string(data);
67}
69{
70 if (!j.is_string())
71 {
72 LOG_WARN("Could not parse '{}' into CovarianceClkPhaseDriftUnits. Consider resaving the flow", j.dump());
73 return;
74 }
75 std::string str = j.get<std::string>();
76 for (size_t i = 0; i < static_cast<size_t>(CovarianceClkPhaseDriftUnits::COUNT); i++)
77 {
78 auto enumItem = static_cast<CovarianceClkPhaseDriftUnits>(i);
79 if (str == to_string(enumItem))
80 {
81 data = enumItem;
82 return;
83 }
84 }
85}
86
88{
89 j = to_string(data);
90}
92{
93 if (!j.is_string())
94 {
95 LOG_WARN("Could not parse '{}' into CovarianceClkFrequencyDriftUnits. Consider resaving the flow", j.dump());
96 return;
97 }
98 std::string str = j.get<std::string>();
99 for (size_t i = 0; i < static_cast<size_t>(CovarianceClkFrequencyDriftUnits::COUNT); i++)
100 {
101 auto enumItem = static_cast<CovarianceClkFrequencyDriftUnits>(i);
102 if (str == to_string(enumItem))
103 {
104 data = enumItem;
105 return;
106 }
107 }
108}
109
110} // namespace NAV::Units
111
112double NAV::convertUnit(const double& value, Units::CovarianceAccelUnits unit)
113{
114 switch (unit)
115 {
117 return value;
119 return std::pow(value, 2);
121 break;
122 }
123 return value; // Covariance of the acceleration 𝜎_a due to user motion in horizontal and vertical component [m²/s³]
124}
125
127{
128 switch (unit)
129 {
131 return value;
133 return std::pow(value, 2);
135 return deg2rad(deg2rad(value));
137 return std::pow(deg2rad(value), 2);
139 return deg2rad(deg2rad(value)) / 3600.0;
141 return std::pow(deg2rad(value) / 60.0, 2);
143 break;
144 }
145 return value; // Covariance of the acceleration 𝜎_a due to user motion in horizontal and vertical component [m²/s³]
146}
147
149{
150 switch (unit)
151 {
153 return value;
155 return std::pow(value, 2);
157 break;
158 }
159 return value; // Covariance of the clock phase drift [m²/s]
160}
161
163{
164 switch (unit)
165 {
167 return value;
169 return std::pow(value, 2);
171 break;
172 }
173 return value; // Covariance of the frequency phase drift [m²/s³]
174}
175
177{
178 switch (unit)
179 {
181 return "m^2/s^3";
183 return "m/√(s^3)";
185 break;
186 }
187 return "";
188}
189
191{
192 switch (unit)
193 {
195 return "rad^2/s";
197 return "rad/√(s)";
199 return "deg^2/s";
201 return "deg/√(s)";
203 return "deg^2 s/min^2";
205 return "deg √(s)/min";
207 break;
208 }
209 return "";
210}
211
213{
214 switch (unit)
215 {
217 return "m^2/s";
219 return "m/√s";
221 break;
222 }
223 return "";
224}
225
227{
228 switch (unit)
229 {
231 return "m^2/s^3";
233 return "m/√(s^3)";
235 break;
236 }
237 return "";
238}
nlohmann::json json
json namespace
Units used by the system model parameters.
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
CovarianceAngularVelocityUnits
Possible Units for the Standard deviation of the rotation velocity.
Definition Units.hpp:37
@ COUNT
Amount of items in the enum.
Definition Units.hpp:44
CovarianceClkPhaseDriftUnits
Possible Units for the Standard deviation of the clock phase drift.
Definition Units.hpp:49
@ COUNT
Amount of items in the enum.
Definition Units.hpp:52
CovarianceAccelUnits
Possible Units for the Standard deviation of the acceleration due to user motion.
Definition Units.hpp:29
@ COUNT
Amount of items in the enum.
Definition Units.hpp:32
@ m_sqrts3
[ m / √(s^3) ]
Definition Units.hpp:31
void from_json(const json &j, PositionUncertaintyUnits &data)
Converts the provided json object into the data object.
Definition Units.cpp:22
CovarianceClkFrequencyDriftUnits
Possible Units for the Standard deviation of the clock frequency drift.
Definition Units.hpp:57
@ COUNT
Amount of items in the enum.
Definition Units.hpp:60
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