From ee70b5996f5268f25b971942486b635c71ba3d6a Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Tue, 14 Dec 2021 22:38:54 -0500 Subject: [PATCH] Updated formula for position plugin --- src/plugins/PositionPlugin.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/plugins/PositionPlugin.cpp b/src/plugins/PositionPlugin.cpp index e0503930c..e10f05d1e 100644 --- a/src/plugins/PositionPlugin.cpp +++ b/src/plugins/PositionPlugin.cpp @@ -148,14 +148,22 @@ int32_t PositionPlugin::runOnce() NodeInfo *node = service.refreshMyNodeInfo(); // should guarantee there is now a position if (node->has_position && (node->position.latitude_i != 0 || node->position.longitude_i != 0)) { + // The minimum distance to travel before we are able to send a new position packet. + const uint32_t distanceTravelMinimum = 30; + + // The minimum time that would pass before we are able to send a new position packet. + const uint32_t timeTravelMinimum = 30; + + // Determine the distance in meters between two points on the globe float distance = GeoCoord::latLongToMeter(lastGpsLatitude * 1e-7, lastGpsLongitude * 1e-7, node->position.latitude_i * 1e-7, node->position.longitude_i * 1e-7); - // 2500 is a magic number. 50 is the minumum distance we want to travel before sending another position packet. - uint32_t distanceTravel = ((2500 / myNodeInfo.bitrate) >= 50) ? (2500 / myNodeInfo.bitrate) : 50; + // Yes, this has a bunch of magic numbers. Sorry. This is to make the scale non-linear. + const float distanceTravelMath = 1203 / (sqrt( pow(myNodeInfo.bitrate, 1.5) / 1.1 ) ) ; + uint32_t distanceTravel = (distanceTravelMath >= distanceTravelMinimum) ? distanceTravelMath : distanceTravelMinimum; - // 1500 is a magic number. 30 is the minumum interval between position packets - uint32_t timeTravel = ((1500 / myNodeInfo.bitrate) >= 30) ? (1500 / myNodeInfo.bitrate) : 30; + // Yes, this has a bunch of magic numbers. Sorry. + uint32_t timeTravel = ((1500 / myNodeInfo.bitrate) >= timeTravelMinimum) ? (1500 / myNodeInfo.bitrate) : timeTravelMinimum; // If the distance traveled since the last update is greater than 100 meters // and it's been at least 60 seconds since the last update