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 "PressToHgt.hpp" | ||
10 | |||
11 | #include "util/Logger.hpp" | ||
12 | |||
13 | #include "internal/NodeManager.hpp" | ||
14 | namespace nm = NAV::NodeManager; | ||
15 | #include "internal/FlowManager.hpp" | ||
16 | |||
17 | #include "NodeData/Baro/BaroPressObs.hpp" | ||
18 | #include "NodeData/Baro/BaroHgt.hpp" | ||
19 | |||
20 | #include "Navigation/Gravity/Gravity.hpp" | ||
21 | |||
22 | #include "internal/gui/widgets/imgui_ex.hpp" | ||
23 | #include "internal/gui/widgets/EnumCombo.hpp" | ||
24 | #include "internal/gui/widgets/HelpMarker.hpp" | ||
25 | #include "internal/gui/NodeEditorApplication.hpp" | ||
26 | |||
27 | 112 | NAV::PressToHgt::PressToHgt() | |
28 |
3/6✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 112 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 112 times.
✗ Branch 9 not taken.
|
112 | : Node(typeStatic()) |
29 | { | ||
30 | LOG_TRACE("{}: called", name); | ||
31 | 112 | _hasConfig = true; | |
32 | 112 | _guiConfigDefaultWindowSize = { 710, 220 }; | |
33 | |||
34 |
4/8✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 112 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 112 times.
✓ Branch 9 taken 112 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
336 | nm::CreateInputPin(this, "BaroPressObs", Pin::Type::Flow, { NAV::BaroPressObs::type() }, &PressToHgt::receiveObs); |
35 | |||
36 |
4/8✓ Branch 2 taken 112 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 112 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 112 times.
✓ Branch 10 taken 112 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
448 | nm::CreateOutputPin(this, "BaroHgt", Pin::Type::Flow, { NAV::BaroHgt::type() }); |
37 | 336 | } | |
38 | |||
39 | 224 | NAV::PressToHgt::~PressToHgt() | |
40 | { | ||
41 | LOG_TRACE("{}: called", nameId()); | ||
42 | 224 | } | |
43 | |||
44 | 224 | std::string NAV::PressToHgt::typeStatic() | |
45 | { | ||
46 |
1/2✓ Branch 1 taken 224 times.
✗ Branch 2 not taken.
|
448 | return "PressToHgt"; |
47 | } | ||
48 | |||
49 | ✗ | std::string NAV::PressToHgt::type() const | |
50 | { | ||
51 | ✗ | return typeStatic(); | |
52 | } | ||
53 | |||
54 | 112 | std::string NAV::PressToHgt::category() | |
55 | { | ||
56 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
224 | return "Data Processor"; |
57 | } | ||
58 | |||
59 | ✗ | void NAV::PressToHgt::guiConfig() | |
60 | { | ||
61 | ✗ | float columnWidth = 140.0F * gui::NodeEditorApplication::windowFontRatio(); | |
62 | |||
63 | ✗ | if (ImGui::InputDouble(fmt::format("Sea-level pressure##{}", size_t(id)).c_str(), &_pressure0, 0.0, 0.0, "%.3f hPa")) | |
64 | { | ||
65 | LOG_DATA("{}: pressure0 changed to {}", nameId(), _pressure0); | ||
66 | ✗ | flow::ApplyChanges(); | |
67 | } | ||
68 | ✗ | if (ImGui::InputDouble(fmt::format("Sea-level temperature##{}", size_t(id)).c_str(), &_temp0, 0.0, 0.0, "%.3f K")) | |
69 | { | ||
70 | LOG_DATA("{}: temp0 changed to {}", nameId(), _temp0); | ||
71 | ✗ | flow::ApplyChanges(); | |
72 | } | ||
73 | ✗ | if (ImGui::InputDouble(fmt::format("Temperature lapse rate##{}", size_t(id)).c_str(), &_lapserate, 0.0, 0.0, "%.6f K / m")) | |
74 | { | ||
75 | LOG_DATA("{}: lapserate changed to {}", nameId(), _lapserate); | ||
76 | ✗ | flow::ApplyChanges(); | |
77 | } | ||
78 | ✗ | if (ImGui::InputDouble(fmt::format("Geoid undulation##{}", size_t(id)).c_str(), &_geoidhgt, 0.0, 0.0, "%.3f m")) | |
79 | { | ||
80 | LOG_DATA("{}: geoidhgt changed to {}", nameId(), _geoidhgt); | ||
81 | ✗ | flow::ApplyChanges(); | |
82 | } | ||
83 | ✗ | ImGui::SetNextItemWidth(columnWidth); | |
84 | ✗ | if (gui::widgets::EnumCombo(fmt::format("Gravity input##{}", size_t(id)).c_str(), _gravityInput)) | |
85 | { | ||
86 | LOG_DATA("{}: gravity input changed to {}", nameId(), fmt::underlying(_gravityInput)); | ||
87 | ✗ | flow::ApplyChanges(); | |
88 | } | ||
89 | ✗ | ImGui::SameLine(); | |
90 | ✗ | gui::widgets::HelpMarker("The 'position' input calculates the gravity magnitude from EGM96.\n\n"); | |
91 | ✗ | if (_gravityInput == GravityInput::Manual) | |
92 | { | ||
93 | ✗ | if (ImGui::InputDouble(fmt::format("Gravity##{}", size_t(id)).c_str(), &_gravity, 0.0, 0.0, "%.5f m / s²")) | |
94 | { | ||
95 | LOG_DATA("{}: gravity changed to {}", nameId(), _gravity); | ||
96 | ✗ | flow::ApplyChanges(); | |
97 | } | ||
98 | } | ||
99 | else // (_gravityInput == GravityInput::Position) | ||
100 | { | ||
101 | ✗ | if (ImGui::InputDouble3(fmt::format("Position LLA [deg, deg, m]##{}", size_t(id)).c_str(), _initPos.data())) | |
102 | { | ||
103 | ✗ | flow::ApplyChanges(); | |
104 | } | ||
105 | } | ||
106 | ✗ | } | |
107 | |||
108 | ✗ | bool NAV::PressToHgt::initialize() | |
109 | { | ||
110 | LOG_TRACE("{}: called", nameId()); | ||
111 | ✗ | if (_gravityInput == GravityInput::Position) | |
112 | { | ||
113 | ✗ | _gravity = n_calcGravitation_EGM96(_initPos).norm(); | |
114 | LOG_DATA("{}: PressToHgt - Local gravity magnitude: {} m/s² at initial position: {} [deg, deg, m]", nameId(), _gravity, _initPos.transpose()); | ||
115 | } | ||
116 | ✗ | _exponent = _gravity * InsConst::dMtr / InsConst::Rg / _lapserate; | |
117 | ✗ | return true; | |
118 | } | ||
119 | |||
120 | ✗ | void NAV::PressToHgt::deinitialize() | |
121 | { | ||
122 | LOG_TRACE("{}: called", nameId()); | ||
123 | ✗ | } | |
124 | |||
125 | ✗ | [[nodiscard]] json NAV::PressToHgt::save() const | |
126 | { | ||
127 | LOG_TRACE("{}: called", nameId()); | ||
128 | |||
129 | ✗ | json j; | |
130 | |||
131 | ✗ | j["temp0"] = _temp0; | |
132 | ✗ | j["pressure0"] = _pressure0; | |
133 | ✗ | j["lapserate"] = _lapserate; | |
134 | ✗ | j["geoidhgt"] = _geoidhgt; | |
135 | ✗ | j["gravity"] = _gravity; | |
136 | ✗ | j["initPos"] = _initPos; | |
137 | ✗ | j["gravityInput"] = _gravityInput; | |
138 | ✗ | return j; | |
139 | ✗ | } | |
140 | |||
141 | ✗ | void NAV::PressToHgt::restore(json const& j) | |
142 | { | ||
143 | LOG_TRACE("{}: called", nameId()); | ||
144 | |||
145 | ✗ | if (j.contains("temp0")) | |
146 | { | ||
147 | ✗ | j.at("temp0").get_to(_temp0); | |
148 | } | ||
149 | ✗ | if (j.contains("pressure0")) | |
150 | { | ||
151 | ✗ | j.at("pressure0").get_to(_pressure0); | |
152 | } | ||
153 | ✗ | if (j.contains("lapserate")) | |
154 | { | ||
155 | ✗ | j.at("lapserate").get_to(_lapserate); | |
156 | } | ||
157 | ✗ | if (j.contains("geoidhgt")) | |
158 | { | ||
159 | ✗ | j.at("geoidhgt").get_to(_geoidhgt); | |
160 | } | ||
161 | ✗ | if (j.contains("gravity")) | |
162 | { | ||
163 | ✗ | j.at("gravity").get_to(_gravity); | |
164 | } | ||
165 | ✗ | if (j.contains("initPos")) | |
166 | { | ||
167 | ✗ | j.at("initPos").get_to(_initPos); | |
168 | } | ||
169 | ✗ | if (j.contains("gravityInput")) | |
170 | { | ||
171 | ✗ | j.at("gravityInput").get_to(_gravityInput); | |
172 | } | ||
173 | ✗ | } | |
174 | |||
175 | ✗ | void NAV::PressToHgt::receiveObs(NAV::InputPin::NodeDataQueue& queue, size_t /* pinIdx */) | |
176 | { | ||
177 | ✗ | auto pressureObs = std::static_pointer_cast<const BaroPressObs>(queue.extract_front()); | |
178 | |||
179 | ✗ | auto baroheight = std::make_shared<BaroHgt>(); | |
180 | |||
181 | ✗ | baroheight->insTime = pressureObs->insTime; | |
182 | |||
183 | ✗ | baroheight->baro_height = _temp0 / _lapserate * (1.0 - std::pow(pressureObs->baro_pressure / _pressure0, 1.0 / _exponent)) + _geoidhgt; | |
184 | |||
185 | // if uncertainty of pressure value is provided carry out error propagation for barometric height (assuming all other parameters are error free) | ||
186 | ✗ | if (pressureObs->baro_pressureStdev.has_value()) | |
187 | { | ||
188 | ✗ | baroheight->baro_heightStdev = std::fabs(_temp0 / (_lapserate * _exponent * pressureObs->baro_pressure) * std::pow(pressureObs->baro_pressure / _pressure0, 1.0 / _exponent - 1.0)) * pressureObs->baro_pressureStdev.value(); | |
189 | } | ||
190 | |||
191 | ✗ | invokeCallbacks(OUTPUT_PORT_INDEX_BAROHEIGHT, baroheight); | |
192 | ✗ | } | |
193 |