From f70dd16cff67da22b07b9dee2bc04104638a56f5 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Mon, 16 Feb 2026 01:04:31 -0500 Subject: [PATCH] fix: Optimize GPS position retrieval with reduced timeout and background retry logic --- turtle.lua | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/turtle.lua b/turtle.lua index cea6532..2fdc8a9 100644 --- a/turtle.lua +++ b/turtle.lua @@ -54,14 +54,12 @@ print("ID: " .. os.getComputerID()) -- GPS Functions local function updatePosition() - print("Requesting GPS position...") - local x, y, z = gps.locate(10) -- Increased timeout to 10 seconds + -- Quick GPS check with short timeout + local x, y, z = gps.locate(2) -- 2 second timeout if x then state.position = {x = math.floor(x), y = math.floor(y), z = math.floor(z)} - print("GPS position: " .. x .. ", " .. y .. ", " .. z) return true end - print("GPS timeout - no position received") return false end @@ -357,7 +355,8 @@ end function broadcastStatus() updateFuel() updateInventory() - updatePosition() + -- Don't update position on every broadcast to avoid GPS delays + -- Position will be updated by movement functions modem.transmit(STATUS_CHANNEL, CHANNEL_RECEIVE, { type = "status", @@ -562,32 +561,23 @@ else print("Wireless modem: OK") end -print("Attempting to get GPS position (this may take 10 seconds)...") -local gpsAttempts = 0 -local maxGpsAttempts = 3 - -while not state.position and gpsAttempts < maxGpsAttempts do - gpsAttempts = gpsAttempts + 1 - print("GPS attempt " .. gpsAttempts .. " of " .. maxGpsAttempts .. "...") - updatePosition() - if not state.position then - print("Waiting 2 seconds before retry...") - sleep(2) - end +print("Attempting quick GPS check...") +-- Single quick GPS attempt (5 second timeout instead of 10) +local x, y, z = gps.locate(5) +if x then + state.position = {x = math.floor(x), y = math.floor(y), z = math.floor(z)} + print("GPS: OK - Position acquired!") +else + print("GPS: Not available - will retry in background") + print("Position tracking disabled for now.") end updateFuel() -if not state.position then - print("WARNING: No GPS signal after " .. maxGpsAttempts .. " attempts!") - print("Make sure GPS hosts are set up correctly.") - print("Limited functionality available - position tracking disabled.") -else - print("GPS: OK - Position acquired!") -end - print("Ready! Waiting for commands...") +print("Broadcasting initial status...") broadcastStatus() +print("Turtle " .. os.getComputerID() .. " is online!") -- Main execution loop parallel.waitForAny(