Created
June 14, 2024 23:29
-
-
Save Hri7566/f66daa5a6cb08f495bfca70fcd5de873 to your computer and use it in GitHub Desktop.
create gantry crane computercraft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- libgantry | |
-- Crane control library | |
-- by Hri7566 | |
-- Crane designed by Khorne_The_Proto | |
local gantry = {} | |
local bn = nil | |
local gs = nil | |
local red = nil | |
local blue = nil | |
function gantry:setup(bunkernet, sequenced_gearshift, red, blue, gearshift) | |
bn = bunkernet | |
gs = sequenced_gearshift | |
red_side = red | |
blue_side = blue | |
gearshift_side = gearshift | |
end | |
function gantry:move(num) | |
gs.move(num) | |
end | |
function gantry:red(enabled) | |
-- Set red dye output | |
rs.setOutput("right", enabled) | |
end | |
function gantry:blue(enabled) | |
-- Set blue dye output | |
rs.setOutput("top", enabled) | |
end | |
function gantry:setDirection(dir) | |
-- Set motor direction | |
rs.setOutput("back", dir) | |
end | |
function gantry:breakRope() | |
bn:send({ | |
m = "big_crane_break" | |
}) | |
os.sleep(5) | |
end | |
function gantry:waitForDumbass() | |
while gs.isRunning() do | |
os.sleep(0.2) | |
end | |
end | |
function gantry:selectWinch() | |
self:red(true) | |
self:blue(true) | |
self:setDirection(true) | |
os.sleep(0.2) | |
end | |
function gantry:selectX() | |
self:red(false) | |
self:blue(true) | |
self:setDirection(true) | |
os.sleep(0.2) | |
end | |
function gantry:selectZ() | |
self:red(false) | |
self:blue(false) | |
self:setDirection(false) | |
os.sleep(0.2) | |
end | |
function gantry:moveWinch(num) | |
self:selectWinch() | |
if num < 0 then | |
-- Up | |
self:setDirection(false) | |
else | |
-- Down | |
self:setDirection(true) | |
end | |
self:move(math.abs(num)) | |
os.sleep(num / 10) | |
end | |
function gantry:moveX(num) | |
self:selectX() | |
if num < 0 then | |
-- Left | |
self:setDirection(false) | |
else | |
-- Right | |
self:setDirection(true) | |
end | |
self:move(math.abs(num)) | |
self:waitForDumbass() | |
end | |
function gantry:moveZ(num) | |
self:selectZ() | |
if num < 0 then | |
-- Forward | |
self:setDirection(true) | |
else | |
-- Back | |
self:setDirection(false) | |
end | |
self:move(math.abs(num)) | |
self:waitForDumbass() | |
end | |
function gantry:reset() | |
-- Reset crane position | |
-- Break winch rope | |
gantry:breakRope() | |
gantry:moveX(-25) | |
gantry:moveZ(-25) | |
end | |
return gantry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment