Compare commits
2 Commits
9f9abb45ec
...
a2d43d0cfb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2d43d0cfb | ||
|
|
94713539da |
35
turtle.lua
35
turtle.lua
@@ -54,15 +54,19 @@ print("ID: " .. os.getComputerID())
|
||||
|
||||
-- GPS Functions
|
||||
local function updatePosition()
|
||||
local x, y, z = gps.locate(2)
|
||||
print("Requesting GPS position...")
|
||||
local x, y, z = gps.locate(10) -- Increased timeout to 10 seconds
|
||||
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
|
||||
|
||||
local function setHome()
|
||||
print("Setting home position...")
|
||||
if updatePosition() then
|
||||
state.homePosition = {
|
||||
x = state.position.x,
|
||||
@@ -551,12 +555,35 @@ end
|
||||
|
||||
-- Main loop
|
||||
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()
|
||||
|
||||
if not state.position then
|
||||
print("WARNING: No GPS signal!")
|
||||
print("Limited functionality available")
|
||||
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...")
|
||||
|
||||
Reference in New Issue
Block a user