0.2.0
Loading...
Searching...
No Matches
CycleSlipDetector.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 <variant>
17#include <array>
21
22namespace NAV
23{
24
27{
28 public:
30 enum class Detector
31 {
32 LLI,
35 };
36
39 [[nodiscard]] bool isEnabled(const Detector& detector) const
40 {
41 switch (detector)
42 {
43 case Detector::LLI:
44 return _enableLLICheck;
46 return _singleFrequencyDetector.isEnabled();
48 return _dualFrequencyDetector.isEnabled();
49 };
50 return false;
51 }
55 void setEnabled(bool enabled, const Detector& detector)
56 {
57 switch (detector)
58 {
59 case Detector::LLI:
60 _enableLLICheck = enabled;
61 break;
63 _singleFrequencyDetector.setEnabled(enabled);
64 break;
66 _dualFrequencyDetector.setEnabled(enabled);
67 break;
68 };
69 }
70
73 [[nodiscard]] size_t getWindowSize(const Detector& detector) const
74 {
75 return detector == Detector::SingleFrequency ? _singleFrequencyDetector.getWindowSize() : _dualFrequencyDetector.getWindowSize();
76 }
80 void setWindowSize(size_t windowSize, const Detector& detector)
81 {
82 if (detector == Detector::SingleFrequency) { _singleFrequencyDetector.setWindowSize(windowSize); }
83 else { _dualFrequencyDetector.setWindowSize(windowSize); }
84 }
85
88 [[nodiscard]] double getThreshold(const Detector& detector) const
89 {
90 return detector == Detector::SingleFrequency ? _singleFrequencyThresholdPercentage : _dualFrequencyThresholdPercentage;
91 }
95 void setThreshold(double threshold, const Detector& detector)
96 {
97 if (detector == Detector::SingleFrequency) { _singleFrequencyThresholdPercentage = threshold; }
98 else { _dualFrequencyThresholdPercentage = threshold; }
99 }
100
103 [[nodiscard]] size_t getPolynomialDegree(const Detector& detector) const
104 {
105 return detector == Detector::SingleFrequency ? _singleFrequencyDetector.getPolynomialDegree() : _dualFrequencyDetector.getPolynomialDegree();
106 }
110 void setPolynomialDegree(size_t polyDegree, const Detector& detector)
111 {
112 if (detector == Detector::SingleFrequency) { _singleFrequencyDetector.setPolynomialDegree(polyDegree); }
113 else { _dualFrequencyDetector.setPolynomialDegree(polyDegree); }
114 }
115
118
121 [[nodiscard]] Strategy getFitStrategy(const Detector& detector) const
122 {
123 return detector == Detector::SingleFrequency ? _singleFrequencyDetector.getFitStrategy() : _dualFrequencyDetector.getFitStrategy();
124 }
128 void setFitStrategy(Strategy strategy, const Detector& detector)
129 {
130 if (detector == Detector::SingleFrequency) { _singleFrequencyDetector.setFitStrategy(strategy); }
131 else { _dualFrequencyDetector.setFitStrategy(strategy); }
132 }
133
146 {
147 std::array<SatSigId, 2> signals;
148 };
149
151 using Result = std::variant<CycleSlipLossOfLockIndicator, CycleSlipDualFrequency, CycleSlipSingleFrequency>;
152
155 {
162
164 std::vector<Signal> signals;
165 int8_t freqNum = -128;
166 };
167
173 [[nodiscard]] std::vector<Result> checkForCycleSlip(InsTime insTime, const std::vector<SatelliteObservation>& satObs, const std::string& nameId);
174
177 void resetSignal(const SatSigId& satSigId);
178
180 void reset();
181
184 {
188 constexpr bool operator==(const DualFrequencyCombination& rhs) const { return satId == rhs.satId && sig1 == rhs.sig1 && sig2 == rhs.sig2; }
189
193 constexpr bool operator<(const DualFrequencyCombination& rhs) const
194 {
195 return satId == rhs.satId ? (sig1 == rhs.sig1
196 ? sig2 < rhs.sig2
197 : sig1 < rhs.sig1)
198 : satId < rhs.satId;
199 }
200
204 };
205
206 private:
208 bool _enableLLICheck = true;
209
210 double _singleFrequencyThresholdPercentage = 11.0;
211 double _dualFrequencyThresholdPercentage = 0.6;
212
214 PolynomialCycleSlipDetector<SatSigId> _singleFrequencyDetector{ 4, 2, false };
215
217 PolynomialCycleSlipDetector<DualFrequencyCombination> _dualFrequencyDetector{ 2, 1 };
218
219 friend bool CycleSlipDetectorGui(const char* label, CycleSlipDetector& cycleSlipDetector, float width, bool dualFrequencyAvailable);
220 friend void to_json(json& j, const CycleSlipDetector& data);
221 friend void from_json(const json& j, CycleSlipDetector& data);
222};
223
229bool CycleSlipDetectorGui(const char* label, CycleSlipDetector& cycleSlipDetector, float width = 0.0F, bool dualFrequencyAvailable = true);
230
234void to_json(json& j, const CycleSlipDetector& data);
238void from_json(const json& j, CycleSlipDetector& data);
239
242[[nodiscard]] std::string to_string(const CycleSlipDetector::Result& cycleSlip);
243
244} // namespace NAV
245
250std::ostream& operator<<(std::ostream& os, const NAV::CycleSlipDetector::Result& obj);
251
252namespace std
253{
255template<>
256struct hash<NAV::CycleSlipDetector::DualFrequencyCombination>
257{
261 {
262 auto hash1 = std::hash<NAV::SatId>{}(c.satId);
263 auto hash2 = std::hash<NAV::Code>{}(c.sig1);
264 auto hash3 = std::hash<NAV::Code>{}(c.sig2);
265
266 return hash1 | (hash2 << 24) | (hash3 << 48);
267 }
268};
269} // namespace std
270
271#ifndef DOXYGEN_IGNORE
272
274template<>
275struct fmt::formatter<NAV::CycleSlipDetector::Result> : fmt::formatter<std::string>
276{
281 template<typename FormatContext>
282 auto format(const NAV::CycleSlipDetector::Result& cycleSlip, FormatContext& ctx) const
283 {
284 return fmt::formatter<std::string>::format(to_string(cycleSlip), ctx);
285 }
286};
287
288#endif
std::ostream & operator<<(std::ostream &os, const NAV::CycleSlipDetector::Result &obj)
Stream insertion operator overload.
bool CycleSlipDetectorGui(const char *label, CycleSlipDetector &cycleSlipDetector, float width=0.0F, bool dualFrequencyAvailable=true)
Shows a GUI for advanced configuration of the CycleSlipDetector.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
GNSS Observation messages.
Polynomial Cycle-slip detection algorithm.
const char * to_string(gui::widgets::PositionWithFrame::ReferenceFrame refFrame)
Converts the enum to a string.
Structs identifying a unique satellite.
Enumerate for GNSS Codes.
Definition Code.hpp:88
Cycle-slip detector.
Definition CycleSlipDetector.hpp:27
void reset()
Resets all data.
std::variant< CycleSlipLossOfLockIndicator, CycleSlipDualFrequency, CycleSlipSingleFrequency > Result
Result of the cycle-slip detection test.
Definition CycleSlipDetector.hpp:151
bool isEnabled(const Detector &detector) const
Is the cycle-slip detector enabled?
Definition CycleSlipDetector.hpp:39
friend bool CycleSlipDetectorGui(const char *label, CycleSlipDetector &cycleSlipDetector, float width, bool dualFrequencyAvailable)
Shows a GUI for advanced configuration of the CycleSlipDetector.
void setWindowSize(size_t windowSize, const Detector &detector)
Sets the amount of points used for the fit (sliding window)
Definition CycleSlipDetector.hpp:80
std::vector< Result > checkForCycleSlip(InsTime insTime, const std::vector< SatelliteObservation > &satObs, const std::string &nameId)
Checks for a cycle slip.
void setThreshold(double threshold, const Detector &detector)
Sets the threshold to categorize a measurement as cycle slip.
Definition CycleSlipDetector.hpp:95
void resetSignal(const SatSigId &satSigId)
Resets all data related to the provided signal.
Strategy getFitStrategy(const Detector &detector) const
Get the strategy used for fitting.
Definition CycleSlipDetector.hpp:121
friend void to_json(json &j, const CycleSlipDetector &data)
Write info to a json object.
void setEnabled(bool enabled, const Detector &detector)
Sets the enabled state.
Definition CycleSlipDetector.hpp:55
void setFitStrategy(Strategy strategy, const Detector &detector)
Sets the strategy used for fitting.
Definition CycleSlipDetector.hpp:128
size_t getWindowSize(const Detector &detector) const
Get the window size for the polynomial fit.
Definition CycleSlipDetector.hpp:73
double getThreshold(const Detector &detector) const
Get the threshold to categorize a measurement as cycle slip [% of smallest wavelength].
Definition CycleSlipDetector.hpp:88
Detector
Detectors in use.
Definition CycleSlipDetector.hpp:31
@ LLI
Loss-of-Lock Indicator check.
@ SingleFrequency
Single frequency detector.
@ DualFrequency
Dual frequency detector.
void setPolynomialDegree(size_t polyDegree, const Detector &detector)
Sets the degree of the polynomial which is used for fitting.
Definition CycleSlipDetector.hpp:110
friend void from_json(const json &j, CycleSlipDetector &data)
Read info from a json object.
size_t getPolynomialDegree(const Detector &detector) const
Get the degree of the polynomial which is used for fitting.
Definition CycleSlipDetector.hpp:103
The class is responsible for all time-related tasks.
Definition InsTime.hpp:667
Cycle-slip detection.
Definition PolynomialCycleSlipDetector.hpp:49
Strategy
Possible Fit strategies.
Definition PolynomialRegressor.hpp:43
Cycle-slip found in dual frequency combination.
Definition CycleSlipDetector.hpp:146
std::array< SatSigId, 2 > signals
Signal identifiers where the cycle-slip occurred.
Definition CycleSlipDetector.hpp:147
Cycle-slip because LLI was set.
Definition CycleSlipDetector.hpp:136
SatSigId signal
Signal identifier where the cycle-slip occurred.
Definition CycleSlipDetector.hpp:137
Cycle-slip found in single frequency carrier-phase observation.
Definition CycleSlipDetector.hpp:141
SatSigId signal
Signal identifier where the cycle-slip occurred.
Definition CycleSlipDetector.hpp:142
Dual frequency combination.
Definition CycleSlipDetector.hpp:184
SatId satId
Satellite Identifier.
Definition CycleSlipDetector.hpp:201
Code sig2
Signal code/frequency (f(sig2) < f(sig1), e.g. L2 if L1-L2)
Definition CycleSlipDetector.hpp:203
constexpr bool operator==(const DualFrequencyCombination &rhs) const
Equal comparison (needed for unordered_map)
Definition CycleSlipDetector.hpp:188
Code sig1
Signal code/frequency (f(sig1) > f(sig2), e.g. L1 if L1-L2)
Definition CycleSlipDetector.hpp:202
constexpr bool operator<(const DualFrequencyCombination &rhs) const
Less than comparison (needed for map)
Definition CycleSlipDetector.hpp:193
Signal for a code.
Definition CycleSlipDetector.hpp:158
GnssObs::ObservationData::CarrierPhase measurement
Carrier-phase measurement and LLI flag.
Definition CycleSlipDetector.hpp:160
Code code
Code.
Definition CycleSlipDetector.hpp:159
Satellite observations ordered per satellite.
Definition CycleSlipDetector.hpp:155
int8_t freqNum
Frequency number. Only used for GLONASS G1 and G2.
Definition CycleSlipDetector.hpp:165
SatId satId
Satellite identifier.
Definition CycleSlipDetector.hpp:163
std::vector< Signal > signals
List of signals.
Definition CycleSlipDetector.hpp:164
Carrier phase.
Definition GnssObs.hpp:71
Identifies a satellite (satellite system and number)
Definition SatelliteIdentifier.hpp:32
Identifies a satellite signal (satellite frequency and number)
Definition SatelliteIdentifier.hpp:62
std::size_t operator()(const NAV::CycleSlipDetector::DualFrequencyCombination &c) const
Hash function for SatId.
Definition CycleSlipDetector.hpp:260