Advertisement
guitarplayer616

[GPS] schem turtle

Nov 25th, 2016
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. --setup gps: pastebin get qLthLak5 gps-deploy, gps-deploy x y z height
  2.  
  3.  
  4. function gpsSetup()
  5.     if gps.locate() then
  6.         gpsi = true
  7.         origDir = calibrateDir()
  8.         local h,k,l = gps.locate()
  9.         local k = k + 1
  10.         Hoff,Koff,Loff = h,k,l
  11.         Hoff = math.floor(Hoff)
  12.         Koff = math.floor(Koff)
  13.         Loff = math.floor(Loff)
  14.     else
  15.         origDir = "south"
  16.     end
  17. end
  18.  
  19. function openRednet()
  20.     for _,v in ipairs(peripheral.getNames()) do
  21.             if peripheral.getType(v)=="modem" then
  22.                     rednet.open(v)
  23.             end
  24.     end
  25. end
  26.  
  27.  
  28. function resynchronize()
  29.     if gpsi then
  30.         recalibratePos()
  31.         face = calibrateDir()
  32.         recalibrateFace()
  33.         recordPos(heightPos,widthPos,lengthPos,face)
  34.     end
  35. end
  36.  
  37. function calibrateDir()
  38.     --if gpsi then
  39.         local dir
  40.         local h,k,l = gps.locate()
  41.         h = math.floor(h)
  42.         k = math.floor(k)
  43.         l = math.floor(l)
  44.         while not turtle.forward() do
  45.             turtle.dig()
  46.         end
  47.         local h2,k2,l2 = gps.locate()
  48.         turtle.back()
  49.         if h2>h then
  50.             dir = "east"
  51.         elseif h2<h then
  52.             dir = "west"
  53.         elseif l2>l then
  54.             dir = "south"
  55.         elseif l2<l then
  56.             dir = "north"
  57.         end
  58.         return dir
  59.     --end
  60. end
  61.  
  62. function recalibratePos()
  63.     local h,k,l = gps.locate()
  64.     local xtemp,ytemp,ztemp  = h - Hoff, k - Koff, l - Loff
  65.  
  66.     if origDir == "south" then
  67.         widthPos = 0 + xtemp  
  68.         heightPos = ytemp
  69.         lengthPos = 0 + ztemp
  70.     elseif origDir == "north" then
  71.         widthPos = 0 - xtemp
  72.         heightPos = ytemp
  73.         lengthPos = 0 - ztemp
  74.     elseif origDir == "east" then
  75.         widthPos = 0  - ztemp
  76.         heightPos = ytemp
  77.         lengthPos = 0  + xtemp
  78.     elseif origDir == "west" then
  79.         widthPos = 0 + ztemp
  80.         heightPos = ytemp
  81.         lengthPos = 0 - xtemp
  82.     end
  83.  
  84. end
  85.  
  86. function recalibrateFace()
  87.     if origDir ~= "south" then
  88.         if origDir == "north" then
  89.             update("right")
  90.             update("right")
  91.         elseif origDir == "east" then
  92.             update("right")
  93.         elseif origDir == "west" then
  94.             update("left")
  95.         end
  96.     end
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement