1
0
mirror of https://github.com/kepler155c/opus synced 2025-02-06 20:20:03 +00:00
opus/sys/extensions/tgps.lua

59 lines
1.2 KiB
Lua
Raw Normal View History

2017-09-05 21:21:43 -04:00
if not turtle or turtle.enableGPS then
2016-12-11 14:24:52 -05:00
return
end
requireInjector(getfenv(1))
local GPS = require('gps')
local Config = require('config')
2016-12-11 14:24:52 -05:00
2017-05-24 19:48:48 -04:00
function turtle.enableGPS(timeout)
2017-07-30 19:53:43 -04:00
if turtle.point.gps then
2017-05-24 19:48:48 -04:00
return turtle.point
end
local pt = GPS.getPointAndHeading(timeout)
2016-12-11 14:24:52 -05:00
if pt then
2017-07-23 22:37:07 -04:00
turtle.setPoint(pt, true)
return turtle.point
2016-12-11 14:24:52 -05:00
end
end
function turtle.gotoGPSHome()
local config = { }
Config.load('gps', config)
if config.home then
2017-05-24 19:48:48 -04:00
if turtle.enableGPS() then
turtle.pathfind(config.home)
2016-12-11 14:24:52 -05:00
end
end
end
function turtle.setGPSHome()
local config = { }
Config.load('gps', config)
2017-09-18 14:46:46 -04:00
if turtle.point.gps then
config.home = turtle.point
Config.update('gps', config)
2017-09-18 14:46:46 -04: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 14:24:52 -05:00
end
end