1
0
mirror of https://github.com/kepler155c/opus synced 2024-10-01 08:20:41 +00:00
opus/sys/extensions/tgps.lua

59 lines
1.2 KiB
Lua
Raw Normal View History

2017-09-06 01:21:43 +00:00
if not turtle or turtle.enableGPS then
2016-12-11 19:24:52 +00:00
return
end
requireInjector(getfenv(1))
local GPS = require('gps')
local Config = require('config')
2016-12-11 19:24:52 +00:00
2017-05-24 23:48:48 +00:00
function turtle.enableGPS(timeout)
2017-07-30 23:53:43 +00:00
if turtle.point.gps then
2017-05-24 23:48:48 +00:00
return turtle.point
end
local pt = GPS.getPointAndHeading(timeout)
2016-12-11 19:24:52 +00:00
if pt then
2017-07-24 02:37:07 +00:00
turtle.setPoint(pt, true)
return turtle.point
2016-12-11 19:24:52 +00:00
end
end
function turtle.gotoGPSHome()
local config = { }
Config.load('gps', config)
if config.home then
2017-05-24 23:48:48 +00:00
if turtle.enableGPS() then
turtle.pathfind(config.home)
2016-12-11 19:24:52 +00:00
end
end
end
function turtle.setGPSHome()
local config = { }
Config.load('gps', config)
2017-09-18 18:46:46 +00:00
if turtle.point.gps then
config.home = turtle.point
Config.update('gps', config)
2017-09-18 18:46:46 +00:00
else
local pt = GPS.getPoint()
if pt then
local originalHeading = turtle.point.heading
local heading = GPS.getHeading()
if heading then
local turns = (turtle.point.heading - originalHeading) % 4
pt.heading = (heading - turns) % 4
config.home = pt
Config.update('gps', config)
pt = GPS.getPoint()
pt.heading = heading
turtle.setPoint(pt, true)
turtle.gotoPoint(config.home)
end
end
2016-12-11 19:24:52 +00:00
end
end