turtle follow

This commit is contained in:
kepler155c@gmail.com 2019-02-20 08:52:27 -05:00
parent c307f4020c
commit ab4fd29d16
4 changed files with 31 additions and 14 deletions

View File

@ -34,30 +34,37 @@ function GPS.getPoint(timeout, debug)
return pt
end
function GPS.getHeading(timeout)
function GPS.getHeading(timeout, destructive)
if not turtle then
return
end
local apt = GPS.locate(timeout)
if not apt then
return
return false, 'GPS not available'
end
local heading = turtle.point.heading
while not turtle.forward() do
while true do
if not turtle.inspect() and turtle.forward() then
break
end
turtle.turnRight()
if turtle.getHeading() == heading then
_G.printError('GPS.getPoint: Unable to move forward')
return
if destructive then
turtle.dig()
if turtle.forward() then
break
end
end
return false, 'GPS.getPoint: Unable to move forward'
end
end
local bpt = GPS.locate()
if not bpt then
return
return false, 'GPS not available'
end
if apt.x < bpt.x then
@ -70,8 +77,8 @@ function GPS.getHeading(timeout)
return 3
end
function GPS.getPointAndHeading(timeout)
local heading = GPS.getHeading(timeout)
function GPS.getPointAndHeading(timeout, destructive)
local heading = GPS.getHeading(timeout, destructive)
if heading then
local pt = GPS.getPoint()
if pt then

View File

@ -84,15 +84,25 @@ return function (fn, ...)
if trace[i] == "stack traceback:" then trace_starts = i; break end
end
for _, line in pairs(trace) do
_G._debug(line)
end
-- If this traceback is more than 15 elements long, keep the first 9, last 5
-- and put an ellipsis between the rest
local max = 10
if trace_starts and #trace - trace_starts > max then
local keep_starts = trace_starts + 7
for i = #trace - trace_starts - max, 0, -1 do table.remove(trace, keep_starts + i) end
for i = #trace - trace_starts - max, 0, -1 do
table.remove(trace, keep_starts + i)
end
table.insert(trace, keep_starts, " ...")
end
for k, line in pairs(trace) do
trace[k] = line:gsub("in function", " in")
end
return false, table.remove(trace, 1), table.concat(trace, "\n")
end

View File

@ -28,9 +28,9 @@ local tab = UI.Tab {
function tab:enable()
local choices = { }
for k,v in pairs(device) do
for _,v in pairs(device) do
if v.type == 'monitor' then
table.insert(choices, { name = k, value = v.side })
table.insert(choices, { name = v.side, value = v.side })
end
end

View File

@ -1239,8 +1239,8 @@ function turtle.inspectForwardAt(pt) return _actionForwardAt(actionsAt.inspe
function turtle.inspectUpAt(pt) return _actionUpAt(actionsAt.inspect, pt) end
-- [[ GPS ]] --
function turtle.enableGPS(timeout)
local pt = GPS.getPointAndHeading(timeout)
function turtle.enableGPS(timeout, destructive)
local pt = GPS.getPointAndHeading(timeout, destructive)
if pt then
turtle.setPoint(pt, true)
return turtle.point