Silasko

phone ping

Dec 3rd, 2020 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. function phone_pingGPS()
  2.     rednet.open("back")
  3.         rednet.broadcast("ping")
  4.         id,message = rednet.receive()
  5.         print("Device "..id..": ")
  6.         print(message)
  7.         data = parseParams(message)
  8.         print(coords[1])
  9.         getTurtleHeading()
  10.        
  11. end
  12.  
  13.  
  14. function split (inputstr, sep)
  15.     if sep == nil then
  16.             sep = "%s"
  17.     end
  18.     local t={}
  19.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  20.             table.insert(t, str)
  21.     end
  22.     return t
  23. end
  24.  
  25. function parseParams(data)
  26.     coords = {}
  27.     params = split(data, ",")
  28.    
  29.     coords[1] = vector.new(params[1], params[2], params[3])
  30.     coords[2] = vector.new(params[4], params[5], params[6])
  31.     coords[3] = vector.new(params[7], params[8], params[9])
  32.  
  33.     return (coords)
  34. end
  35.  
  36. function getTurtleHeading()
  37.     local a = vector.new(gps.locate())
  38.     print("Caller pos: ",math.floor(a.x),",",math.floor(a.y),",",math.floor(a.z))
  39.     print("Turtle pos: ",coords[1])
  40.     local c = a - coords[1]
  41.  
  42.     print("Difference in positions: ",math.floor(c.x),",",math.floor(c.y),",",math.floor(c.z)))
  43.     if c.x < 0 then
  44.         print("Turtle to East")
  45.     else
  46.         print("Turtle to West")
  47.     end
  48.     if c.z < 0 then
  49.         print("Turtle to South")
  50.     else
  51.         print("Turtle to North")
  52.     end
  53. end
  54.  
  55. phone_pingGPS()
Add Comment
Please, Sign In to add comment