Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function phone_pingGPS()
- rednet.open("back")
- rednet.broadcast("ping")
- id,message = rednet.receive()
- print("Device "..id..": ")
- print(message)
- data = parseParams(message)
- print(coords[1])
- getTurtleHeading()
- end
- function split (inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function parseParams(data)
- coords = {}
- params = split(data, ",")
- coords[1] = vector.new(params[1], params[2], params[3])
- coords[2] = vector.new(params[4], params[5], params[6])
- coords[3] = vector.new(params[7], params[8], params[9])
- return (coords)
- end
- function getTurtleHeading()
- local a = vector.new(gps.locate())
- print("Caller pos: ",math.floor(a.x),",",math.floor(a.y),",",math.floor(a.z))
- print("Turtle pos: ",coords[1])
- local c = a - coords[1]
- print("Difference in positions: ",math.floor(c.x),",",math.floor(c.y),",",math.floor(c.z)))
- if c.x < 0 then
- print("Turtle to East")
- else
- print("Turtle to West")
- end
- if c.z < 0 then
- print("Turtle to South")
- else
- print("Turtle to North")
- end
- end
- phone_pingGPS()
Add Comment
Please, Sign In to add comment