| 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 | #include "Units.hpp" | ||
| 10 | |||
| 11 | #include <cmath> | ||
| 12 | #include "Navigation/Transformations/Units.hpp" | ||
| 13 | #include "util/Logger.hpp" | ||
| 14 | |||
| 15 | namespace NAV::Units | ||
| 16 | { | ||
| 17 | |||
| 18 | ✗ | void to_json(json& j, const PositionUncertaintyUnits& data) | |
| 19 | { | ||
| 20 | ✗ | j = to_string(data); | |
| 21 | ✗ | } | |
| 22 | ✗ | void from_json(const json& j, PositionUncertaintyUnits& data) | |
| 23 | { | ||
| 24 | ✗ | if (!j.is_string()) | |
| 25 | { | ||
| 26 | ✗ | LOG_WARN("Could not parse '{}' into PositionUncertaintyUnits. 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>(PositionUncertaintyUnits::COUNT); i++) | |
| 31 | { | ||
| 32 | ✗ | auto enumItem = static_cast<PositionUncertaintyUnits>(i); | |
| 33 | ✗ | if (str == to_string(enumItem)) | |
| 34 | { | ||
| 35 | ✗ | data = enumItem; | |
| 36 | ✗ | return; | |
| 37 | } | ||
| 38 | } | ||
| 39 | ✗ | } | |
| 40 | |||
| 41 | ✗ | void to_json(json& j, const VelocityUncertaintyUnits& data) | |
| 42 | { | ||
| 43 | ✗ | j = to_string(data); | |
| 44 | ✗ | } | |
| 45 | ✗ | void from_json(const json& j, VelocityUncertaintyUnits& data) | |
| 46 | { | ||
| 47 | ✗ | if (!j.is_string()) | |
| 48 | { | ||
| 49 | ✗ | LOG_WARN("Could not parse '{}' into VelocityUncertaintyUnits. 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>(VelocityUncertaintyUnits::COUNT); i++) | |
| 54 | { | ||
| 55 | ✗ | auto enumItem = static_cast<VelocityUncertaintyUnits>(i); | |
| 56 | ✗ | if (str == to_string(enumItem)) | |
| 57 | { | ||
| 58 | ✗ | data = enumItem; | |
| 59 | ✗ | return; | |
| 60 | } | ||
| 61 | } | ||
| 62 | ✗ | } | |
| 63 | |||
| 64 | ✗ | void to_json(json& j, const AttitudeUncertaintyUnits& data) | |
| 65 | { | ||
| 66 | ✗ | j = to_string(data); | |
| 67 | ✗ | } | |
| 68 | ✗ | void from_json(const json& j, AttitudeUncertaintyUnits& data) | |
| 69 | { | ||
| 70 | ✗ | if (!j.is_string()) | |
| 71 | { | ||
| 72 | ✗ | LOG_WARN("Could not parse '{}' into AttitudeUncertaintyUnits. 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>(AttitudeUncertaintyUnits::COUNT); i++) | |
| 77 | { | ||
| 78 | ✗ | auto enumItem = static_cast<AttitudeUncertaintyUnits>(i); | |
| 79 | ✗ | if (str == to_string(enumItem)) | |
| 80 | { | ||
| 81 | ✗ | data = enumItem; | |
| 82 | ✗ | return; | |
| 83 | } | ||
| 84 | } | ||
| 85 | ✗ | } | |
| 86 | |||
| 87 | ✗ | void to_json(json& j, const VelocityUnits& data) | |
| 88 | { | ||
| 89 | ✗ | j = to_string(data); | |
| 90 | ✗ | } | |
| 91 | ✗ | void from_json(const json& j, VelocityUnits& data) | |
| 92 | { | ||
| 93 | ✗ | if (!j.is_string()) | |
| 94 | { | ||
| 95 | ✗ | LOG_WARN("Could not parse '{}' into VelocityUnits. 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>(VelocityUnits::COUNT); i++) | |
| 100 | { | ||
| 101 | ✗ | auto enumItem = static_cast<VelocityUnits>(i); | |
| 102 | ✗ | if (str == to_string(enumItem)) | |
| 103 | { | ||
| 104 | ✗ | data = enumItem; | |
| 105 | ✗ | return; | |
| 106 | } | ||
| 107 | } | ||
| 108 | ✗ | } | |
| 109 | |||
| 110 | ✗ | void to_json(json& j, const AttitudeUnits& data) | |
| 111 | { | ||
| 112 | ✗ | j = to_string(data); | |
| 113 | ✗ | } | |
| 114 | ✗ | void from_json(const json& j, AttitudeUnits& data) | |
| 115 | { | ||
| 116 | ✗ | if (!j.is_string()) | |
| 117 | { | ||
| 118 | ✗ | LOG_WARN("Could not parse '{}' into AttitudeUnits. Consider resaving the flow", j.dump()); | |
| 119 | ✗ | return; | |
| 120 | } | ||
| 121 | ✗ | std::string str = j.get<std::string>(); | |
| 122 | ✗ | for (size_t i = 0; i < static_cast<size_t>(AttitudeUnits::COUNT); i++) | |
| 123 | { | ||
| 124 | ✗ | auto enumItem = static_cast<AttitudeUnits>(i); | |
| 125 | ✗ | if (str == to_string(enumItem)) | |
| 126 | { | ||
| 127 | ✗ | data = enumItem; | |
| 128 | ✗ | return; | |
| 129 | } | ||
| 130 | } | ||
| 131 | ✗ | } | |
| 132 | |||
| 133 | } // namespace NAV::Units | ||
| 134 | |||
| 135 | ✗ | double NAV::convertUnit(const double& value, Units::PositionUncertaintyUnits unit) | |
| 136 | { | ||
| 137 | ✗ | switch (unit) | |
| 138 | { | ||
| 139 | ✗ | case Units::PositionUncertaintyUnits::meter: | |
| 140 | ✗ | return value; | |
| 141 | ✗ | case Units::PositionUncertaintyUnits::meter2: | |
| 142 | ✗ | return std::sqrt(value); | |
| 143 | ✗ | case Units::PositionUncertaintyUnits::COUNT: | |
| 144 | ✗ | break; | |
| 145 | } | ||
| 146 | ✗ | return value; // Position standard deviation [m] | |
| 147 | } | ||
| 148 | ✗ | Eigen::Vector3d NAV::convertUnit(const Eigen::Vector3d& value, Units::PositionUncertaintyUnits unit) | |
| 149 | { | ||
| 150 | ✗ | switch (unit) | |
| 151 | { | ||
| 152 | ✗ | case Units::PositionUncertaintyUnits::meter: | |
| 153 | ✗ | return value; | |
| 154 | ✗ | case Units::PositionUncertaintyUnits::meter2: | |
| 155 | ✗ | return value.array().sqrt(); | |
| 156 | ✗ | case Units::PositionUncertaintyUnits::COUNT: | |
| 157 | ✗ | break; | |
| 158 | } | ||
| 159 | ✗ | return value; // Position standard deviation [m] | |
| 160 | } | ||
| 161 | |||
| 162 | ✗ | double NAV::convertUnit(const double& value, Units::VelocityUncertaintyUnits unit) | |
| 163 | { | ||
| 164 | ✗ | switch (unit) | |
| 165 | { | ||
| 166 | ✗ | case Units::VelocityUncertaintyUnits::m_s: | |
| 167 | ✗ | return value; | |
| 168 | ✗ | case Units::VelocityUncertaintyUnits::m2_s2: | |
| 169 | ✗ | return std::sqrt(value); | |
| 170 | ✗ | case Units::VelocityUncertaintyUnits::COUNT: | |
| 171 | ✗ | break; | |
| 172 | } | ||
| 173 | ✗ | return value; // Velocity standard deviation [m/s] | |
| 174 | } | ||
| 175 | ✗ | Eigen::Vector3d NAV::convertUnit(const Eigen::Vector3d& value, Units::VelocityUncertaintyUnits unit) | |
| 176 | { | ||
| 177 | ✗ | switch (unit) | |
| 178 | { | ||
| 179 | ✗ | case Units::VelocityUncertaintyUnits::m_s: | |
| 180 | ✗ | return value; | |
| 181 | ✗ | case Units::VelocityUncertaintyUnits::m2_s2: | |
| 182 | ✗ | return value.array().sqrt(); | |
| 183 | ✗ | case Units::VelocityUncertaintyUnits::COUNT: | |
| 184 | ✗ | break; | |
| 185 | } | ||
| 186 | ✗ | return value; // Velocity standard deviation [m/s] | |
| 187 | } | ||
| 188 | |||
| 189 | ✗ | double NAV::convertUnit(const double& value, Units::AttitudeUncertaintyUnits unit) | |
| 190 | { | ||
| 191 | ✗ | switch (unit) | |
| 192 | { | ||
| 193 | ✗ | case Units::AttitudeUncertaintyUnits::rad: | |
| 194 | ✗ | return value; | |
| 195 | ✗ | case Units::AttitudeUncertaintyUnits::deg: | |
| 196 | ✗ | return deg2rad(value); | |
| 197 | ✗ | case Units::AttitudeUncertaintyUnits::rad2: | |
| 198 | ✗ | return std::sqrt(value); | |
| 199 | ✗ | case Units::AttitudeUncertaintyUnits::deg2: | |
| 200 | ✗ | return deg2rad(std::sqrt(value)); | |
| 201 | ✗ | case Units::AttitudeUncertaintyUnits::COUNT: | |
| 202 | ✗ | break; | |
| 203 | } | ||
| 204 | ✗ | return value; // Attitude standard deviation [rad] | |
| 205 | } | ||
| 206 | ✗ | Eigen::Vector3d NAV::convertUnit(const Eigen::Vector3d& value, Units::AttitudeUncertaintyUnits unit) | |
| 207 | { | ||
| 208 | ✗ | switch (unit) | |
| 209 | { | ||
| 210 | ✗ | case Units::AttitudeUncertaintyUnits::rad: | |
| 211 | ✗ | return value; | |
| 212 | ✗ | case Units::AttitudeUncertaintyUnits::deg: | |
| 213 | ✗ | return deg2rad(value); | |
| 214 | ✗ | case Units::AttitudeUncertaintyUnits::rad2: | |
| 215 | ✗ | return value.array().sqrt(); | |
| 216 | ✗ | case Units::AttitudeUncertaintyUnits::deg2: | |
| 217 | ✗ | return deg2rad(value.array().sqrt()); | |
| 218 | ✗ | case Units::AttitudeUncertaintyUnits::COUNT: | |
| 219 | ✗ | break; | |
| 220 | } | ||
| 221 | ✗ | return value; // Attitude standard deviation [rad] | |
| 222 | } | ||
| 223 | |||
| 224 | ✗ | double NAV::convertUnit(const double& value, Units::VelocityUnits unit) | |
| 225 | { | ||
| 226 | ✗ | switch (unit) | |
| 227 | { | ||
| 228 | ✗ | case Units::VelocityUnits::m_s: | |
| 229 | ✗ | return value; | |
| 230 | ✗ | case Units::VelocityUnits::COUNT: | |
| 231 | ✗ | break; | |
| 232 | } | ||
| 233 | ✗ | return value; // [m/s] | |
| 234 | } | ||
| 235 | ✗ | Eigen::Vector3d NAV::convertUnit(const Eigen::Vector3d& value, Units::VelocityUnits unit) | |
| 236 | { | ||
| 237 | ✗ | switch (unit) | |
| 238 | { | ||
| 239 | ✗ | case Units::VelocityUnits::m_s: | |
| 240 | ✗ | return value; | |
| 241 | ✗ | case Units::VelocityUnits::COUNT: | |
| 242 | ✗ | break; | |
| 243 | } | ||
| 244 | ✗ | return value; // [m/s] | |
| 245 | } | ||
| 246 | |||
| 247 | ✗ | double NAV::convertUnit(const double& value, Units::AttitudeUnits unit) | |
| 248 | { | ||
| 249 | ✗ | switch (unit) | |
| 250 | { | ||
| 251 | ✗ | case Units::AttitudeUnits::rad: | |
| 252 | ✗ | return value; | |
| 253 | ✗ | case Units::AttitudeUnits::deg: | |
| 254 | ✗ | return deg2rad(value); | |
| 255 | ✗ | case Units::AttitudeUnits::COUNT: | |
| 256 | ✗ | break; | |
| 257 | } | ||
| 258 | ✗ | return value; // [rad] | |
| 259 | } | ||
| 260 | ✗ | Eigen::Vector3d NAV::convertUnit(const Eigen::Vector3d& value, Units::AttitudeUnits unit) | |
| 261 | { | ||
| 262 | ✗ | switch (unit) | |
| 263 | { | ||
| 264 | ✗ | case Units::AttitudeUnits::rad: | |
| 265 | ✗ | return value; | |
| 266 | ✗ | case Units::AttitudeUnits::deg: | |
| 267 | ✗ | return deg2rad(value); | |
| 268 | ✗ | case Units::AttitudeUnits::COUNT: | |
| 269 | ✗ | break; | |
| 270 | } | ||
| 271 | ✗ | return value; // [rad] | |
| 272 | } | ||
| 273 | |||
| 274 | ✗ | std::string NAV::to_string(Units::PositionUncertaintyUnits unit) | |
| 275 | { | ||
| 276 | ✗ | switch (unit) | |
| 277 | { | ||
| 278 | ✗ | case Units::PositionUncertaintyUnits::meter2: | |
| 279 | ✗ | return "m^2"; | |
| 280 | ✗ | case Units::PositionUncertaintyUnits::meter: | |
| 281 | ✗ | return "m"; | |
| 282 | ✗ | case Units::PositionUncertaintyUnits::COUNT: | |
| 283 | ✗ | break; | |
| 284 | } | ||
| 285 | ✗ | return ""; | |
| 286 | } | ||
| 287 | |||
| 288 | ✗ | std::string NAV::to_string(Units::VelocityUncertaintyUnits unit) | |
| 289 | { | ||
| 290 | ✗ | switch (unit) | |
| 291 | { | ||
| 292 | ✗ | case Units::VelocityUncertaintyUnits::m2_s2: | |
| 293 | ✗ | return "m^2/s^2"; | |
| 294 | ✗ | case Units::VelocityUncertaintyUnits::m_s: | |
| 295 | ✗ | return "m/s"; | |
| 296 | ✗ | case Units::VelocityUncertaintyUnits::COUNT: | |
| 297 | ✗ | break; | |
| 298 | } | ||
| 299 | ✗ | return ""; | |
| 300 | } | ||
| 301 | |||
| 302 | ✗ | std::string NAV::to_string(Units::AttitudeUncertaintyUnits unit) | |
| 303 | { | ||
| 304 | ✗ | switch (unit) | |
| 305 | { | ||
| 306 | ✗ | case Units::AttitudeUncertaintyUnits::rad: | |
| 307 | ✗ | return "rad"; | |
| 308 | ✗ | case Units::AttitudeUncertaintyUnits::deg: | |
| 309 | ✗ | return "deg"; | |
| 310 | ✗ | case Units::AttitudeUncertaintyUnits::rad2: | |
| 311 | ✗ | return "rad^2"; | |
| 312 | ✗ | case Units::AttitudeUncertaintyUnits::deg2: | |
| 313 | ✗ | return "deg^2"; | |
| 314 | ✗ | case Units::AttitudeUncertaintyUnits::COUNT: | |
| 315 | ✗ | break; | |
| 316 | } | ||
| 317 | ✗ | return ""; | |
| 318 | } | ||
| 319 | |||
| 320 | ✗ | std::string NAV::to_string(Units::VelocityUnits unit) | |
| 321 | { | ||
| 322 | ✗ | switch (unit) | |
| 323 | { | ||
| 324 | ✗ | case Units::VelocityUnits::m_s: | |
| 325 | ✗ | return "m/s"; | |
| 326 | ✗ | case Units::VelocityUnits::COUNT: | |
| 327 | ✗ | break; | |
| 328 | } | ||
| 329 | ✗ | return ""; | |
| 330 | } | ||
| 331 | |||
| 332 | ✗ | std::string NAV::to_string(Units::AttitudeUnits unit) | |
| 333 | { | ||
| 334 | ✗ | switch (unit) | |
| 335 | { | ||
| 336 | ✗ | case Units::AttitudeUnits::rad: | |
| 337 | ✗ | return "rad"; | |
| 338 | ✗ | case Units::AttitudeUnits::deg: | |
| 339 | ✗ | return "deg"; | |
| 340 | ✗ | case Units::AttitudeUnits::COUNT: | |
| 341 | ✗ | break; | |
| 342 | } | ||
| 343 | ✗ | return ""; | |
| 344 | } | ||
| 345 |