Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cfg = require("config")
- rednet.open(cfg.modem)
- rednet.host(cfg.prefix .. "joint", cfg.prefix .. cfg.hostname)
- local gear = peripheral.wrap(cfg.gearshift)
- local function execute(sender, delta)
- if math.abs(delta) < 0.2 then
- return
- end
- gear.setInstructions({
- {
- type = "turn_angle",
- value = math.abs(delta),
- speed_modifier = delta >= 0 and 1 or -1
- },
- {
- type = "end"
- }
- })
- gear.start()
- while gear.isRunning() do
- sleep(0)
- end
- rednet.send(
- sender,
- {
- type = "done",
- joint = cfg.hostname,
- delta = delta
- },
- cfg.prefix .. ".joint.done"
- )
- end
- while true do
- local sender, msg, protocol = rednet.receive(nil)
- if protocol == cfg.prefix .. ".joint.command"
- and msg.type == "turn" then
- execute(sender, msg.delta)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment