0.4.1
Loading...
Searching...
No Matches
BaroSimulator.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 "BaroSimulator.hpp"
10
11#include <limits>
12
13#include "util/Logger.hpp"
14
16namespace nm = NAV::NodeManager;
18
21
23
28
30 : Node(typeStatic())
31{
32 LOG_TRACE("{}: called", name);
33 _hasConfig = true;
34 _guiConfigDefaultWindowSize = { 710, 220 };
35
36 std::mt19937_64 gen(static_cast<uint64_t>(std::chrono::system_clock::now().time_since_epoch().count()));
37 std::uniform_int_distribution<uint64_t> dist(0, std::numeric_limits<uint64_t>::max() / 2);
38 _pressureRng.seed = dist(gen);
39
41
43}
44
49
51{
52 return "BaroSimulator";
53}
54
55std::string NAV::BaroSimulator::type() const
56{
57 return typeStatic();
58}
59
61{
62 return "Data Simulator";
63}
64
66{
67 float columnWidth = 140.0F * gui::NodeEditorApplication::windowFontRatio();
68
69 if (ImGui::InputDouble(fmt::format("Sea-level pressure##{}", size_t(id)).c_str(), &_pressure0, 0.0, 0.0, "%.3f hPa"))
70 {
71 LOG_DATA("{}: pressure0 changed to {}", nameId(), _pressure0);
73 }
74 if (ImGui::InputDouble(fmt::format("Sea-level temperature##{}", size_t(id)).c_str(), &_temp0, 0.0, 0.0, "%.3f K"))
75 {
76 LOG_DATA("{}: temo0 changed to {}", nameId(), _temp0);
78 }
79 if (ImGui::InputDouble(fmt::format("Temperature lapse rate##{}", size_t(id)).c_str(), &_lapserate, 0.0, 0.0, "%.6f K / m"))
80 {
81 LOG_DATA("{}: lapserate changed to {}", nameId(), _lapserate);
83 }
84 if (ImGui::InputDouble(fmt::format("Geoid undulation##{}", size_t(id)).c_str(), &_geoidhgt, 0.0, 0.0, "%.3f m"))
85 {
86 LOG_DATA("{}: geoidhgt changed to {}", nameId(), _geoidhgt);
88 }
89 ImGui::SetNextItemWidth(columnWidth);
90 if (gui::widgets::EnumCombo(fmt::format("Gravity input##{}", size_t(id)).c_str(), _gravityInput))
91 {
92 LOG_DATA("{}: gravity input changed to {}", nameId(), fmt::underlying(_gravityInput));
94 }
95 ImGui::SameLine();
96 gui::widgets::HelpMarker("The 'position' input calculates the gravity magnitude from EGM96.\n\n");
98 {
99 if (ImGui::InputDouble(fmt::format("Gravity##{}", size_t(id)).c_str(), &_gravity, 0.0, 0.0, "%.5f m / s²"))
100 {
101 LOG_DATA("{}: gravity changed to {}", nameId(), _gravity);
103 }
104 }
105 else // (_gravityInput == GravityInput::position)
106 {
107 if (ImGui::InputDouble3(fmt::format("Position LLA [deg, deg, m]##{}", size_t(id)).c_str(), _initPos.data()))
108 {
110 }
111 }
112 if (ImGui::InputDouble(fmt::format("Std. Dev. of Pressure noise##{}", size_t(id)).c_str(), &_pressurenoise, 0.0, 0.0, "%.3f hPa"))
113 {
114 LOG_DEBUG("{}: pressurenoise changed to {}", nameId(), _pressurenoise);
116 }
117 float itemWidth = 470 * gui::NodeEditorApplication::windowFontRatio();
118 auto rngInput = [&](const char* title, RandomNumberGenerator& rng) {
119 float currentCursorX = ImGui::GetCursorPosX();
120 if (ImGui::Checkbox(fmt::format("##rng.useSeed {} {}", title, size_t(id)).c_str(), &rng.useSeed))
121 {
122 LOG_DEBUG("{}: {} rng.useSeed changed to {}", nameId(), title, rng.useSeed);
124 }
125 if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Use seed?"); }
126 ImGui::SameLine();
127 if (!rng.useSeed)
128 {
129 ImGui::BeginDisabled();
130 }
131 ImGui::SetNextItemWidth(itemWidth - (ImGui::GetCursorPosX() - currentCursorX));
132 if (ImGui::SliderULong(fmt::format("{} Seed##{}", title, size_t(id)).c_str(), &rng.seed, 0, std::numeric_limits<uint64_t>::max() / 2, "%lu"))
133 {
134 LOG_DEBUG("{}: {} rng.seed changed to {}", nameId(), title, rng.seed);
136 }
137 if (!rng.useSeed)
138 {
139 ImGui::EndDisabled();
140 }
141 };
142 rngInput("Pressure Noise seed", _pressureRng);
143}
144
146{
147 LOG_TRACE("{}: called", nameId());
149 {
151 LOG_DATA("{}: PressToHgt - Local gravity magnitude: {} m/s² at initial position: {} [deg, deg, m]", nameId(), _gravity, _initPos.transpose());
152 }
154 _pressureRng.resetSeed();
155 return true;
156}
157
159{
160 LOG_TRACE("{}: called", nameId());
161}
162
163[[nodiscard]] json NAV::BaroSimulator::save() const
164{
165 LOG_TRACE("{}: called", nameId());
166
167 json j;
168
169 j["temp0"] = _temp0;
170 j["pressure0"] = _pressure0;
171 j["lapserate"] = _lapserate;
172 j["geoidhgt"] = _geoidhgt;
173 j["gravity"] = _gravity;
174 j["initPos"] = _initPos;
175 j["gravityInput"] = _gravityInput;
176 j["pressurenoise"] = _pressurenoise;
177 j["pressureRng"] = _pressureRng;
178 return j;
179}
180
182{
183 LOG_TRACE("{}: called", nameId());
184
185 if (j.contains("temp0"))
186 {
187 j.at("temp0").get_to(_temp0);
188 }
189 if (j.contains("pressure0"))
190 {
191 j.at("pressure0").get_to(_pressure0);
192 }
193 if (j.contains("lapserate"))
194 {
195 j.at("lapserate").get_to(_lapserate);
196 }
197 if (j.contains("geoidhgt"))
198 {
199 j.at("geoidhgt").get_to(_geoidhgt);
200 }
201 if (j.contains("gravity"))
202 {
203 j.at("gravity").get_to(_gravity);
204 }
205 if (j.contains("initPos"))
206 {
207 j.at("initPos").get_to(_initPos);
208 }
209 if (j.contains("gravityInput"))
210 {
211 j.at("gravityInput").get_to(_gravityInput);
212 }
213 if (j.contains("pressurenoise"))
214 {
215 j.at("pressurenoise").get_to(_pressurenoise);
216 }
217 if (j.contains("pressureRng"))
218 {
219 j.at("pressureRng").get_to(_pressureRng);
220 }
221}
222
224{
225 auto PosObs = std::static_pointer_cast<const Pos>(queue.extract_front());
226
227 auto pressureObs = std::make_shared<BaroPressObs>();
228
229 pressureObs->insTime = PosObs->insTime;
230
231 pressureObs->baro_pressure = _pressure0 * std::pow(1 - _lapserate * (PosObs->altitude() - _geoidhgt) / _temp0, _exponent) + _pressureRng.getRand_normalDist(0.0, _pressurenoise);
232
233 pressureObs->baro_pressureStdev = _pressurenoise;
234
236}
Barometric Pressure Storage Class.
Barometer observation simulator.
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_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
Definition Logger.hpp:67
#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.
Position Storage Class.
static std::string type()
Returns the type of the data class.
static constexpr size_t OUTPUT_PORT_INDEX_BAROPRESSURE
Flow.
double _pressurenoise
pressure noise in hPa
json save() const override
Saves the node into a json object.
double _gravity
Gravity in m / s²
static std::string typeStatic()
String representation of the Class Type.
void receiveObs(InputPin::NodeDataQueue &queue, size_t pinIdx)
Converts the RtklibPosObs into PosVel.
~BaroSimulator() override
Destructor.
double _pressure0
Pressure at Sea level in hPa.
RandomNumberGenerator _pressureRng
Random number generator for the pressure noise.
double _temp0
Temperature at Sea level in deg K.
void guiConfig() override
ImGui config window which is shown on double click.
static std::string category()
String representation of the Class Category.
BaroSimulator()
Default constructor.
Eigen::Vector3d _initPos
Initial position in LLA [deg, deg, m] for the calculation of the local gravity through EGM96.
void deinitialize() override
Deinitialize the node.
double _lapserate
Temperature lapse rate in K / m.
bool initialize() override
Initialize the node.
GravityInput _gravityInput
Default gravity input type.
@ Position
Entry of the position, gravity is then deducted from EGM96.
@ Manual
Manual entry of the gravity's magnitude.
double _geoidhgt
Geoid undulation in m.
void restore(const json &j) override
Restores the node from a json object.
double _exponent
save computations, by storing g * M / R0 / L;
std::string type() const override
String representation of the Class Type.
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
static std::string type()
Returns the type of the data class.
Definition Pos.hpp:36
Manages a thread which calls a specified function at a specified interval.
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 SliderULong(const char *label, uint64_t *v, uint64_t v_min, uint64_t v_max, const char *format, ImGuiSliderFlags flags)
Shows a Slider GUI element for 'uint64'.
Definition imgui_ex.cpp:129
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