0.5.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
16
19
21
26
28 : Node(typeStatic())
29{
30 LOG_TRACE("{}: called", name);
31 _hasConfig = true;
32 _guiConfigDefaultWindowSize = { 710, 220 };
33
34 std::mt19937_64 gen(static_cast<uint64_t>(std::chrono::system_clock::now().time_since_epoch().count()));
35 std::uniform_int_distribution<uint64_t> dist(0, std::numeric_limits<uint64_t>::max() / 2);
36 _pressureRng.seed = dist(gen);
37
39
41}
42
47
49{
50 return "BaroSimulator";
51}
52
53std::string NAV::BaroSimulator::type() const
54{
55 return typeStatic();
56}
57
59{
60 return "Data Simulator";
61}
62
64{
65 float columnWidth = 140.0F * gui::NodeEditorApplication::windowFontRatio();
66
67 if (ImGui::InputDouble(fmt::format("Sea-level pressure##{}", size_t(id)).c_str(), &_pressure0, 0.0, 0.0, "%.3f hPa"))
68 {
69 LOG_DATA("{}: pressure0 changed to {}", nameId(), _pressure0);
71 }
72 if (ImGui::InputDouble(fmt::format("Sea-level temperature##{}", size_t(id)).c_str(), &_temp0, 0.0, 0.0, "%.3f K"))
73 {
74 LOG_DATA("{}: temo0 changed to {}", nameId(), _temp0);
76 }
77 if (ImGui::InputDouble(fmt::format("Temperature lapse rate##{}", size_t(id)).c_str(), &_lapserate, 0.0, 0.0, "%.6f K / m"))
78 {
79 LOG_DATA("{}: lapserate changed to {}", nameId(), _lapserate);
81 }
82 if (ImGui::InputDouble(fmt::format("Geoid undulation##{}", size_t(id)).c_str(), &_geoidhgt, 0.0, 0.0, "%.3f m"))
83 {
84 LOG_DATA("{}: geoidhgt changed to {}", nameId(), _geoidhgt);
86 }
87 ImGui::SetNextItemWidth(columnWidth);
88 if (gui::widgets::EnumCombo(fmt::format("Gravity input##{}", size_t(id)).c_str(), _gravityInput))
89 {
90 LOG_DATA("{}: gravity input changed to {}", nameId(), fmt::underlying(_gravityInput));
92 }
93 ImGui::SameLine();
94 gui::widgets::HelpMarker("The 'position' input calculates the gravity magnitude from EGM96.\n\n");
96 {
97 if (ImGui::InputDouble(fmt::format("Gravity##{}", size_t(id)).c_str(), &_gravity, 0.0, 0.0, "%.5f m / s²"))
98 {
99 LOG_DATA("{}: gravity changed to {}", nameId(), _gravity);
101 }
102 }
103 else // (_gravityInput == GravityInput::position)
104 {
105 if (ImGui::InputDouble3(fmt::format("Position LLA [deg, deg, m]##{}", size_t(id)).c_str(), _initPos.data()))
106 {
108 }
109 }
110 if (ImGui::InputDouble(fmt::format("Std. Dev. of Pressure noise##{}", size_t(id)).c_str(), &_pressurenoise, 0.0, 0.0, "%.3f hPa"))
111 {
112 LOG_DEBUG("{}: pressurenoise changed to {}", nameId(), _pressurenoise);
114 }
115 float itemWidth = 470 * gui::NodeEditorApplication::windowFontRatio();
116 auto rngInput = [&](const char* title, RandomNumberGenerator& rng) {
117 float currentCursorX = ImGui::GetCursorPosX();
118 if (ImGui::Checkbox(fmt::format("##rng.useSeed {} {}", title, size_t(id)).c_str(), &rng.useSeed))
119 {
120 LOG_DEBUG("{}: {} rng.useSeed changed to {}", nameId(), title, rng.useSeed);
122 }
123 if (ImGui::IsItemHovered()) { ImGui::SetTooltip("Use seed?"); }
124 ImGui::SameLine();
125 if (!rng.useSeed)
126 {
127 ImGui::BeginDisabled();
128 }
129 ImGui::SetNextItemWidth(itemWidth - (ImGui::GetCursorPosX() - currentCursorX));
130 if (ImGui::SliderULong(fmt::format("{} Seed##{}", title, size_t(id)).c_str(), &rng.seed, 0, std::numeric_limits<uint64_t>::max() / 2, "%lu"))
131 {
132 LOG_DEBUG("{}: {} rng.seed changed to {}", nameId(), title, rng.seed);
134 }
135 if (!rng.useSeed)
136 {
137 ImGui::EndDisabled();
138 }
139 };
140 rngInput("Pressure Noise seed", _pressureRng);
141}
142
144{
145 LOG_TRACE("{}: called", nameId());
147 {
149 LOG_DATA("{}: PressToHgt - Local gravity magnitude: {} m/s² at initial position: {} [deg, deg, m]", nameId(), _gravity, _initPos.transpose());
150 }
152 _pressureRng.resetSeed();
153 return true;
154}
155
157{
158 LOG_TRACE("{}: called", nameId());
159}
160
161[[nodiscard]] json NAV::BaroSimulator::save() const
162{
163 LOG_TRACE("{}: called", nameId());
164
165 json j;
166
167 j["temp0"] = _temp0;
168 j["pressure0"] = _pressure0;
169 j["lapserate"] = _lapserate;
170 j["geoidhgt"] = _geoidhgt;
171 j["gravity"] = _gravity;
172 j["initPos"] = _initPos;
173 j["gravityInput"] = _gravityInput;
174 j["pressurenoise"] = _pressurenoise;
175 j["pressureRng"] = _pressureRng;
176 return j;
177}
178
180{
181 LOG_TRACE("{}: called", nameId());
182
183 if (j.contains("temp0"))
184 {
185 j.at("temp0").get_to(_temp0);
186 }
187 if (j.contains("pressure0"))
188 {
189 j.at("pressure0").get_to(_pressure0);
190 }
191 if (j.contains("lapserate"))
192 {
193 j.at("lapserate").get_to(_lapserate);
194 }
195 if (j.contains("geoidhgt"))
196 {
197 j.at("geoidhgt").get_to(_geoidhgt);
198 }
199 if (j.contains("gravity"))
200 {
201 j.at("gravity").get_to(_gravity);
202 }
203 if (j.contains("initPos"))
204 {
205 j.at("initPos").get_to(_initPos);
206 }
207 if (j.contains("gravityInput"))
208 {
209 j.at("gravityInput").get_to(_gravityInput);
210 }
211 if (j.contains("pressurenoise"))
212 {
213 j.at("pressurenoise").get_to(_pressurenoise);
214 }
215 if (j.contains("pressureRng"))
216 {
217 j.at("pressureRng").get_to(_pressureRng);
218 }
219}
220
222{
223 auto PosObs = std::static_pointer_cast<const Pos>(queue.extract_front());
224
225 auto pressureObs = std::make_shared<BaroPressObs>();
226
227 pressureObs->insTime = PosObs->insTime;
228
229 pressureObs->baro_pressure = _pressure0 * std::pow(1 - _lapserate * (PosObs->altitude() - _geoidhgt) / _temp0, _exponent) + _pressureRng.getRand_normalDist(0.0, _pressurenoise);
230
231 pressureObs->baro_pressureStdev = _pressurenoise;
232
234}
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
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: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
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
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