Advertisement
minuslinus

basic gps program

Mar 28th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. local arg = { ... }
  2. local xcord=tonumber(arg[1])
  3. local ycord=tonumber(arg[2])
  4. local zcord=tonumber(arg[3])
  5.  
  6. if  arg[1]==nil
  7.     or
  8.     arg[2]==nil
  9.     or
  10.     arg[3]==nil then
  11.     print("gps <x> <y> <z>")
  12.     return
  13. end
  14.  
  15. function locate()
  16.     g = vector.new(gps.locate(2))
  17.     turtle.forward()
  18.     g2 = vector.new(gps.locate(2))
  19.     turtle.back()
  20.     if g.x == g2.x then
  21.         if g.y > g2.y then
  22.             turtle.turnLeft()
  23.             turtle.turnLeft()
  24.         end
  25.     else
  26.         if g.x > g2.x then
  27.             turtle.turnLeft()
  28.         else
  29.             turtle.turnRight()
  30.         end
  31.     end
  32. end
  33.  
  34. function calc()
  35.     xmove = xcord - g.x
  36.     if xmove < 0 then xmove=xmove*(-1) end
  37.     ymove = ycord - g.y
  38.     if ymove < 0 then ymove=ymove*(-1) end
  39.     zmove = zcord - g.z
  40.     if zmove < 0 then zmove=zmove*(-1) end
  41. end
  42.    
  43. function move()
  44.     if xcord ~= g.x then
  45.         if xcord < g.x then
  46.             turtle.turnRight()
  47.             for i=1,xmove do
  48.                 turtle.forward()
  49.             end
  50.             turtle.turnLeft()
  51.         else
  52.             turtle.turnLeft()
  53.             for i=1,xmove do
  54.                 turtle.forward()
  55.             end
  56.             turtle.turnRight()
  57.         end
  58.     end
  59.     if ycord ~= g.y then
  60.         if ycord > g.y then
  61.             for i=1,ymove do
  62.                 turtle.forward()
  63.             end
  64.         else
  65.             turtle.turnLeft()
  66.             turtle.turnLeft()
  67.             for i=1,ymove do
  68.                 turtle.forward()
  69.             end
  70.             turtle.turnLeft()
  71.             turtle.turnLeft()
  72.         end
  73.     end
  74.     if zcord ~= g.z then
  75.         if zcord < g.z then
  76.             for i=1,zmove do
  77.                 turtle.down()
  78.             end
  79.         else
  80.             for i=1,zmove do
  81.                 turtle.up()
  82.             end
  83.         end
  84.     end
  85. end
  86.  
  87. locate()
  88. calc()
  89. move()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement