0.5.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
14
17
19
24
36
38{
39 LOG_TRACE("{}: called", nameId());
40}
41
43{
44 return "PressToHgt";
45}
46
47std::string NAV::PressToHgt::type() const
48{
49 return typeStatic();
50}
51
53{
54 return "Data Processor";
55}
56
58{
59 float columnWidth = 140.0F * gui::NodeEditorApplication::windowFontRatio();
60
61 if (ImGui::InputDouble(fmt::format("Sea-level pressure##{}", size_t(id)).c_str(), &_pressure0, 0.0, 0.0, "%.3f hPa"))
62 {
63 LOG_DATA("{}: pressure0 changed to {}", nameId(), _pressure0);
65 }
66 if (ImGui::InputDouble(fmt::format("Sea-level temperature##{}", size_t(id)).c_str(), &_temp0, 0.0, 0.0, "%.3f K"))
67 {
68 LOG_DATA("{}: temp0 changed to {}", nameId(), _temp0);
70 }
71 if (ImGui::InputDouble(fmt::format("Temperature lapse rate##{}", size_t(id)).c_str(), &_lapserate, 0.0, 0.0, "%.6f K / m"))
72 {
73 LOG_DATA("{}: lapserate changed to {}", nameId(), _lapserate);
75 }
76 if (ImGui::InputDouble(fmt::format("Geoid undulation##{}", size_t(id)).c_str(), &_geoidhgt, 0.0, 0.0, "%.3f m"))
77 {
78 LOG_DATA("{}: geoidhgt changed to {}", nameId(), _geoidhgt);
80 }
81 ImGui::SetNextItemWidth(columnWidth);
82 if (gui::widgets::EnumCombo(fmt::format("Gravity input##{}", size_t(id)).c_str(), _gravityInput))
83 {
84 LOG_DATA("{}: gravity input changed to {}", nameId(), fmt::underlying(_gravityInput));
86 }
87 ImGui::SameLine();
88 gui::widgets::HelpMarker("The 'position' input calculates the gravity magnitude from EGM96.\n\n");
90 {
91 if (ImGui::InputDouble(fmt::format("Gravity##{}", size_t(id)).c_str(), &_gravity, 0.0, 0.0, "%.5f m / s²"))
92 {
93 LOG_DATA("{}: gravity changed to {}", nameId(), _gravity);
95 }
96 }
97 else // (_gravityInput == GravityInput::Position)
98 {
99 if (ImGui::InputDouble3(fmt::format("Position LLA [deg, deg, m]##{}", size_t(id)).c_str(), _initPos.data()))
100 {
102 }
103 }
104}
105
107{
108 LOG_TRACE("{}: called", nameId());
110 {
112 LOG_DATA("{}: PressToHgt - Local gravity magnitude: {} m/s² at initial position: {} [deg, deg, m]", nameId(), _gravity, _initPos.transpose());
113 }
115 return true;
116}
117
119{
120 LOG_TRACE("{}: called", nameId());
121}
122
123[[nodiscard]] json NAV::PressToHgt::save() const
124{
125 LOG_TRACE("{}: called", nameId());
126
127 json j;
128
129 j["temp0"] = _temp0;
130 j["pressure0"] = _pressure0;
131 j["lapserate"] = _lapserate;
132 j["geoidhgt"] = _geoidhgt;
133 j["gravity"] = _gravity;
134 j["initPos"] = _initPos;
135 j["gravityInput"] = _gravityInput;
136 return j;
137}
138
140{
141 LOG_TRACE("{}: called", nameId());
142
143 if (j.contains("temp0"))
144 {
145 j.at("temp0").get_to(_temp0);
146 }
147 if (j.contains("pressure0"))
148 {
149 j.at("pressure0").get_to(_pressure0);
150 }
151 if (j.contains("lapserate"))
152 {
153 j.at("lapserate").get_to(_lapserate);
154 }
155 if (j.contains("geoidhgt"))
156 {
157 j.at("geoidhgt").get_to(_geoidhgt);
158 }
159 if (j.contains("gravity"))
160 {
161 j.at("gravity").get_to(_gravity);
162 }
163 if (j.contains("initPos"))
164 {
165 j.at("initPos").get_to(_initPos);
166 }
167 if (j.contains("gravityInput"))
168 {
169 j.at("gravityInput").get_to(_gravityInput);
170 }
171}
172
174{
175 auto pressureObs = std::static_pointer_cast<const BaroPressObs>(queue.extract_front());
176
177 auto baroheight = std::make_shared<BaroHgt>();
178
179 baroheight->insTime = pressureObs->insTime;
180
181 baroheight->baro_height = _temp0 / _lapserate * (1.0 - std::pow(pressureObs->baro_pressure / _pressure0, 1.0 / _exponent)) + _geoidhgt;
182
183 // if uncertainty of pressure value is provided carry out error propagation for barometric height (assuming all other parameters are error free)
184 if (pressureObs->baro_pressureStdev.has_value())
185 {
186 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();
187 }
188
190}
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
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:522
Node(std::string name)
Constructor.
Definition Node.cpp:29
OutputPin * CreateOutputPin(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.
Definition Node.cpp:278
std::string nameId() const
Node name and id.
Definition Node.cpp:323
std::string name
Name of the Node.
Definition Node.hpp:507
InputPin * CreateInputPin(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.
Definition Node.cpp:252
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
Definition Node.cpp:179
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:525
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
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:137
@ Flow
NodeData Trigger.
Definition Pin.hpp:52