0.4.1
Loading...
Searching...
No Matches
PressToHgt.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 "PressToHgt.hpp"
10
11#include "util/Logger.hpp"
12
14namespace nm = NAV::NodeManager;
16
19
21
26
28 : Node(typeStatic())
29{
30 LOG_TRACE("{}: called", name);
31 _hasConfig = true;
32 _guiConfigDefaultWindowSize = { 710, 220 };
33
35
37}
38
40{
41 LOG_TRACE("{}: called", nameId());
42}
43
45{
46 return "PressToHgt";
47}
48
49std::string NAV::PressToHgt::type() const
50{
51 return typeStatic();
52}
53
55{
56 return "Data Processor";
57}
58
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);
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);
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);
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);
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));
88 }
89 ImGui::SameLine();
90 gui::widgets::HelpMarker("The 'position' input calculates the gravity magnitude from EGM96.\n\n");
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);
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 {
104 }
105 }
106}
107
109{
110 LOG_TRACE("{}: called", nameId());
112 {
114 LOG_DATA("{}: PressToHgt - Local gravity magnitude: {} m/s² at initial position: {} [deg, deg, m]", nameId(), _gravity, _initPos.transpose());
115 }
117 return true;
118}
119
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
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
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
192}
Barometric Height Storage Class.
Barometric Pressure Storage Class.
Combo representing an enumeration.
Save/Load the Nodes.
nlohmann::json json
json namespace
Different Gravity Models.
Text Help Marker (?) with Tooltip.
Utility class for logging to console and file.
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
Definition Logger.hpp:29
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Definition Logger.hpp:65
Manages all Nodes.
Pressure to height converter.
static std::string type()
Returns the type of the data class.
Definition BaroHgt.hpp:28
static std::string type()
Returns the type of the data class.
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
static constexpr double Rg
Universal gas constant in [J/K/mol].
static constexpr double dMtr
Molar mass of dry air in [kg/mol].
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:410
Node(std::string name)
Constructor.
Definition Node.cpp:30
std::string nameId() const
Node name and id.
Definition Node.cpp:253
std::string name
Name of the Node.
Definition Node.hpp:395
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
Definition Node.cpp:180
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:413
void deinitialize() override
Deinitialize the node.
bool initialize() override
Initialize the node.
double _temp0
Temperature at Sea level in deg K.
double _geoidhgt
Geoid undulation in m.
void guiConfig() override
ImGui config window which is shown on double click.
double _lapserate
Temperature lapse rate in K / m.
std::string type() const override
String representation of the Class Type.
~PressToHgt() override
Destructor.
static constexpr size_t OUTPUT_PORT_INDEX_BAROHEIGHT
Flow.
@ Position
Entry of the position, gravity is then deducted from EGM96.
@ Manual
Manual entry of the gravity's magnitude.
void restore(const json &j) override
Restores the node from a json object.
static std::string category()
String representation of the Class Category.
double _gravity
Gravity in m / s²
static std::string typeStatic()
String representation of the Class Type.
GravityInput _gravityInput
Default gravity input type.
double _exponent
save computations, by storing g * M / R0 / L;
PressToHgt()
Default constructor.
double _pressure0
Pressure at Sea level in hPa.
Eigen::Vector3d _initPos
Initial position in LLA [deg, deg, m] for the calculation of the local gravity through EGM96.
void receiveObs(InputPin::NodeDataQueue &queue, size_t pinIdx)
Converts the RtklibPosObs into PosVel.
json save() const override
Saves the node into a json object.
auto extract_front()
Returns a copy of the first element in the container and removes it from the container.
Definition TsDeque.hpp:494
static float windowFontRatio()
Ratio to multiply for GUI window elements.
ImGui extensions.
bool InputDouble3(const char *label, double v[3], const char *format, ImGuiInputTextFlags flags)
Shows an InputText GUI element for an array of 'double[3]'.
Definition imgui_ex.cpp:178
OutputPin * CreateOutputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier, OutputPin::PinData data=static_cast< void * >(nullptr), int idx=-1)
Create an Output Pin object.
InputPin * CreateInputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier={}, InputPin::Callback callback=static_cast< InputPin::FlowFirableCallbackFunc >(nullptr), InputPin::FlowFirableCheckFunc firable=nullptr, int priority=0, int idx=-1)
Create an Input Pin object.
void ApplyChanges()
Signals that there have been changes to the flow.
bool EnumCombo(const char *label, T &enumeration, size_t startIdx=0)
Combo representing an enumeration.
Definition EnumCombo.hpp:30
void HelpMarker(const char *desc, const char *symbol="(?)")
Text Help Marker, e.g. '(?)', with Tooltip.
Eigen::Vector3< typename Derived::Scalar > n_calcGravitation_EGM96(const Eigen::MatrixBase< Derived > &lla_position, size_t ndegree=10)
Calculates the gravitation (acceleration due to mass attraction of the Earth) at the WGS84 reference ...
Definition Gravity.hpp:128
@ Flow
NodeData Trigger.
Definition Pin.hpp:52