fix: Improve GPS position retrieval with error handling and retry logic
This commit is contained in:
29
turtle.lua
29
turtle.lua
@@ -555,12 +555,35 @@ end
|
|||||||
|
|
||||||
-- Main loop
|
-- Main loop
|
||||||
print("Initializing...")
|
print("Initializing...")
|
||||||
updatePosition()
|
print("Checking for wireless modem...")
|
||||||
|
if not modem then
|
||||||
|
print("ERROR: Wireless modem not found!")
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
updateFuel()
|
updateFuel()
|
||||||
|
|
||||||
if not state.position then
|
if not state.position then
|
||||||
print("WARNING: No GPS signal!")
|
print("WARNING: No GPS signal after " .. maxGpsAttempts .. " attempts!")
|
||||||
print("Limited functionality available")
|
print("Make sure GPS hosts are set up correctly.")
|
||||||
|
print("Limited functionality available - position tracking disabled.")
|
||||||
|
else
|
||||||
|
print("GPS: OK - Position acquired!")
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Ready! Waiting for commands...")
|
print("Ready! Waiting for commands...")
|
||||||
|
|||||||
Reference in New Issue
Block a user