Advertisement
osmarks

NI position approximator

Jun 12th, 2021 (edited)
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.56 KB | None | 0 0
  1. local iface = peripheral.wrap "back"
  2. local x, y, z = gps.locate()
  3.  
  4. local approx = y
  5. local function do_approx()
  6.     local past_time = os.epoch "utc"
  7.     while true do
  8.         local time = os.epoch "utc"
  9.         local diff = (time - past_time) / 1000
  10.         past_time = time
  11.         local meta = iface.getMetaByName "gollark"
  12.         approx = approx + (meta.motionY * diff)
  13.         sleep()
  14.     end
  15. end
  16.  
  17. local function do_gps()
  18.     while true do
  19.         local x, y, z = gps.locate()
  20.         print("real=", y, "\napprox=", approx, "\ndiff=", y - approx)
  21.         sleep(0.5)
  22.     end
  23. end
  24.  
  25. parallel.waitForAll(do_approx, do_gps)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement