74 if (!detector.polyReg.windowSizeReached())
80 auto polynomial = detector.polyReg.calcPolynomial();
88 if (std::abs(measurementDifference - predictedValue) > threshold)
147 detector.second.polyReg.setWindowSize(windowSize);
160 detector.second.polyReg.setPolynomialDegree(polyDegree);
176 detector.second.polyReg.setStrategy(strategy);
182 [[nodiscard]] std::optional<size_t>
getDataSize(
const Key& key)
const
186 return _detectors.at(key).polyReg.data().size();
217 return static_cast<double>((insTime - detector.
startTime).count());
238 auto polynomial = detector.polyReg.calcPolynomial();
239 if (!polynomial) {
return {}; }
245 [[nodiscard]] std::optional<Polynomial<double>>
calcPolynomial(
const Key& key)
const
249 return _detectors.at(key).polyReg.calcPolynomial();
261 detector.polyReg.push_back(
calcRelativeTime(insTime, detector), measurementDifference);
272template<
typename Key>
275 bool changed =
false;
277 bool enabled = polynomialCycleSlipDetector.
isEnabled();
278 if (ImGui::Checkbox(fmt::format(
"Enabled##{}", label).c_str(), &enabled))
281 polynomialCycleSlipDetector.
setEnabled(enabled);
284 if (!enabled) { ImGui::BeginDisabled(); }
286 ImGui::SetNextItemWidth(width);
287 if (
int windowSize =
static_cast<int>(polynomialCycleSlipDetector.
getWindowSize());
288 ImGui::InputIntL(fmt::format(
"Window size##{}", label).c_str(), &windowSize,
292 polynomialCycleSlipDetector.
setWindowSize(
static_cast<size_t>(windowSize));
295 ImGui::SetNextItemWidth(width);
297 ImGui::InputIntL(fmt::format(
"Polynomial Degree##{}", label).c_str(), &polyDegree,
298 0, std::min(
static_cast<int>(polynomialCycleSlipDetector.
getWindowSize()) - 1, std::numeric_limits<int>::max())))
304 ImGui::SetNextItemWidth(width);
312 ImGui::Checkbox(fmt::format(
"Reset after cycle-slip##{}", label).c_str(), &resetAfterCycleSlip))
318 if (!enabled) { ImGui::EndDisabled(); }
326template<
typename Key>
340template<
typename Key>
343 if (j.contains(
"enabled"))
345 auto enabled = j.at(
"enabled").get<
bool>();
348 if (j.contains(
"windowSize"))
350 auto windowSize = j.at(
"windowSize").get<
size_t>();
353 if (j.contains(
"polynomialDegree"))
355 auto polynomialDegree = j.at(
"polynomialDegree").get<
size_t>();
358 if (j.contains(
"strategy"))
360 auto strategy = j.at(
"strategy").get<
size_t>();
363 if (j.contains(
"resetAfterCycleSlip"))
365 auto reset = j.at(
"resetAfterCycleSlip").get<
bool>();
Combo representing an enumeration.
nlohmann::json json
json namespace
The class is responsible for all time-related tasks.
Utility functions for std::pair.
Polynomial curve fitting.
Structs identifying a unique satellite.
std::unordered_map< Key, T > unordered_map
Unordered map type.
Allows creation of GNSS measurement combinations.
The class is responsible for all time-related tasks.
size_t getPolynomialDegree() const
Get the degree of the polynomial which is used for fitting.
void setFitStrategy(Strategy strategy)
Sets the strategy used for fitting.
void setWindowSize(size_t windowSize)
Sets the amount of points used for the fit (sliding window)
void addMeasurement(const Key &key, InsTime insTime, double measurementDifference)
Add a measurement to the polynomial fit.
std::optional< double > predictValue(const Key &key, const InsTime &insTime) const
Predicts a value from the collected data and polynomial fit.
void setEnabled(bool enabled)
Sets the enabled state.
bool _resetAfterCycleSlip
Whether to discard all data after a cycle-slip.
PolynomialRegressor<>::Strategy Strategy
Strategies for fitting.
friend class CycleSlipDetector
bool isEnabled() const
Is the cycle-slip detector enabled?
std::optional< size_t > getDataSize(const Key &key) const
Get the amount of data collected.
std::optional< double > calcRelativeTime(const Key &key, const InsTime &insTime) const
Calculate the relative time to the start time of the detector.
void setPolynomialDegree(size_t polyDegree)
Sets the degree of the polynomial which is used for fitting.
size_t getWindowSize() const
Get the window size for the polynomial fit.
void setResetAfterCycleSlip(bool reset)
Sets whether to discard all data after a cycle-slip.
static double calcRelativeTime(const InsTime &insTime, const SignalDetector &detector)
Calculate the relative time to the start time of the detector.
Strategy _strategy
Strategy used for fitting.
std::optional< Polynomial< double > > calcPolynomial(const Key &key) const
Calculates the polynomial from the collected data.
bool resetAfterCycleSlip() const
Whether to discard all data after a cycle-slip.
PolynomialCycleSlipDetectorResult checkForCycleSlip(const Key &key, InsTime insTime, double measurementDifference, double threshold)
Checks for a cycle slip.
size_t _windowSize
Window size for the sliding window.
bool _enabled
Whether the cycle-slip detector is enabled.
Strategy getFitStrategy() const
Get the strategy used for fitting.
size_t _polyDegree
Polynomial degree to fit.
void reset(const Key &key)
Reset the polynomial for the given combination.
unordered_map< Key, SignalDetector > _detectors
Detectors, one for each key.
PolynomialCycleSlipDetector(size_t windowSize, size_t polyDegree, bool enabled=true)
Constructor.
friend class GnssAnalyzer
void clear()
Empties the collected polynomials.
Polynomial Curve Fitting.
Strategy
Possible Fit strategies.
bool InputIntL(const char *label, int *v, int v_min, int v_max, int step, int step_fast, ImGuiInputTextFlags flags)
Shows a value limited InputText GUI element for 'int'.
void to_json(json &j, const Node &node)
Converts the provided node into a json object.
PolynomialCycleSlipDetectorResult
Cycle-slip detection result type.
@ NoCycleSlip
No cycle-slip found.
@ LessDataThanWindowSize
Less data than the specified window size (cannot predict cycle-slip yet)
@ Disabled
The cycle-slip detector is disabled.
@ CycleSlip
Cycle-slip found.
void from_json(const json &j, Node &node)
Converts the provided json object into a node object.
bool PolynomialCycleSlipDetectorGui(const char *label, PolynomialCycleSlipDetector< Key > &polynomialCycleSlipDetector, float width=0.0F)
Shows a GUI for advanced configuration of the PolynomialCycleSlipDetector.
SignalDetector(InsTime startTime, size_t windowSize, size_t polyDegree, Strategy strategy)
Constructor.
PolynomialRegressor< double > polyReg
Polynomial Regressor.
InsTime startTime
Time when the first message for this detector was received.