From 031c9faa97238691e144c0a2eadea7086fc888a0 Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Thu, 23 Dec 2021 17:49:56 +0100 Subject: [PATCH] add a low pass filter to keep the TTL more stable --- src/types/Inbound.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/types/Inbound.cpp b/src/types/Inbound.cpp index 076b12d..db4a2db 100644 --- a/src/types/Inbound.cpp +++ b/src/types/Inbound.cpp @@ -37,7 +37,8 @@ Inbound::Inbound(EuroScopePlugIn::CRadarTarget& target, const aman::AircraftSche m_runway(inbound.arrivalrunway()), m_nextStarWaypoint(0), m_arrivalRoute(), - m_timeToLose() { + m_timeToLose(), + m_resetFilter(true) { this->createWindTables(wind); this->updatePrediction(target, inbound); } @@ -331,7 +332,15 @@ void Inbound::predictETA(const EuroScopePlugIn::CRadarTarget& target, const Euro this->m_waypointEstimatedTimeOfArrival = UtcTime::currentUtc() + std::chrono::seconds(static_cast(flightTime.convert(second))); const auto delta = std::chrono::duration_cast(destination.plannedArrivalTime() - UtcTime::currentUtc()); const auto plannedFlightTime = static_cast(delta.count()) * second; - this->m_timeToLose = plannedFlightTime - flightTime; + const auto timeToLose = plannedFlightTime - flightTime; + + if (true == this->m_resetFilter) { + this->m_timeToLose = timeToLose; + this->m_resetFilter = false; + } + else { + this->m_timeToLose = 0.9f * this->m_timeToLose + 0.1f * timeToLose; + } } void Inbound::update(EuroScopePlugIn::CRadarTarget& target) { @@ -345,8 +354,10 @@ void Inbound::update(EuroScopePlugIn::CRadarTarget& target) { if (this->m_nextStarWaypoint < this->m_arrivalRoute.size()) { const auto maxDistance = this->m_groundSpeed * 60_s; - if (maxDistance > gsl::at(this->m_arrivalRoute, this->m_nextStarWaypoint).position().distanceTo(__convert(target.GetPosition().GetPosition()))) + if (maxDistance > gsl::at(this->m_arrivalRoute, this->m_nextStarWaypoint).position().distanceTo(__convert(target.GetPosition().GetPosition()))) { this->m_nextStarWaypoint += 1; + this->m_resetFilter = true; + } } this->predictETA(target, target.GetCorrelatedFlightPlan().GetPositionPredictions()); @@ -355,6 +366,8 @@ void Inbound::update(EuroScopePlugIn::CRadarTarget& target) { void Inbound::directTo(EuroScopePlugIn::CRadarTarget& radarTarget, const std::string& waypoint) { std::size_t i = 0; + this->m_resetFilter = true; + for (const auto& arrivalPoint : std::as_const(this->m_arrivalRoute)) { if (arrivalPoint.name() == waypoint) { this->m_nextStarWaypoint = i;