Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ SeedBreeder.lua
- Robot's running instructions
- For use in SkunkWorks AgriCraft Seed Breeder
- Version 1.3
- ]]
- --[[ SETUP
- Place three blocks of appropriate soil in a line. Hoe if necessary.
- On the blocks next to and above the soil - next to where the crop sticks will
- go - place a line of three seed analyzers.
- The following directions will be written from the perspective of someone
- standing on the central soil block, facing the analyzers:
- *On top of the left-hand analyzer, place a container of crop sticks. This
- should either contain a very large number or be automatically restocked in
- some manner.
- *On top of the right-hand analyzer, place a container for surplus, non-maxed
- seeds. These should be disposed of before the container fills up, e.g. an XU
- trash can, TE nullifier, Garden Stuff compost bin, dropper over lava...
- *Two blocks FORWARD and 1 block off the ground, place a container for crops
- obtained during the breeding process. This too should be kept from filling.
- *Two blocks to the LEFT and one block off the ground, place a container
- holding the seeds to be bred up.
- *Two blocks to the RIGHT and one block off the ground, place a container for
- fully-bred seeds. As with the others, keep it from overfilling.
- The robot requires an inventory upgrade, inventory controller upgrade, and
- wireless modem, therefore it must be in at least a tier 2 case.
- A computer should be attached to the analyzers which is equipped with a
- wireless network card or attached
- Place the robot 1 block off the ground, in the space just used as a reference.
- It should face the analyzers, with empty space to its front, left, and right,
- and have an active charger positioned behind or above it. It will spend most
- of its time in this spot. If playing with weeds enabled, place a handrake
- in the 16th slot of the robot's inventory - the lower right slot if only 1
- inventory upgrade is installed.
- Crop sticks can be placed in slot 1 of the inventory, however take care not
- to overfill this slot, as it must have room to collect the sticks from any
- harvested crops in the breeding process. Other slots should be empty.
- Install Lua boot environments, then install this file on the robot and
- "FarmRemote.lua" on the analyzer computer by whatever means is convenient.
- I have attempted to supply default configuration options that will work, but
- if you are using several within transmission range of each other, or if these
- values would interfere with other wireless equipment, edit the variables in
- the CONFIGURATION section appropriately.
- No two installations should use the same CommandPort if they could possibly
- detect one another.
- The CommandPort and SignalStr values should match on both ends.
- Pay careful attention to the "AnaSide" variable on the remote program.
- It must be set to match your own configuration.
- Once all configuration is complete, run "SeedRemote.lua" on the
- analyzer computer, then stand clear of the robot and run this file.
- ]]
- -- CONFIGURATION --
- -- Wireless settings - these should match those on the host computer
- CommandPort=9090 -- Network port used to send/receive commands
- local SignalStr=100 -- Wireless signal strength
- -- END CONFIGURATION --
- -- FUNCTION DEFINITIONS --
- function netSend (msg)
- wNet.broadcast(CommandPort, msg)
- end
- function netListen (timeout)
- if timeout then -- Was a timeout value passed? Used for handshake
- local _, _, _, _, _, msg = event.pull(timeout, "modem")
- return msg
- else -- Unlimited time, for main sequence
- local _, _, _, _, _, msg = event.pull("modem")
- return msg
- end
- end
- function harvestMid() -- Dig up whatever's in the middle plot, below
- robot.select(1) -- Ensure cropsticks get stacked
- robot.swingDown()
- end
- function harvestRight() -- Move to and harvest the right-hand plot
- robot.turnRight()
- robot.forward()
- robot.select(1)
- robot.swingDown()
- robot.back()
- robot.turnLeft()
- end
- function harvestLeft() -- As above but for the left plot
- robot.turnLeft()
- robot.forward()
- robot.select(1)
- robot.swingDown()
- robot.back()
- robot.turnRight()
- end
- --checkCropSticks should only be executed when the robot is already moved
- --forward, next to the crop-sticks input container
- function checkCropSticks() --Check count in the "cropstick" slot
- robot.select(1)
- if robot.count(1) < 20 then -- Need to grab more crop sticks
- print "Low on cropsticks, replenishing..."
- robot.turnLeft()
- robot.suck(20) -- Keep a working range of 20-40, avoid overfilling
- robot.turnRight()
- end
- end
- function stackName ( slot) -- Shorthand for lowercase stack name in a slot
- if robot.count(slot) > 0 then
- return string.lower(iCont.getStackInInternalSlot(slot).name)
- else return nil end
- end
- function moveSeed() -- Searches pickups for a seed, moves it to slot 13
- local seedFound = false
- for i=2, 12 do
- if string.find(stackName(i),"seed") then
- robot.select(i)
- robot.transferTo(13)
- seedFound=true
- break
- end
- end
- if not seedFound then print "ERROR: No seed found!" end
- end
- function deliverSeed() -- Deliver the current "active seed" for analysis
- robot.forward()
- robot.select(13)
- robot.dropDown()
- end -- Robot will remain in place for the analysis
- function dumpStuff() -- Clear the misc inventory space of any dropped items
- robot.forward()
- for i=2, 12 do
- if robot.count(i) > 0 then -- If the slot is not empty...
- robot.select(i)
- if string.find(stackName(i),"seed") then -- Surplus seed
- robot.turnRight() -- Face the "surplus seeds" box
- robot.drop()
- robot.turnLeft()
- else -- Harvested crops
- robot.drop()
- end
- end
- end
- checkCropSticks() -- Since we're here...
- robot.back()
- end
- function retrieveSeed() -- Pick up analyzed seed
- checkCropSticks() -- Stock up while we're moved forward if necessary
- robot.select(13) -- Ensure it goes to the seed slot
- robot.suckDown()
- robot.back()
- end
- function plantLeft() -- Plant the current seed in the left plot
- robot.turnLeft()
- robot.forward()
- robot.select(1) -- Crop sticks
- iCont.equip()
- robot.useDown()
- iCont.equip() -- Put the crop sticks back in inventory
- robot.useDown() -- A single use makes cross crops, grab the spare stick
- robot.select(13) -- Active seed
- iCont.equip()
- robot.useDown() -- Plant the seed, should only have one
- robot.back()
- robot.turnRight()
- end
- function plantRight() -- As above but for the right
- robot.turnRight()
- robot.forward()
- robot.select(1) -- Crop sticks
- iCont.equip()
- robot.useDown()
- iCont.equip() -- Put the crop sticks back in inventory
- robot.useDown() -- A single use makes cross crops, grab the spare stick
- robot.select(13) -- Active seed
- iCont.equip()
- robot.useDown() -- Plant the seed, should only have one
- robot.back()
- robot.turnLeft()
- end
- function crossMid() -- Place cross crops
- robot.select(1) -- Crop sticks
- iCont.equip()
- robot.useDown() -- A single use places cross crops
- iCont.equip() -- Put the sticks back in inventory
- end
- function waitForFix() -- Wait for the user to change something
- os.sleep(1) -- Buffer period to make sure this doesn't immediately go off
- print("Press a key to retry...")
- event.pull("key") -- Wait for a keyboard event
- end
- --EXPERIMENTAL: Program was not developed with weeds active!
- --Only the middle plot should ever have a chance to grow weeds
- function removeWeeds() -- Rake weeds until they're gone
- local hasWeeds = true -- Control variable
- robot.select(16) -- Handrake
- iCont.equip()
- repeat -- Weed multiple times if necessary
- robot.useDown()
- netSend("CheckMidWeeds")
- if netListen() == "HasNoWeeds" then hasWeeds=false end
- until not hasWeeds
- iCont.equip() -- Put the handrake away
- end
- function getNextSeed() -- Fetch the next seed for breeding up
- local gotSeed=false
- robot.turnLeft()
- robot.forward()
- robot.select(13)
- if robot.suck() then gotSeed=true end -- Successful
- robot.back()
- robot.turnRight()
- if not gotSeed then
- print "No seeds found! Insert seeds for breeding."
- waitForFix()
- end
- return gotSeed
- end
- function doneWithSeed() -- Deliver the active seed as finished
- robot.turnRight()
- robot.forward()
- robot.select(13)
- robot.drop()
- robot.back()
- robot.turnLeft()
- end
- function waitForMid() -- Wait for the middle crop to sprout, clear any weeds
- local midStat="Empty"
- repeat
- midStat=netListen()
- if midStat=="HasWeeds" then
- print("WARNING! Weeds detected! Raking...")
- removeWeeds()
- local cropSticks=robot.count(1)
- print("Weeds cleared. Current cropsticks: "..cropSticks)
- if cropSticks < 20 then
- print "Fetching more cropsticks..."
- robot.forward() -- Special case since the robot won't
- robot.turnLeft() -- already be moved forward
- robot.select(1)
- robot.suck(20)
- robot.turnRight()
- robot.back()
- print "Cropsticks replenished."
- end
- print "Replacing cross crop."
- robot.select(1)
- iCont.equip()
- robot.useDown()
- iCont.equip()
- print "Continuing to wait..."
- end
- until midStat=="HasPlant"
- end
- -- END FUNCTION DEFINITIONS --
- local version="1.3"
- event = require("event")
- component = require("component")
- robot = require("robot")
- wNet = component.proxy(component.modem.address)
- iCont = component.proxy(component.inventory_controller.address)
- print("---------------------------------------------")
- print("SkunkWorks Logistics - AgriCraft Seed Breeder")
- print("Robot/main control program")
- print("Version "..version)
- print("---------------------------------------------")
- wNet.setStrength(SignalStr)
- wNet.close()
- wNet.open(CommandPort)
- print("Communicating on port "..CommandPort.." with power "..SignalStr)
- print("Attempting handshake with analyzer control station.")
- handshake=false -- Control to break out of the handshake loop
- while true do
- for i=1, 10 do
- netSend("Handshake")
- local thisMsg=netListen(10) or "<no response>"
- print("Try "..i.. " of 10: "..thisMsg)
- if thisMsg=="Confirm" then
- print "Success!"
- handshake=true
- break
- end
- end
- if handshake then break end
- print("Handshake failed! Is the computer running?")
- waitForFix()
- end
- handshake=nil
- while true do -- Main sequence starts here
- repeat
- print "Fetching next seed."
- until getNextSeed()
- deliverSeed()
- print "Analyzing new seed..."
- netSend("Analyze")
- seedSum=netListen()
- if seedSum==30 then -- Seed already maxed?
- print("Seed already at max stats!")
- retrieveSeed()
- doneWithSeed()
- else -- Begin main breeding cycle
- print("Seed stat total: "..seedSum)
- print("Planting in LEFT patch.")
- retrieveSeed()
- plantLeft()
- leftSum=seedSum
- netSend("GrowLeft")
- print("Waiting for growth...")
- repeat until netListen() == "LeftGrown" -- Wait for plant to grow
- print("Left patch grown!")
- print("Placing cross crops.")
- crossMid() -- Place cross crops to get duplicate seed
- netSend("WatchMid")
- print("Waiting for sprout...")
- waitForMid()
- print "Sprout detected! Collecting."
- harvestMid()
- moveSeed()
- deliverSeed()
- netSend("Analyze")
- print "Analyzing seed..." -- This should be a clone of a non-max seed
- seedSum = netListen() -- But let's check it again just in case
- retrieveSeed()
- print "Planting in RIGHT plot."
- plantRight()
- rightSum=seedSum
- print "Waiting for growth..."
- netSend("GrowRight")
- repeat until netListen() == "RightGrown"
- print "Right patch grown!"
- nextPlot = "LEFT" -- Which side will we be replacing next? Alternate
- while true do -- Main breeding routine starts here
- print "Placing cross crops."
- crossMid()
- netSend("WatchMid")
- waitForMid()
- print "Sprout detected! Collecting."
- harvestMid()
- moveSeed()
- deliverSeed()
- netSend("Analyze")
- print "Analyzing seed..."
- local sumNew = netListen()
- print ("Total seed values: "..sumNew)
- if sumNew == 30 then -- Seed's done!
- print "Seed fully bred! Delivering and cleaning up..."
- retrieveSeed()
- doneWithSeed()
- harvestLeft() -- Clear the soil
- harvestRight()
- dumpStuff() -- Drop off the spare seeds & harvested stuff
- break
- elseif nextPlot=="LEFT" then
- print ("Total in LEFT plot: "..leftSum)
- if sumNew > leftSum then -- Seed has improved
- print "Replacing LEFT seed..."
- retrieveSeed()
- harvestLeft() -- Selects 1. The new seed is still in 13
- plantLeft()
- leftSum = sumNew
- print "Clearing inventory..."
- dumpStuff() -- Drop off the old seed & harvested stuff
- nextPlot="RIGHT" -- Switch sides for next time
- netSend("GrowLeft")
- print "Waiting for new seed to grow..."
- repeat until netListen() == "LeftGrown"
- else -- Seed hasn't improved, dump it
- print "New seed is not an improvement. Discarding..."
- robot.suckDown()
- robot.turnRight()
- robot.drop()
- robot.turnLeft()
- checkCropSticks()
- robot.back()
- end -- comparing to left seed
- elseif nextPlot=="RIGHT" then
- print ("Total in RIGHT plot: "..rightSum)
- if sumNew > rightSum then -- Seed has improved
- print "Replacing RIGHT seed..."
- retrieveSeed()
- harvestRight() -- Selects 1. The new seed is still in 13
- plantRight()
- rightSum = sumNew
- print "Clearing inventory..."
- dumpStuff() -- Drop off the old seed & harvested stuff
- nextPlot="LEFT" -- Switch sides for next time
- netSend("GrowRight")
- print "Waiting for new seed to grow..."
- repeat until netListen() == "RightGrown"
- else -- Seed hasn't improved, dump it
- print "New seed is not an improvement. Discarding..."
- robot.suckDown()
- robot.turnRight()
- robot.drop()
- robot.turnLeft()
- checkCropSticks()
- robot.back()
- end -- comparing to right seed
- else -- Shouldn't happen
- print "ERROR: nextPlot was unassigned! Picking LEFT"
- print ("Total in LEFT plot: "..leftSum)
- if sumNew > leftSum then -- Seed has improved
- print "Replacing LEFT seed..."
- retrieveSeed()
- harvestLeft() -- Selects 1. The new seed is still in 13
- plantLeft()
- leftSum = sumNew
- print "Clearing inventory..."
- dumpStuff() -- Drop off the old seed & harvested stuff
- nextPlot="RIGHT" -- Pick a side for next time
- netSend("GrowLeft")
- print "Waiting for new seed to grow..."
- repeat until netListen() == "LeftGrown"
- else -- Seed hasn't improved, dump it
- print "New seed is not an improvement. Discarding..."
- robot.suckDown()
- robot.turnRight()
- robot.drop()
- robot.turnLeft()
- checkCropSticks()
- robot.back()
- end -- comparing to left seed
- end -- End inspecting new seed
- end -- main breeding sequence
- end -- processing new seed
- end -- main loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement