cleanup + example start
This commit is contained in:
1
ignore/scripts/abort
Normal file
1
ignore/scripts/abort
Normal file
@@ -0,0 +1 @@
|
||||
turtle.abort(true)
|
||||
7
ignore/scripts/goHome
Normal file
7
ignore/scripts/goHome
Normal file
@@ -0,0 +1,7 @@
|
||||
_G.requireInjector(_ENV)
|
||||
local config = require('config').load('gps')
|
||||
if config.home then
|
||||
if turtle.enableGPS() then
|
||||
return turtle.pathfind(config.home)
|
||||
end
|
||||
end
|
||||
29
ignore/scripts/moveTo
Normal file
29
ignore/scripts/moveTo
Normal file
@@ -0,0 +1,29 @@
|
||||
turtle.run(function()
|
||||
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local GPS = require('gps')
|
||||
local Socket = require('socket')
|
||||
|
||||
local id = {COMPUTER_ID}
|
||||
|
||||
if not turtle.enableGPS() then
|
||||
error('turtle: No GPS found')
|
||||
end
|
||||
|
||||
local socket = Socket.connect(id, 161)
|
||||
if not socket then
|
||||
error('turtle: Unable to connect to ' .. id)
|
||||
end
|
||||
|
||||
socket:write({ type = 'gps' })
|
||||
|
||||
local pt = socket:read(3)
|
||||
if not pt then
|
||||
error('turtle: No GPS response')
|
||||
end
|
||||
|
||||
if not turtle.pathfind(pt) then
|
||||
error('Unable to go to location')
|
||||
end
|
||||
end)
|
||||
1
ignore/scripts/reboot
Normal file
1
ignore/scripts/reboot
Normal file
@@ -0,0 +1 @@
|
||||
os.reboot()
|
||||
8
ignore/scripts/setHome
Normal file
8
ignore/scripts/setHome
Normal file
@@ -0,0 +1,8 @@
|
||||
_G.requireInjector(_ENV)
|
||||
local Config = require('config')
|
||||
local pt = turtle.enableGPS()
|
||||
if pt then
|
||||
local config = Config.load('gps', { })
|
||||
config.home = pt
|
||||
Config.update('gps', config)
|
||||
end
|
||||
1
ignore/scripts/shutdown
Normal file
1
ignore/scripts/shutdown
Normal file
@@ -0,0 +1 @@
|
||||
os.shutdown()
|
||||
74
ignore/scripts/summon
Normal file
74
ignore/scripts/summon
Normal file
@@ -0,0 +1,74 @@
|
||||
local function summon(id)
|
||||
|
||||
_G.requireInjector(_ENV)
|
||||
|
||||
local GPS = require('gps')
|
||||
local Point = require('point')
|
||||
local Socket = require('socket')
|
||||
|
||||
turtle.setStatus('GPSing')
|
||||
turtle.setPoint({ x = 0, y = 0, z = 0, heading = 0 })
|
||||
|
||||
local pts = {
|
||||
[ 1 ] = { x = 0, z = 0, y = 0 },
|
||||
[ 2 ] = { x = 4, z = 0, y = 0 },
|
||||
[ 3 ] = { x = 2, z = -2, y = 2 },
|
||||
[ 4 ] = { x = 2, z = 2, y = 2 },
|
||||
}
|
||||
local tFixes = { }
|
||||
|
||||
local socket = Socket.connect(id, 161)
|
||||
|
||||
if not socket then
|
||||
error('turtle: Unable to connect to ' .. id)
|
||||
end
|
||||
|
||||
local function getDistance()
|
||||
socket:write({ type = 'ping' })
|
||||
local _, d = socket:read(5)
|
||||
return d
|
||||
end
|
||||
|
||||
local function doGPS()
|
||||
tFixes = { }
|
||||
for i = 1, 4 do
|
||||
if not turtle.go(pts[i]) then
|
||||
error('turtle: Unable to perform GPS maneuver')
|
||||
end
|
||||
local distance = getDistance()
|
||||
if not distance then
|
||||
error('turtle: No response from ' .. id)
|
||||
end
|
||||
table.insert(tFixes, {
|
||||
position = vector.new(turtle.point.x, turtle.point.y, turtle.point.z),
|
||||
distance = distance
|
||||
})
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
if not doGPS() then
|
||||
turtle.turnAround()
|
||||
turtle.setPoint({ x = 0, y = 0, z = 0, heading = 0})
|
||||
if not doGPS() then
|
||||
socket:close()
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
socket:close()
|
||||
|
||||
local pos = GPS.trilaterate(tFixes)
|
||||
|
||||
if pos then
|
||||
local pt = { x = pos.x, y = pos.y, z = pos.z }
|
||||
local _, h = Point.calculateMoves(turtle.getPoint(), pt)
|
||||
local hi = turtle.getHeadingInfo(h)
|
||||
turtle.setStatus('recalling')
|
||||
turtle.pathfind({ x = pt.x - hi.xd, z = pt.z - hi.zd, y = pt.y - hi.yd, heading = h })
|
||||
else
|
||||
error("turtle: Could not determine position")
|
||||
end
|
||||
end
|
||||
|
||||
turtle.run(function() summon({COMPUTER_ID}) end)
|
||||
Reference in New Issue
Block a user