Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ SeedRemote.lua
- Analyzer monitoring remote program
- For use in SkunkWorks AgriCraft Seed Breeder
- Version 1.3 --]]
- --[[ This should be installed on a computer with a wireless network card,
- attached to three computer-controlled seed analyzers.
- For full setup details, see SeedBreeder.lua
- Once setup is complete, run this file FIRST, then run
- SeedBreeder.lua on the robot.
- A handshake process is included to allow for flexibility in load order,
- but especially in places with high network activity, it may fail if the
- robot's program is started first.]]
- -- CONFIGURATION --
- --[[ Ensure the wireless settings variables below match those on the robot.
- Also be sure to set "AnaSide" below them to whatever matches your own
- orientation, and set "AddrAnaLeft", "AddrAnaMid", and "AddrAnaRight" as
- the addresses of your respective seed analyzers.]]
- --Wireless settings - these should be identical to the robot's values
- CommandPort=9090 -- Network port used to receive commands
- local SignalStr=100 -- Wireless signal strength
- --SET ME - This indicates which side of the analyzers the soil is on
- --It should be one of "NORTH", "EAST", "SOUTH", or "WEST"
- --Note this is looking from the analyzer to the crops, NOT vice versa
- AnaSide=""
- --These should be filled in based on the addresses of your seed analyzers.
- --Left and right are based on robot's POV, standing over the crops,
- --looking at the analyzers, unlike AnaSide above.
- AddrAnaMid=""
- AddrAnaLeft=""
- AddrAnaRight=""
- --[[This is how long the computer will wait between attempts to look at the
- status of the middle crop plot. This is the only one that is allowed to sit
- empty for any length of time, and thus the only one that should be
- vulnerable to weeds. If soil + growth boosts mean that weeds aren't being
- caught in a timely fashion, decrease this value. If weeds are off, it can be
- safely increased to reduce load. --]]
- MidTimer=10
- --[[This is the time between checks for the side plots, which should not
- ever be vulnerable to weeds. If you have strong growth acceleration, you may
- want to turn this value down. --]]
- GrowTimer=20
- -- END CONFIGURATION --
- -- FUNCTION DEFINITIONS --
- function netSend (msg)
- wNet.broadcast(CommandPort, msg)
- end
- -- This station never expects an immediate response
- function netListen() -- Therefore, unlike the robot, it never needs a timeout
- local _, _, _, _, _, msg = event.pull("modem")
- return msg
- end
- function sumMid()
- if (not (AnaMid.isAnalyzed())) then
- print "Analyzing specimen..."
- AnaMid.analyze() -- Start the analysis
- repeat
- os.sleep(1) -- Give it a second...
- until (AnaMid.isAnalyzed()) -- then try again
- print "Analysis complete!"
- else print "Specimen already analyzed!" end
- local gro, gain, str = AnaMid.getSpecimenStats()
- return gro+gain+str
- end
- function watchMid()
- local midStat = "Empty"
- print "Monitoring middle plot..."
- while (midStat == "Empty") do
- os.sleep(midTimer)
- if (AnaMid.hasWeeds(AnaSide)) then
- midStat="HasWeeds"
- print "WARNING! Weeds detected!"
- elseif (AnaMid.hasPlant(AnaSide)) then
- midStat="HasPlant"
- print "Sprout detected!"
- end
- end
- return midStat
- end
- function checkMidWeeds()
- if (AnaMid.hasWeeds(AnaSide)) then
- print("Weeds still present!")
- netSend("HasWeeds")
- else
- print("Weeds cleared.")
- netSend("HasNoWeeds")
- end
- end
- function growLeft()
- print "Waiting for LEFT plot to grow..."
- while (not (AnaLeft.isMature(AnaSide))) do os.sleep(GrowTimer) end
- print "Done growing!"
- netSend("LeftGrown")
- end
- function growRight()
- print "Waiting for RIGHT plot to grow..."
- while (not (AnaRight.isMature(AnaSide))) do os.sleep(GrowTimer) end
- print "Done growing!"
- netSend("RightGrown")
- end
- -- END FUNCTION DEFINITIONS --
- -- Possible instructions --
- --[[
- "CheckMidWeeds" -> "HasWeeds" | "HasNoWeeds"
- "Handshake" -> "Confirm"
- "Analyze" -> sum
- "GrowLeft" -> "LeftGrown"
- "GrowRight" -> "RightGrown"
- "WatchMid" -> "HasWeeds" | "HasPlant"
- End possible instructions --]]
- local version="1.3"
- event = require("event")
- component = require("component")
- wNet = component.proxy(component.modem.address)
- AnaMid=component.proxy(AddrAnaMid)
- AnaLeft=component.proxy(AddrAnaLeft)
- AnaRight=component.proxy(AddrAnaRight)
- 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 "Listening for commands..."
- while true do -- Main loop
- local cmd = netListen()
- if (cmd=="Handshake") then
- print "Received handshake request! Sending confirmation."
- netSend("Confirm")
- elseif (cmd=="Analyze") then
- local sum=sumMid()
- print("Sending sum of analyzed seed data: "..sum)
- netSend(sum)
- elseif (cmd=="WatchMid") then
- netSend(watchMid())
- elseif (cmd=="CheckMidWeeds") then
- checkMidWeeds()
- elseif (cmd=="GrowLeft") then
- growLeft()
- elseif (cmd="GrowRight") then
- growRight()
- else
- print("Ignoring unrecognized command: "..cmd)
- end -- if cmd
- end -- main loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement