SHARE
TWEET

[OpenComputers] cart

Doob Jun 15th, 2015 (edited) 263 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local position = 'back'
  2. local r = require('robot')
  3. local component = require('component')
  4. local event = require("event")
  5.  
  6. local function goF() -- курсовой робот
  7.   r.swing()
  8.   r.placeDown()
  9.   r.forward()
  10.   r.placeDown()
  11.   r.swingUp()
  12. end
  13.  
  14. local function goB() -- кормовой, с поршнем
  15.   component.piston.push()
  16.   r.forward()
  17.   r.swingDown()
  18. end
  19.  
  20. local function inverter(side, x) -- инвертер функций
  21.   if x == true then
  22.     if side == 'left' then
  23.       r.turnLeft()
  24.     elseif side == 'right' then
  25.       r.turnRight()
  26.     end
  27.   elseif x == false then
  28.     if side == 'left' then
  29.       r.turnRight()
  30.     elseif side == 'right' then
  31.       r.turnLeft()
  32.     end
  33.   end
  34. end
  35.  
  36. local function turnF(side) -- поворотник курсового
  37.   r.swingUp()
  38.   inverter(side, true)
  39.   r.swing()
  40.   os.sleep(0.4)
  41.   r.forward()
  42.   inverter(side, true)
  43.   r.swing()
  44.   os.sleep(0.4)
  45.   r.forward()
  46.   inverter(side, false)
  47.   r.swingUp()
  48. end
  49.  
  50. local function turnB(side) -- поворотник кормового
  51.   r.swing()
  52.   inverter(side, false)
  53.   for i = 1, 2 do
  54.     r.swing()
  55.     os.sleep(0.4)
  56.     r.forward()
  57.   end
  58.   inverter(side, true)
  59.   for j = 1, 2 do
  60.     r.swing()
  61.     os.sleep(0.4)
  62.     r.forward()
  63.   end
  64.   inverter(side, true)
  65.   r.place()
  66. end
  67.  
  68. tArgs = {...}
  69. if position == 'front' then
  70.   if tArgs[1] == 'go' then
  71.     for k = 1, tArgs[2] do
  72.       goF()
  73.       component.modem.broadcast(100, 'go')
  74.     end
  75.   elseif tArgs[1] == 'turn' then
  76.     turnF(tArgs[2])
  77.     component.modem.broadcast(100, tArgs[2])
  78.   end
  79. elseif position == 'back' then
  80.   r.place()
  81.   component.modem.open(100)
  82.   while true do
  83.     local _, _, _, _, _, msg = event.pull("modem_message")
  84.     if msg == 'go' then
  85.       goB()
  86.     else
  87.       turnB(msg)
  88.     end
  89.   end
  90. end
  91.  
  92. --usage: <cart go number> <cart turn left> <cart turn right>
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