0.4.1
Loading...
Searching...
No Matches
SinglePointPositioning.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
10#include <imgui.h>
11
15#include <fmt/core.h>
16namespace nm = NAV::NodeManager;
20
22
26
27#include "util/Logger.hpp"
29
43
48
50{
51 return "SinglePointPositioning - SPP";
52}
53
55{
56 return typeStatic();
57}
58
60{
61 return "Data Processor";
62}
63
65{
66 auto nSatColumnContent = [&](size_t pinIndex) -> bool {
67 if (auto gnssNavInfo = getInputValue<GnssNavInfo>(pinIndex))
68 {
69 size_t usedSatNum = 0;
70 std::string usedSats;
71 std::string allSats;
72
73 std::string filler = ", ";
74 for (const auto& satellite : gnssNavInfo->v->satellites())
75 {
76 if (_algorithm._obsFilter.isSatelliteAllowed(satellite.first))
77 {
78 usedSatNum++;
79 usedSats += (allSats.empty() ? "" : filler) + fmt::format("{}", satellite.first);
80 }
81 allSats += (allSats.empty() ? "" : filler) + fmt::format("{}", satellite.first);
82 }
83 ImGui::TextUnformatted(fmt::format("{} / {}", usedSatNum, gnssNavInfo->v->nSatellites()).c_str());
84 if (ImGui::IsItemHovered())
85 {
86 ImGui::SetTooltip("Used satellites: %s\n"
87 "Avail satellites: %s",
88 usedSats.c_str(), allSats.c_str());
89 }
90 }
91 return false;
92 };
93
94 if (_dynamicInputPins.ShowGuiWidgets(size_t(id), inputPins, this, { { .header = "# Sat", .content = nSatColumnContent } }))
95 {
97 }
98
99 ImGui::Separator();
100
101 // ###########################################################################################################
102
103 const float itemWidth = 280.0F * gui::NodeEditorApplication::windowFontRatio();
104 const float unitWidth = 100.0F * gui::NodeEditorApplication::windowFontRatio();
105
106 if (_algorithm.ShowGuiWidgets(nameId().c_str(), itemWidth, unitWidth))
107 {
109 }
110}
111
113{
114 LOG_TRACE("{}: called", nameId());
115
116 return {
117 { "dynamicInputPins", _dynamicInputPins },
118 { "algorithm", _algorithm },
119 };
120}
121
123{
124 LOG_TRACE("{}: called", nameId());
125
126 if (j.contains("dynamicInputPins")) { NAV::gui::widgets::from_json(j.at("dynamicInputPins"), _dynamicInputPins, this); }
127 if (j.contains("algorithm")) { j.at("algorithm").get_to(_algorithm); }
128}
129
131{
132 LOG_TRACE("{}: called", nameId());
133
134 if (std::all_of(inputPins.begin() + INPUT_PORT_INDEX_GNSS_NAV_INFO, inputPins.end(), [](const InputPin& inputPin) { return !inputPin.isPinLinked(); }))
135 {
136 LOG_ERROR("{}: You need to connect a GNSS NavigationInfo provider", nameId());
137 return false;
138 }
139
140 _algorithm.reset();
141
142 LOG_DEBUG("{}: initialized", nameId());
143
144 return true;
145}
146
148{
149 LOG_TRACE("{}: called", nameId());
150}
151
156
158{
159 nm::DeleteInputPin(node->inputPins.at(pinIdx));
160}
161
163{
164 // Collection of all connected navigation data providers
165 std::vector<InputPin::IncomingLink::ValueWrapper<GnssNavInfo>> gnssNavInfoWrappers;
166 std::vector<const GnssNavInfo*> gnssNavInfos;
167 for (size_t i = 0; i < _dynamicInputPins.getNumberOfDynamicPins(); i++)
168 {
170 {
171 gnssNavInfoWrappers.push_back(*gnssNavInfo);
172 gnssNavInfos.push_back(gnssNavInfo->v);
173 }
174 }
175 if (gnssNavInfos.empty()) { return; }
176
177 auto gnssObs = std::static_pointer_cast<const GnssObs>(queue.extract_front());
178 LOG_DATA("{}: [{}] Calculating SPP", nameId(), gnssObs->insTime.toYMDHMS(GPST));
179
180 if (auto sppSol = _algorithm.calcSppSolution(gnssObs, gnssNavInfos, nameId()))
181 {
183 }
184}
Single Point Positioning Algorithm.
Holds all Constants.
Save/Load the Nodes.
nlohmann::json json
json namespace
Navigation message information.
GNSS Observation messages.
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_ERROR
Error occurred, which stops part of the program to work, but not everything.
Definition Logger.hpp:73
#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 and Velocity Storage Class.
Single Point Positioning (SPP) / Code Phase Positioning.
SPP Algorithm output.
Vector Utility functions.
static std::string type()
Returns the type of the data class.
static std::string type()
Returns the type of the data class.
Definition GnssObs.hpp:150
Input pins of nodes.
Definition Pin.hpp:491
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:410
Node(std::string name)
Constructor.
Definition Node.cpp:30
std::optional< InputPin::IncomingLink::ValueWrapper< T > > getInputValue(size_t portIndex) const
Get Input Value connected on the pin. Only const data types.
Definition Node.hpp:290
std::vector< InputPin > inputPins
List of input pins.
Definition Node.hpp:397
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 void pinAddCallback(Node *node)
Function to call to add a new pin.
std::string type() const override
String representation of the Class Type.
void recvGnssObs(InputPin::NodeDataQueue &queue, size_t pinIdx)
Receive Function for the Gnss Observations.
static constexpr size_t OUTPUT_PORT_INDEX_SPPSOL
Flow (SppSol)
static std::string typeStatic()
String representation of the Class Type.
static void pinDeleteCallback(Node *node, size_t pinIdx)
Function to call to delete a pin.
static std::string category()
String representation of the Class Category.
SinglePointPositioning()
Default constructor.
void deinitialize() override
Deinitialize the node.
gui::widgets::DynamicInputPins _dynamicInputPins
Dynamic input pins.
~SinglePointPositioning() override
Destructor.
void restore(const json &j) override
Restores the node from a json object.
SPP::Algorithm _algorithm
SPP algorithm.
bool initialize() override
Initialize the node.
json save() const override
Saves the node into a json object.
static constexpr size_t INPUT_PORT_INDEX_GNSS_NAV_INFO
GnssNavInfo.
void guiConfig() override
ImGui config window which is shown on double click.
static std::string type()
Returns the type of the data class.
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.
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.
bool DeleteInputPin(InputPin &pin)
Deletes the input pin. Invalidates the pin reference given.
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.
void from_json(const json &j, DynamicInputPins &obj, Node *node)
Converts the provided json object into a node object.
@ GPST
GPS Time.
@ Flow
NodeData Trigger.
Definition Pin.hpp:52
@ Object
Generic Object.
Definition Pin.hpp:57