Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot = require("robot")
- local comp = require("computer")
- local mod = require("component").modem
- --local file = require("component").filesystem
- local event = require("event")
- local shell = require('shell')
- local fRun = true
- local size = 9
- local cardID = ""
- local status = "wait"
- function round2(num, numDecimalPlaces)
- return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
- end
- function readcardID()
- cardID = "97b51251-7036-4a13-a303-92f7dcf0a83a"
- end
- function harvest()
- status="harvest"
- -- fly to start
- robot.forward()
- for y=1, size do
- -- harvest one line
- robot.swingDown()
- robot.useDown()
- robot.placeDown()
- for x=1, (size-1) do
- robot.forward()
- robot.swingDown()
- robot.useDown()
- robot.placeDown()
- end
- -- turn
- if y%2 == 1 then
- robot.turnLeft()
- robot.forward()
- robot.turnLeft()
- else
- robot.turnRight()
- robot.forward()
- robot.turnRight()
- end
- end
- -- return
- for y=1, (size-1) do
- robot.forward()
- end
- robot.turnLeft()
- for y=1, (size) do
- robot.forward()
- end
- robot.turnRight()
- robot.forward()
- robot.turnAround()
- end
- function unload()
- robot.turnAround()
- for c = 2, 16 do
- robot.select(c)
- if robot.count() > 0 then
- robot.drop()
- else
- robot.select(1)
- break
- end
- end
- robot.turnAround()
- end
- function onChatMessage(...)
- local fOwner = false;
- local com = ""
- for n,arg in ipairs({...}) do
- if n==3 then
- print("src:"..arg.."!")
- if arg==cardID then
- print("Owner")
- fOwner=true
- end
- end
- if n==6 then
- print("com:"..arg)
- com = arg
- end
- end
- if fOwner==true then
- if com=="status" then
- print("ok")
- mod.broadcast(225, status)
- end
- if com=="exit" then
- mod.broadcast(225, 'ok')
- fRun=false
- os.exit()
- end
- else
- --fRun=false
- print("no owner signal")
- --os.exit()
- end
- end
- readcardID()
- --os.exit()
- mod.open(225)
- event.listen("modem_message", onChatMessage)
- while fRun==true do
- harvest()
- status="wait"
- if robot.count(2) == 64 then
- unload()
- end
- -- one hour sleeping
- for i=1, 3600 do
- if fRun==false then
- break
- end
- os.sleep(1)
- print(round2(1*i/36,2)..'%')
- end
- --
- end
- mod.close(225)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement