0.2.0
Loading...
Searching...
No Matches
Combiner.hpp
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
13
14#pragma once
15
16#include <unordered_set>
17#include <map>
18
21
23
36
40
41namespace NAV
42{
44class Combiner : public Node, public CommonLog
45{
46 public:
50 ~Combiner() override;
52 Combiner(const Combiner&) = delete;
54 Combiner(Combiner&&) = delete;
56 Combiner& operator=(const Combiner&) = delete;
59
61 [[nodiscard]] static std::string typeStatic();
62
64 [[nodiscard]] std::string type() const override;
65
67 [[nodiscard]] static std::string category();
68
71 void guiConfig() override;
72
74 [[nodiscard]] json save() const override;
75
78 void restore(const json& j) override;
79
80 private:
81 constexpr static size_t OUTPUT_PORT_INDEX_DYN_DATA = 0;
82
84 static inline std::vector<std::string> _dataIdentifier = { Pos::type(),
98
100 struct Combination
101 {
103 struct Term
104 {
105 double factor = 1.0;
106 size_t pinIndex = 0;
107 std::variant<size_t, std::string> dataSelection = size_t(0);
108
111
115 [[nodiscard]] std::string description(const Combiner* node, const std::vector<std::string>& descriptors) const
116 {
117 if (std::holds_alternative<size_t>(dataSelection) && std::get<size_t>(dataSelection) < descriptors.size())
118 {
119 return fmt::format("{} {} ({})", factor == 1.0 ? "+" : (factor == -1.0 ? "-" : fmt::format("{:.2f}", factor)),
120 descriptors.at(std::get<size_t>(dataSelection)), node->inputPins.at(pinIndex).name);
121 }
122 if (std::holds_alternative<std::string>(dataSelection))
123 {
124 return fmt::format("{} {} ({})", factor == 1.0 ? "+" : (factor == -1.0 ? "-" : fmt::format("{:.2f}", factor)),
125 std::get<std::string>(dataSelection), node->inputPins.at(pinIndex).name);
126 }
127 return fmt::format("N/A ({})", node->inputPins.at(pinIndex).name);
128 }
129 };
130
132 std::vector<Term> terms{ Term{ .factor = +1.0, .pinIndex = 0 },
133 Term{ .factor = -1.0, .pinIndex = 1 } };
134
137 [[nodiscard]] std::string description(const Combiner* node) const
138 {
139 std::string desc;
140 for (const auto& term : terms)
141 {
142 auto descriptors = node->getDataDescriptors(term.pinIndex);
143 auto termDescription = term.description(node, descriptors);
144
145 if (!desc.empty())
146 {
147 if (termDescription.starts_with("+ ") || termDescription.starts_with("- "))
148 {
149 desc += " ";
150 }
151 else
152 {
153 desc += " + ";
154 }
155 }
156 desc += termDescription;
157 }
158
159 return desc;
160 }
161 };
162
164 std::vector<Combination> _combinations{ Combination() };
165
167 struct PinData
168 {
170 std::vector<std::string> dynDataDescriptors;
171 };
172
174 std::vector<PinData> _pinData;
175
177 struct SendRequest
178 {
179 size_t combIndex = 0;
180 std::unordered_set<size_t> termIndices;
181 double result = 0.0;
182 std::vector<std::string> events;
183 };
184
186 std::map<InsTime, std::vector<SendRequest>> _sendRequests;
187
190 static void pinAddCallback(Node* node);
194 static void pinDeleteCallback(Node* node, size_t pinIdx);
195
198 gui::widgets::DynamicInputPins _dynamicInputPins{ 0, this, pinAddCallback, pinDeleteCallback };
199
201 bool initialize() override;
202
204 void deinitialize() override;
205
208 [[nodiscard]] std::vector<std::string> getDataDescriptors(size_t pinIndex) const;
209
212 [[nodiscard]] bool isLastObsThisEpoch(const InsTime& insTime) const;
213
217 void receiveData(InputPin::NodeDataQueue& queue, size_t pinIdx);
218
222 friend void to_json(json& j, const Combination& data);
226 friend void from_json(const json& j, Combination& data);
230 friend void to_json(json& j, const Combination::Term& data);
234 friend void from_json(const json& j, Combination::Term& data);
235};
236
237} // namespace NAV
Common logging variables like time into run and local positions.
Inputs pins which can be added dynamically.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
GNSS measurement combinations.
GNSS Observation messages.
Data storage class for simulated IMU observations.
Data storage class for one VectorNavImu observation.
Parent Class for all IMU Observations.
Loosely-coupled Kalman Filter INS/GNSS errors.
Tightly-coupled Kalman Filter INS/GNSS errors.
Data storage class for one KVH Imu observation.
Node Class.
Polynomial curve fitting.
Position, Velocity and Attitude Storage Class.
RTKLIB Pos Observation Class.
A buffer which is overwriting itself from the start when full.
SPP Algorithm output.
Unordered map wrapper.
Binary Outputs from VectorNav Sensors.
Calculates differences between signals.
Definition Combiner.hpp:45
Combiner & operator=(Combiner &&)=delete
Move assignment operator.
friend void from_json(const json &j, Combination::Term &data)
Read info from a json object.
friend void to_json(json &j, const Combination::Term &data)
Write info to a json object.
Combiner(const Combiner &)=delete
Copy constructor.
void guiConfig() override
ImGui config window which is shown on double click.
static std::string typeStatic()
String representation of the Class Type.
friend void from_json(const json &j, Combination &data)
Read info from a json object.
Combiner(Combiner &&)=delete
Move constructor.
static std::string category()
String representation of the Class Category.
std::string type() const override
String representation of the Class Type.
Combiner()
Default constructor.
void restore(const json &j) override
Restores the node from a json object.
friend void to_json(json &j, const Combination &data)
Write info to a json object.
~Combiner() override
Destructor.
Combiner & operator=(const Combiner &)=delete
Copy assignment operator.
json save() const override
Saves the node into a json object.
Common logging variables like time into run and local positions.
Definition CommonLog.hpp:26
static std::string type()
Returns the type of the data class.
Definition GnssCombination.hpp:32
static std::string type()
Returns the type of the data class.
Definition GnssObs.hpp:149
static std::string type()
Returns the type of the data class.
Definition ImuObsSimulated.hpp:31
static std::string type()
Returns the type of the data class.
Definition ImuObsWDelta.hpp:31
static std::string type()
Returns the type of the data class.
Definition ImuObs.hpp:34
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:703
static std::string type()
Returns the type of the data class.
Definition InsGnssLCKFSolution.hpp:29
static std::string type()
Returns the type of the data class.
Definition InsGnssTCKFSolution.hpp:26
static std::string type()
Returns the type of the data class.
Definition KvhObs.hpp:39
Abstract parent class for all nodes.
Definition Node.hpp:86
Node(std::string name)
Constructor.
std::vector< InputPin > inputPins
List of input pins.
Definition Node.hpp:380
Polynomial Curve Fitting.
Definition PolynomialRegressor.hpp:39
static std::string type()
Returns the type of the data class.
Definition PosVelAtt.hpp:29
static std::string type()
Returns the type of the data class.
Definition PosVel.hpp:27
static std::string type()
Returns the type of the data class.
Definition Pos.hpp:33
static std::string type()
Returns the type of the data class.
Definition RtklibPosObs.hpp:131
A buffer which is overwriting itself from the start when full.
Definition ScrollingBuffer.hpp:29
static std::string type()
Returns the type of the data class.
Definition SppSolution.hpp:38
static std::string type()
Returns the type of the data class.
Definition VectorNavBinaryOutput.hpp:41
Term of a combination equation.
Definition Combiner.hpp:104
double factor
Factor to multiply the term with.
Definition Combiner.hpp:105
ScrollingBuffer< std::vector< std::string > > events
Last events to add if we send.
Definition Combiner.hpp:110
std::string description(const Combiner *node, const std::vector< std::string > &descriptors) const
Get a string description of the combination.
Definition Combiner.hpp:115
size_t pinIndex
Pin Index.
Definition Combiner.hpp:106
std::variant< size_t, std::string > dataSelection
Data Index or Data identifier.
Definition Combiner.hpp:107
PolynomialRegressor< double > polyReg
Polynomial Regressor to interpolate data.
Definition Combiner.hpp:109