mirror of
https://github.com/kepler155c/opus
synced 2024-11-10 18:59:55 +00:00
turtle follow
This commit is contained in:
parent
c307f4020c
commit
ab4fd29d16
@ -34,30 +34,37 @@ function GPS.getPoint(timeout, debug)
|
|||||||
return pt
|
return pt
|
||||||
end
|
end
|
||||||
|
|
||||||
function GPS.getHeading(timeout)
|
function GPS.getHeading(timeout, destructive)
|
||||||
|
|
||||||
if not turtle then
|
if not turtle then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local apt = GPS.locate(timeout)
|
local apt = GPS.locate(timeout)
|
||||||
if not apt then
|
if not apt then
|
||||||
return
|
return false, 'GPS not available'
|
||||||
end
|
end
|
||||||
|
|
||||||
local heading = turtle.point.heading
|
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()
|
turtle.turnRight()
|
||||||
if turtle.getHeading() == heading then
|
if turtle.getHeading() == heading then
|
||||||
_G.printError('GPS.getPoint: Unable to move forward')
|
if destructive then
|
||||||
return
|
turtle.dig()
|
||||||
|
if turtle.forward() then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false, 'GPS.getPoint: Unable to move forward'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local bpt = GPS.locate()
|
local bpt = GPS.locate()
|
||||||
if not bpt then
|
if not bpt then
|
||||||
return
|
return false, 'GPS not available'
|
||||||
end
|
end
|
||||||
|
|
||||||
if apt.x < bpt.x then
|
if apt.x < bpt.x then
|
||||||
@ -70,8 +77,8 @@ function GPS.getHeading(timeout)
|
|||||||
return 3
|
return 3
|
||||||
end
|
end
|
||||||
|
|
||||||
function GPS.getPointAndHeading(timeout)
|
function GPS.getPointAndHeading(timeout, destructive)
|
||||||
local heading = GPS.getHeading(timeout)
|
local heading = GPS.getHeading(timeout, destructive)
|
||||||
if heading then
|
if heading then
|
||||||
local pt = GPS.getPoint()
|
local pt = GPS.getPoint()
|
||||||
if pt then
|
if pt then
|
||||||
|
@ -84,15 +84,25 @@ return function (fn, ...)
|
|||||||
if trace[i] == "stack traceback:" then trace_starts = i; break end
|
if trace[i] == "stack traceback:" then trace_starts = i; break end
|
||||||
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
|
-- If this traceback is more than 15 elements long, keep the first 9, last 5
|
||||||
-- and put an ellipsis between the rest
|
-- and put an ellipsis between the rest
|
||||||
local max = 10
|
local max = 10
|
||||||
if trace_starts and #trace - trace_starts > max then
|
if trace_starts and #trace - trace_starts > max then
|
||||||
local keep_starts = trace_starts + 7
|
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, " ...")
|
table.insert(trace, keep_starts, " ...")
|
||||||
end
|
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")
|
return false, table.remove(trace, 1), table.concat(trace, "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@ local tab = UI.Tab {
|
|||||||
function tab:enable()
|
function tab:enable()
|
||||||
local choices = { }
|
local choices = { }
|
||||||
|
|
||||||
for k,v in pairs(device) do
|
for _,v in pairs(device) do
|
||||||
if v.type == 'monitor' then
|
if v.type == 'monitor' then
|
||||||
table.insert(choices, { name = k, value = v.side })
|
table.insert(choices, { name = v.side, value = v.side })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1239,8 +1239,8 @@ function turtle.inspectForwardAt(pt) return _actionForwardAt(actionsAt.inspe
|
|||||||
function turtle.inspectUpAt(pt) return _actionUpAt(actionsAt.inspect, pt) end
|
function turtle.inspectUpAt(pt) return _actionUpAt(actionsAt.inspect, pt) end
|
||||||
|
|
||||||
-- [[ GPS ]] --
|
-- [[ GPS ]] --
|
||||||
function turtle.enableGPS(timeout)
|
function turtle.enableGPS(timeout, destructive)
|
||||||
local pt = GPS.getPointAndHeading(timeout)
|
local pt = GPS.getPointAndHeading(timeout, destructive)
|
||||||
if pt then
|
if pt then
|
||||||
turtle.setPoint(pt, true)
|
turtle.setPoint(pt, true)
|
||||||
return turtle.point
|
return turtle.point
|
||||||
|
Loading…
Reference in New Issue
Block a user