daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Dec 9th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. robot = require("robot")
  2. component = require("component")
  3. StartPositionX , StartPositionY , StartPositionZ = component.navigation.getPosition() -- where the robot is when program started
  4. DistX = "NCY"
  5. DistY = "NCY"--Not Calibrated Yet...
  6. DistZ = "NCY"
  7. Down = false
  8. while true do
  9.  CurrentPositionX , CurrentPositionY , CurrentPositionZ = component.navigation.getPosition() -- Where The Robot Currently Is
  10.  print("Current Position: ["..CurrentPositionX..", "..CurrentPositionY..", "..CurrentPositionZ.."]")
  11. end
  12.  
  13. function CheckDirection(Value1 , Value2 , Value3) -- Value1 : (Changing Value) , Value2 : (Value That Gets Compared To Value) , Value3 : X , Y , or Z
  14.     print("Checking Direction")
  15.  local loop = true
  16.  if Value3 == "X" then
  17.   while loop == true do
  18.    robot.forward()
  19.    Value1 = CurrentPositionX --To check if the dir is correct (E(+) , W(-))
  20.    if Value1 ~= Value2 then
  21.     loop = false
  22.     return true
  23.    elseif Value == Value2 then
  24.     robot.back()
  25.     robot.turnLeft()
  26.    end
  27.   end
  28.  elseif Value3 == "Y" then
  29.   while loop == true do
  30.    robot.up()
  31.    Value1 = CurrentPositionY --To check if the dir is correct (Up Or Down)
  32.    if Value1 ~= Value2 then
  33.     loop = false
  34.     return true
  35.    elseif Value == Value2 then
  36.     Down = true
  37.     robot.down()
  38.    end
  39.   end
  40.  elseif Value3 == "Z" then
  41.   while loop == true do
  42.    robot.forward()
  43.    Value1 = CurrentPositionZ --To check if the dir is correct (N(-) , S(+))
  44.    if Value1 ~= Value2 then
  45.     loop = false
  46.     return true
  47.    elseif Value == Value2 then
  48.     robot.back()
  49.     robot.turnLeft()
  50.    end
  51.   end
  52.  end
  53. end
  54.  
  55. function Goto_Origin_X(X)
  56.     print("Going to X")
  57.  if CheckDirection(CurrentPositionX , StartPositionX , "X") then
  58.   DistX = CurrentPositionX - StartPositionX
  59.   print("DistanceX: "..DistX)
  60.   for Count = 0 , DistX do
  61.    if robot.detect == false then
  62.     robot.forward()
  63.    elseif robot.detect() == true then
  64.     robot.up()
  65.    end
  66.   end
  67.   break
  68.  end
  69. end
  70.  
  71. function Goto_Origin_Y(Y)
  72.     print("Going To Y")
  73.  if CheckDirection(CurrentPositionY , StartPositionY , "Y") then
  74.   DistY = CurrentPositionY - StartPositionY
  75.   print("DistanceY: "..DistY)
  76.   for Count = 0 , DistY do
  77.    if robot.detect == false then
  78.     if Down == false then
  79.      robot.up()
  80.     else
  81.      robot.down()
  82.     end
  83.    elseif robot.detect() == true then
  84.     robot.up()
  85.    end
  86.   end
  87.   break
  88.  end
  89. end
  90.  
  91. function Goto_Origin_Z(Z)
  92.     print("Going To Z")
  93.  if CheckDirection(CurrentPositionZ , StartPositionZ , "Z") then
  94.   DistZ = CurrentPositionZ - StartPositionZ
  95.   print("DistanceZ: "..DistZ)
  96.   for Count = 0 , DistZ do
  97.    if robot.detect == false then
  98.     robot.forward()
  99.    elseif robot.detect() == true then
  100.     robot.up()
  101.    end
  102.   end
  103.   break
  104.  end
  105. end
  106.  
  107. Goto_Origin_X(CurrentPositionX)
  108. Goto_Origin_Y(CurrentPositionY)
  109. Goto_Origin_Z(CurrentPositionZ)
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