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