SHARE
TWEET

rtool

a guest Nov 9th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local robot = component.robot
  3. local nav = component.navigation
  4. local sides = require("sides")
  5.  
  6. local RTool = {}
  7.  
  8. function RTool.getWaypoints(dist)
  9.   points = nav.findWaypoints(dist)
  10.   return points
  11. end
  12.  
  13. function RTool.dispWaypoint(t)
  14.   print("label : "..t.label)
  15.   print("redstone : "..tostring(t.redstone))
  16.   print("position")
  17.   print(tostring(t.position[1])..","
  18.         ..tostring(t.position[2])..","
  19.         ..tostring(t.position[3]))
  20. end
  21.  
  22. function RTool.getShortestPoint(points)
  23.   local index = 1
  24.   local lengs = {}
  25.   for i=1, #points do
  26.     x = points[i].position[1]
  27.     y = points[i].position[2]
  28.     z = points[i].position[3]
  29.     lengs[i] = x*x + y*y + z*z
  30.   end
  31.  
  32.   for j=1, #lengs do
  33.     if(lengs[index] > lengs[j]) then
  34.       index = j
  35.     end
  36.   end
  37.  
  38.   return index
  39. end
  40.  
  41. function RTool.turnToSide(side)
  42.   while true do
  43.     if nav.getFacing() == side then
  44.       break;
  45.     else
  46.       robot.turn(true)
  47.     end
  48.   end
  49. end
  50.  
  51. function RTool.moveToX(X)
  52.   local isPos = true
  53.  
  54.   if X<0 then
  55.     isPos = false
  56.     X = X*(-1)
  57.   end
  58.  
  59.   if isPos == true then
  60.     rtool.turnToSide(sides.posx)
  61.   else
  62.     rtool.turnToSide(sides.negx)
  63.   end
  64.  
  65.   for i=1,X do
  66.     robot.move(sides.front)
  67.   end
  68.  
  69. end
  70.  
  71. function RTool.moveToZ(Z)
  72.   local isPos = true
  73.  
  74.   if Z<0 then
  75.     isPos = false
  76.     Z = Z*(-1)
  77.   end
  78.  
  79.   if isPos == true then
  80.     rtool.turnToSide(sides.posz)
  81.   else
  82.     rtool.turnToSide(sides.negz)
  83.   end
  84.  
  85.   for i=1,Z do
  86.     robot.move(sides.front)
  87.   end
  88.  
  89. end
  90.  
  91. return RTool
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top