Browse Source

add a low pass filter to keep the TTL more stable

Sven Czarnian 3 years ago
parent
commit
031c9faa97
1 changed files with 16 additions and 3 deletions
  1. 16 3
      src/types/Inbound.cpp

+ 16 - 3
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<long long>(flightTime.convert(second)));
     const auto delta = std::chrono::duration_cast<std::chrono::seconds>(destination.plannedArrivalTime() - UtcTime::currentUtc());
     const auto plannedFlightTime = static_cast<float>(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;