From 73a7ea74f314a1d7967384856b4e35e57641f7e1 Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Tue, 9 Sep 2025 18:24:53 +0200 Subject: [PATCH] feat: Added threshold to unit movement --- backend/core/src/scheduler.cpp | 6 ++++++ backend/core/src/unit.cpp | 3 ++- backend/utils/include/utils.h | 1 + backend/utils/src/utils.cpp | 4 ++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/core/src/scheduler.cpp b/backend/core/src/scheduler.cpp index 2bdb69cc..4013ceb5 100644 --- a/backend/core/src/scheduler.cpp +++ b/backend/core/src/scheduler.cpp @@ -168,6 +168,12 @@ void Scheduler::handleRequest(string key, json::value value, string username, js string WP = to_string(i); double lat = path[i][L"lat"].as_double(); double lng = path[i][L"lng"].as_double(); + if (path[i].has_number_field(L"threshold")) { + double threshold = path[i][L"threshold"].as_double(); + Coords dest; dest.lat = lat; dest.lng = lng; dest.threshold = threshold; + newPath.push_back(dest); + continue; + } Coords dest; dest.lat = lat; dest.lng = lng; newPath.push_back(dest); } diff --git a/backend/core/src/unit.cpp b/backend/core/src/unit.cpp index 952b7e56..33aa8158 100644 --- a/backend/core/src/unit.cpp +++ b/backend/core/src/unit.cpp @@ -765,6 +765,7 @@ void Unit::goToDestination(string enrouteTask) } } +// NOTE: if the current active path has a threshold set, that value will be used instead of the passed one bool Unit::isDestinationReached(double threshold) { if (activeDestination != NULL) @@ -774,7 +775,7 @@ bool Unit::isDestinationReached(double threshold) { double dist = 0; Geodesic::WGS84().Inverse(p->getPosition().lat, p->getPosition().lng, activeDestination.lat, activeDestination.lng, dist); - if (dist < threshold) + if (dist < (activeDestination.threshold == 0? threshold: activeDestination.threshold)) { log(unitName + " destination reached"); return true; diff --git a/backend/utils/include/utils.h b/backend/utils/include/utils.h index 16b16c68..70f8cf67 100644 --- a/backend/utils/include/utils.h +++ b/backend/utils/include/utils.h @@ -6,6 +6,7 @@ struct Coords { double lat = 0; double lng = 0; double alt = 0; + double threshold = 0; // used for proximity checks only, not part of the actual coordinates }; struct Offset { diff --git a/backend/utils/src/utils.cpp b/backend/utils/src/utils.cpp index a0ebfdf7..40643055 100644 --- a/backend/utils/src/utils.cpp +++ b/backend/utils/src/utils.cpp @@ -64,9 +64,9 @@ std::string random_string(size_t length) return str; } -bool operator== (const Coords& a, const Coords& b) { return a.lat == b.lat && a.lng == b.lng && a.alt == b.alt; } +bool operator== (const Coords& a, const Coords& b) { return a.lat == b.lat && a.lng == b.lng && a.alt == b.alt && a.threshold == b.threshold; } bool operator!= (const Coords& a, const Coords& b) { return !(a == b); } -bool operator== (const Coords& a, const double& b) { return a.lat == b && a.lng == b && a.alt == b; } +bool operator== (const Coords& a, const double& b) { return a.lat == b && a.lng == b && a.alt == b && a.threshold == b } bool operator!= (const Coords& a, const double& b) { return !(a == b); } bool operator== (const Offset& a, const Offset& b) { return a.x == b.x && a.y == b.y && a.z == b.z; }