The cool thing is that it saves the turtle's coordinates to a data/pos.txt file after every move, enabling it to work even when there are no GPS hosts in range. The postion just has to be synced once using the "syncpos" program and then you can use "goto" + x, y, z coordinates (+ direction (optional, must be between 0 and 3)).
The code:
goto:
Spoiler
local tArgs = {...}
local x, y, z, f
local xCur, yCur, zCur, fCur
local xDif, yDif, zDif
local posIn, posOut, pos
local function syncFile()
posOut = io.open("data/pos.txt", "w")
posOut:write(textutils.serialize({xCur, yCur, zCur, fCur}))
posOut:close()
end
local function abort(msg)
syncFile()
print("ERROR: "..msg)
do return end
end
local function up(n)
for i = 1, n do
while not turtle.up() do
turtle.digUp()
end
yCur = yCur + 1
syncFile()
end
end
local function down(n)
for i = 1, n do
while not turtle.down() do
turtle.digDown()
end
yCur = yCur - 1
syncFile()
end
end
local function moveF(dir, n)
while fCur ~= dir do
turtle.turnLeft()
if dir < 0 or dir > 3 then
do return end
end
if fCur ~= 0 then
fCur = fCur - 1
else
fCur = 3
end
syncFile()
end
for i = 1, n do
while not turtle.forward() do
up(1)
end
if fCur == 0 then
zCur = zCur + 1
elseif fCur == 1 then
xCur = xCur - 1
elseif fCur == 2 then
zCur = zCur - 1
elseif fCur == 3 then
xCur = xCur + 1
else
abort("invalid state for fCur")
end
syncFile()
end
end
if not tArgs[1] or not tArgs[2] or not tArgs[3] then
print("Usage: goto <x> <y> <z> [<f>]")
do return end
end
x = tonumber(tArgs[1])
y = tonumber(tArgs[2])
z = tonumber(tArgs[3])
if tArgs[4] then
f = tonumber(tArgs[4])
end
posIn = io.open("data/pos.txt", "r")
pos = posIn:read()
posIn:close()
pos = textutils.unserialize(pos)
xCur = tonumber(pos[1])
yCur = tonumber(pos[2])
zCur = tonumber(pos[3])
fCur = tonumber(pos[4])
xDif = x - xCur
zDif = z - zCur
if xDif &lt; 0 then
xDif = xDif * -1
moveF(1, xDif)
else
moveF(3, xDif)
end
if zDif &lt; 0 then
zDif = zDif * -1
moveF(2, zDif)
else
moveF(0, zDif)
end
yDif = y - yCur
if yDif &lt; 0 then
yDif = yDif * -1
down(yDif)
else
up(yDif)
end
if f then
moveF(f, 0)
end
syncFile()
Pastebin link: http://pastebin.com/Ti7a1wVD
syncpos:
Spoiler
local xIni, yIni, zIni
local xCur, yCur, zCur
local fCur
local posOut
xIni, yIni, zIni = gps.locate(5)
if not xIni or not yIni or not zIni then
print("No or insufficient GPS hosts found")
do return end
end
while not turtle.forward() do
while not turtle.up() do
turtle.digUp()
end
end
xCur, yCur, zCur = gps.locate(5)
if zCur &gt; zIni then
fCur = 0
elseif xCur &lt; xIni then
fCur = 1
elseif zCur &lt; zIni then
fCur = 2
elseif xCur &gt; xIni then
fCur = 3
else
exit()
end
while not turtle.back() do
while not turtle.up() do
turtle.digUp()
end
end
xCur, yCur, zCur = gps.locate(5)
if not fs.isDir("data") then
fs.delete("data")
fs.makeDir("data")
end
posOut = io.open("data/pos.txt", "w")
posOut:write(textutils.serialize({xCur, yCur, zCur, fCur}))
posOut:close()
Pastebin link: http://pastebin.com/k3B7tUKH
Update notes:
- syncpos now exits without an error if there are no GPS hosts, just returns a message
- added code to syncpos to automatically create a data folder if there is none present, be careful not to name a file "data", syncpos will delete it
- more bugfixing
Planned additions:
- builing program for GPS satellites, without need to input coordinates
- advanced excavate with input for exact position and size
If you are interested in how the programs work, feel free to ask and I'll add an explanation to this post.</f></z></y></x>