| 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 "CommonLog.hpp" | ||
| 10 | |||
| 11 | #include <imgui.h> | ||
| 12 | |||
| 13 | #include "Navigation/Ellipsoid/Ellipsoid.hpp" | ||
| 14 | #include "Navigation/Transformations/Units.hpp" | ||
| 15 | |||
| 16 | #include "util/Logger.hpp" | ||
| 17 | |||
| 18 | namespace NAV | ||
| 19 | { | ||
| 20 | |||
| 21 | ✗ | json CommonLog::save() | |
| 22 | { | ||
| 23 | ✗ | json j; | |
| 24 | ✗ | j["useGuiInputs"] = _useGuiInputs; | |
| 25 | ✗ | if (_originPosition) { j["originPosition"] = *_originPosition; } | |
| 26 | |||
| 27 | ✗ | return j; | |
| 28 | ✗ | } | |
| 29 | |||
| 30 | 114 | void CommonLog::restore(const json& j) | |
| 31 | { | ||
| 32 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 2 taken 93 times.
|
114 | if (j.contains("useGuiInputs")) { j.at("useGuiInputs").get_to(_useGuiInputs); } |
| 33 | 93 | else { _useGuiInputs = false; } | |
| 34 |
4/6✓ Branch 1 taken 1 times.
✓ Branch 2 taken 113 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
114 | if (j.contains("originPosition")) { _originPosition = j.at("originPosition").get<gui::widgets::PositionWithFrame>(); } |
| 35 | 113 | else { _originPosition.reset(); } | |
| 36 | 114 | } | |
| 37 | |||
| 38 | 723 | CommonLog::CommonLog() | |
| 39 | { | ||
| 40 |
1/2✓ Branch 1 taken 723 times.
✗ Branch 2 not taken.
|
723 | std::scoped_lock lk(_mutex); |
| 41 | 723 | _index = _wantsInit.size(); // NOLINT(cppcoreguidelines-prefer-member-initializer) | |
| 42 |
1/2✓ Branch 1 taken 723 times.
✗ Branch 2 not taken.
|
723 | _wantsInit.push_back(false); |
| 43 | 723 | } | |
| 44 | |||
| 45 | 1446 | CommonLog::~CommonLog() | |
| 46 | { | ||
| 47 | 1446 | std::scoped_lock lk(_mutex); | |
| 48 | 1446 | _wantsInit.erase(_wantsInit.begin() + static_cast<int64_t>(_index)); | |
| 49 | 1446 | } | |
| 50 | |||
| 51 | 117 | void CommonLog::initialize() const | |
| 52 | { | ||
| 53 |
1/2✓ Branch 1 taken 117 times.
✗ Branch 2 not taken.
|
117 | std::scoped_lock lk(_mutex); |
| 54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
|
117 | if (_useGuiInputs) { return; } |
| 55 |
1/2✓ Branch 1 taken 117 times.
✗ Branch 2 not taken.
|
117 | _wantsInit.at(_index) = true; |
| 56 | |||
| 57 |
3/4✓ Branch 1 taken 117 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 92 times.
✓ Branch 4 taken 25 times.
|
276 | if (std::ranges::all_of(_wantsInit, [](bool val) { return val; })) |
| 58 | { | ||
| 59 |
2/4✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 92 times.
✗ Branch 6 not taken.
|
92 | LOG_DEBUG("Resetting common log variables."); |
| 60 | 92 | _startTime.reset(); | |
| 61 |
1/2✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
|
92 | if (!_useGuiInputs) |
| 62 | { | ||
| 63 | 92 | _originPosition.reset(); | |
| 64 | } | ||
| 65 | |||
| 66 |
1/2✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
|
92 | std::ranges::fill(_wantsInit, false); |
| 67 | } | ||
| 68 | 117 | } | |
| 69 | |||
| 70 | 368566 | double CommonLog::calcTimeIntoRun(const InsTime& insTime) | |
| 71 | { | ||
| 72 |
3/4✓ Branch 1 taken 368566 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 368563 times.
|
737132 | if (std::scoped_lock lk(_mutex); |
| 73 | 368566 | _startTime.empty()) | |
| 74 | { | ||
| 75 | 3 | _startTime = insTime; | |
| 76 |
4/8✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 13 taken 3 times.
✗ Branch 14 not taken.
|
3 | LOG_DEBUG("Common log setting start time to {} ({}) GPST.", _startTime.toYMDHMS(GPST), _startTime.toGPSweekTow(GPST)); |
| 77 | 368566 | } | |
| 78 |
1/2✓ Branch 1 taken 368566 times.
✗ Branch 2 not taken.
|
368566 | return static_cast<double>((insTime - _startTime).count()); |
| 79 | } | ||
| 80 | |||
| 81 | 136504 | CommonLog::LocalPosition CommonLog::calcLocalPosition(const Eigen::Vector3d& lla_position) | |
| 82 | { | ||
| 83 | { | ||
| 84 |
1/2✓ Branch 1 taken 136504 times.
✗ Branch 2 not taken.
|
136504 | std::scoped_lock lk(_mutex); |
| 85 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 136502 times.
|
136504 | if (!_originPosition.has_value()) |
| 86 | { | ||
| 87 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
|
2 | if (lla_position.hasNaN()) |
| 88 | { | ||
| 89 | ✗ | LOG_WARN("Not setting common log origin to {}, {}, {} [deg, deg, m]", | |
| 90 | rad2deg(lla_position.x()), rad2deg(lla_position.y()), lla_position.z()); | ||
| 91 | } | ||
| 92 | else | ||
| 93 | { | ||
| 94 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | _originPosition = gui::widgets::PositionWithFrame(); |
| 95 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | _originPosition->e_position = trafo::lla2ecef_WGS84(lla_position); |
| 96 |
5/10✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
|
2 | LOG_DEBUG("Common log setting position of origin to {}, {}, {} [deg, deg, m]", |
| 97 | rad2deg(lla_position.x()), rad2deg(lla_position.y()), lla_position.z()); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | 136504 | } | |
| 101 | |||
| 102 | // North/South deviation [m] | ||
| 103 | 136504 | double northSouth = calcGeographicalDistance(lla_position.x(), lla_position.y(), | |
| 104 | 136504 | _originPosition->latitude(), lla_position.y()) | |
| 105 |
2/2✓ Branch 3 taken 68324 times.
✓ Branch 4 taken 68180 times.
|
136504 | * (lla_position.x() > _originPosition->latitude() ? 1 : -1); |
| 106 | |||
| 107 | // East/West deviation [m] | ||
| 108 | 273008 | double eastWest = calcGeographicalDistance(lla_position.x(), lla_position.y(), | |
| 109 | 136504 | lla_position.x(), _originPosition->longitude()) | |
| 110 |
2/2✓ Branch 3 taken 144 times.
✓ Branch 4 taken 136360 times.
|
136504 | * (lla_position.y() > _originPosition->longitude() ? 1 : -1); |
| 111 | |||
| 112 | 136504 | return { .northSouth = northSouth, .eastWest = eastWest }; | |
| 113 | } | ||
| 114 | |||
| 115 | ✗ | bool CommonLog::ShowOriginInput(const char* id) | |
| 116 | { | ||
| 117 | ✗ | bool changed = false; | |
| 118 | ✗ | if (ImGui::Checkbox(fmt::format("Override position origin (for all common logging)##{}", id).c_str(), &_useGuiInputs)) | |
| 119 | { | ||
| 120 | ✗ | LOG_DEBUG("{}: useGuiInputs changed to {}", id, _useGuiInputs); | |
| 121 | ✗ | changed = true; | |
| 122 | } | ||
| 123 | ✗ | if (_useGuiInputs) | |
| 124 | { | ||
| 125 | ✗ | if (!_originPosition) { _originPosition = gui::widgets::PositionWithFrame(); } | |
| 126 | ✗ | ImGui::Indent(); | |
| 127 | ✗ | std::scoped_lock lk(_mutex); | |
| 128 | ✗ | if (gui::widgets::PositionInput(fmt::format("Origin##{}", id).c_str(), _originPosition.value(), gui::widgets::PositionInputLayout::SINGLE_ROW)) | |
| 129 | { | ||
| 130 | ✗ | changed = true; | |
| 131 | } | ||
| 132 | ✗ | ImGui::Unindent(); | |
| 133 | ✗ | } | |
| 134 | |||
| 135 | ✗ | return changed; | |
| 136 | } | ||
| 137 | |||
| 138 | } // namespace NAV | ||
| 139 |