ksaw000

JointStartup

Jul 4th, 2026 (edited)
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. local cfg = require("config")
  2.  
  3. rednet.open(cfg.modem)
  4. rednet.host(cfg.prefix .. "joint", cfg.prefix .. cfg.hostname)
  5.  
  6. local gear = peripheral.wrap(cfg.gearshift)
  7.  
  8. local function execute(sender, delta)
  9. if math.abs(delta) < 0.2 then
  10. return
  11. end
  12.  
  13. gear.setInstructions({
  14. {
  15. type = "turn_angle",
  16. value = math.abs(delta),
  17. speed_modifier = delta >= 0 and 1 or -1
  18. },
  19. {
  20. type = "end"
  21. }
  22. })
  23.  
  24. gear.start()
  25.  
  26. while gear.isRunning() do
  27. sleep(0)
  28. end
  29.  
  30. rednet.send(
  31. sender,
  32. {
  33. type = "done",
  34. joint = cfg.hostname,
  35. delta = delta
  36. },
  37. cfg.prefix .. ".joint.done"
  38. )
  39. end
  40.  
  41. while true do
  42. local sender, msg, protocol = rednet.receive(nil)
  43.  
  44. if protocol == cfg.prefix .. ".joint.command"
  45. and msg.type == "turn" then
  46. execute(sender, msg.delta)
  47. end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment