0.4.1
Loading...
Searching...
No Matches
GnssAnalyzer.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
9/// @file GnssAnalyzer.hpp
10/// @brief Allows creation of GNSS measurement combinations
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2023-10-17
13
14#pragma once
15
16#include <vector>
17
19
23
24namespace NAV
25{
26/// @brief Allows creation of GNSS measurement combinations
27class GnssAnalyzer : public Node
28{
29 public:
30 /// @brief Default constructor
32 /// @brief Destructor
33 ~GnssAnalyzer() override;
34 /// @brief Copy constructor
35 GnssAnalyzer(const GnssAnalyzer&) = delete;
36 /// @brief Move constructor
38 /// @brief Copy assignment operator
40 /// @brief Move assignment operator
42
43 /// @brief String representation of the Class Type
44 [[nodiscard]] static std::string typeStatic();
45
46 /// @brief String representation of the Class Type
47 [[nodiscard]] std::string type() const override;
48
49 /// @brief String representation of the Class Category
50 [[nodiscard]] static std::string category();
51
52 /// @brief ImGui config window which is shown on double click
53 /// @attention Don't forget to set _hasConfig to true in the constructor of the node
54 void guiConfig() override;
55
56 /// @brief Saves the node into a json object
57 [[nodiscard]] json save() const override;
58
59 /// @brief Restores the node from a json object
60 /// @param[in] j Json object with the node state
61 void restore(const json& j) override;
62
63 private:
64 constexpr static size_t INPUT_PORT_INDEX_GNSS_OBS = 0; ///< @brief Flow (GnssObs)
65 constexpr static size_t OUTPUT_PORT_INDEX_GNSS_COMBINATION = 0; ///< @brief Flow (GnssCombination)
66
67 /// Combination of GNSS measurements
69 {
70 /// Possible units to calculate the combination in
71 enum class Unit : uint8_t
72 {
73 Meters, ///< Meters
74 Cycles, ///< Cycles
75 };
76
77 /// Unit to calculate the combination in
79
80 /// Term of a combination equation
81 struct Term
82 {
83 /// @brief Observation types
84 enum class ObservationType : uint8_t
85 {
86 Pseudorange, ///< Pseudorange
87 Carrier, ///< Carrier-Phase
88 };
89
90 int sign = +1; ///< +1 or -1
91 SatSigId satSigId = { Code::G1C, 1 }; ///< SignalId and satellite number
92 int8_t freqNum = -128; ///< Frequency number. Only used for GLONASS G1 and G2 // TODO: Set this somewhere
94 bool receivedDuringRun = false; ///< Flag weather the signal was received
95 };
96 std::vector<Term> terms{ Term() }; ///< List of terms making up the combination
97
98 /// Cycle-slip detector
99 PolynomialCycleSlipDetector<std::string> polynomialCycleSlipDetector{ /* windowSize = */ 4, /* polyDegree = */ 2 };
100 /// Threshold to categorize a measurement as cycle slip [% of smallest wavelength]
102 /// Whether to output the prediction even when the window size is not reached
104 /// Whether the polynomials should be outputted
106 /// Polynomial collection
107 std::vector<std::pair<InsTime, Polynomial<double>>> polynomials;
108
109 /// @brief Get a string description of the combination
110 [[nodiscard]] std::string description() const
111 {
112 std::string desc;
113 for (const auto& term : terms)
114 {
115 if (!desc.empty()) { desc += " "; }
116 desc += term.sign == 1 ? "+" : "-";
117 desc += " ";
118 switch (term.obsType)
119 {
121 desc += unit == Unit::Cycles ? "P" : "p";
122 break;
124 desc += unit == Unit::Cycles ? "Φ" : "φ";
125 break;
126 }
127 desc += fmt::format("({})", term.satSigId);
128 }
129 if (unit == Unit::Cycles) { desc += " [cycles]"; }
130 else { desc += " [m]"; }
131
132 return desc;
133 }
134
135 /// @brief Calculates the combined frequency of all terms
136 [[nodiscard]] double calcCombinationFrequency() const
137 {
138 double combinedFreq = 0.0;
139 for (const auto& term : terms)
140 {
141 double freq = term.satSigId.freq().getFrequency(term.freqNum);
142 combinedFreq += static_cast<double>(term.sign) * freq;
143 }
144 return combinedFreq == 0 ? terms.front().satSigId.freq().getFrequency(terms.front().freqNum) : combinedFreq;
145 }
146 };
147
148 /// Combinations to calculate
149 std::vector<Combination> _combinations{ Combination() };
150
151 /// @brief Initialize the node
152 bool initialize() override;
153
154 /// @brief Deinitialize the node
155 void deinitialize() override;
156
157 /// @brief Receive Gnss observation
158 /// @param[in] queue Queue with all the received data messages
159 /// @param[in] pinIdx Index of the pin the data is received on
160 void receiveGnssObs(InputPin::NodeDataQueue& queue, size_t pinIdx);
161
162 /// @brief Write info to a json object
163 /// @param[out] j Json output
164 /// @param[in] data Object to read info from
165 friend void to_json(json& j, const Combination& data);
166 /// @brief Read info from a json object
167 /// @param[in] j Json variable to read info from
168 /// @param[out] data Output object
169 friend void from_json(const json& j, Combination& data);
170 /// @brief Write info to a json object
171 /// @param[out] j Json output
172 /// @param[in] data Object to read info from
173 friend void to_json(json& j, const Combination::Term& data);
174 /// @brief Read info from a json object
175 /// @param[in] j Json variable to read info from
176 /// @param[out] data Output object
177 friend void from_json(const json& j, Combination::Term& data);
178};
179
180} // namespace NAV
Combination of different cycle-slip detection algorithms.
nlohmann::json json
json namespace
Node Class.
Polynomial.
Structs identifying a unique satellite.
@ G1C
GPS L1 - C/A-code.
Definition Code.hpp:96
static std::string typeStatic()
String representation of the Class Type.
static std::string category()
String representation of the Class Category.
~GnssAnalyzer() override
Destructor.
std::vector< Combination > _combinations
Combinations to calculate.
GnssAnalyzer(GnssAnalyzer &&)=delete
Move constructor.
void receiveGnssObs(InputPin::NodeDataQueue &queue, size_t pinIdx)
Receive Gnss observation.
void deinitialize() override
Deinitialize the node.
void guiConfig() override
ImGui config window which is shown on double click.
void restore(const json &j) override
Restores the node from a json object.
static constexpr size_t OUTPUT_PORT_INDEX_GNSS_COMBINATION
Flow (GnssCombination)
static constexpr size_t INPUT_PORT_INDEX_GNSS_OBS
Flow (GnssObs)
std::string type() const override
String representation of the Class Type.
GnssAnalyzer()
Default constructor.
friend void from_json(const json &j, Combination &data)
Read info from a json object.
GnssAnalyzer(const GnssAnalyzer &)=delete
Copy constructor.
GnssAnalyzer & operator=(const GnssAnalyzer &)=delete
Copy assignment operator.
bool initialize() override
Initialize the node.
json save() const override
Saves the node into a json object.
friend void to_json(json &j, const Combination &data)
Write info to a json object.
GnssAnalyzer & operator=(GnssAnalyzer &&)=delete
Move assignment operator.
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
Node(std::string name)
Constructor.
Definition Node.cpp:30
Term of a combination equation.
int8_t freqNum
Frequency number. Only used for GLONASS G1 and G2 // TODO: Set this somewhere.
SatSigId satSigId
SignalId and satellite number.
ObservationType obsType
Observation Type.
bool receivedDuringRun
Flag weather the signal was received.
Combination of GNSS measurements.
PolynomialCycleSlipDetector< std::string > polynomialCycleSlipDetector
Cycle-slip detector.
std::string description() const
Get a string description of the combination.
double calcCombinationFrequency() const
Calculates the combined frequency of all terms.
Unit unit
Unit to calculate the combination in.
std::vector< Term > terms
List of terms making up the combination.
bool polynomialCycleSlipDetectorOutputPolynomials
Whether the polynomials should be outputted.
bool polynomialCycleSlipDetectorOutputWhenWindowSizeNotReached
Whether to output the prediction even when the window size is not reached.
std::vector< std::pair< InsTime, Polynomial< double > > > polynomials
Polynomial collection.
double polynomialCycleSlipDetectorThresholdPercentage
Threshold to categorize a measurement as cycle slip [% of smallest wavelength].
Unit
Possible units to calculate the combination in.
Identifies a satellite signal (satellite frequency and number)