Guest User

Main

a guest
Aug 24th, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. peripheral.find("modem", rednet.open)
  2. print(os.getComputerID()) -- getID
  3.  
  4. local monitor = peripheral.find("monitor")
  5.  
  6. local back = peripheral.wrap("back")
  7. local front = peripheral.wrap("front")
  8. local left = peripheral.wrap("left")
  9. local right = peripheral.wrap("right")
  10.  
  11. -- Blade-specific pitch direction multipliers (for cyclic input)
  12. local pitchSign = {
  13. front = 1,
  14. back = 1,
  15. left = 1,
  16. right = 1
  17. }
  18.  
  19. -- Blade-specific collective pitch direction multipliers (corrected)
  20. local collectiveSign = {
  21. front = -1,
  22. back = 1,
  23. left = -1,
  24. right = 1
  25. }
  26.  
  27. -- Blade direction vectors (fixed in rotor space)
  28. local bladeDirs = {
  29. front = {x = 0, y = 1},
  30. back = {x = 0, y = -1},
  31. left = {x = -1, y = 0},
  32. right = {x = 1, y = 0}
  33. }
  34.  
  35. -- Rotate cyclic vector into rotor space
  36. local function rotateCyclic(x, y, angleDeg)
  37. local rad = math.rad(-angleDeg) -- negative to align with rotor orientation
  38. local cosA = math.cos(rad)
  39. local sinA = math.sin(rad)
  40. return x * cosA - y * sinA, x * sinA + y * cosA
  41. end
  42.  
  43. while true do
  44. local id, Cyaw = rednet.receive()
  45. local id, XAxis = rednet.receive()
  46. local id, YAxis = rednet.receive()
  47. local id, rYAxis = rednet.receive()
  48.  
  49. -- Get current yaw from quaternion
  50. local q = ship.getQuaternion()
  51. local w, x, y, z = q.w, q.x, q.y, q.z
  52.  
  53. local siny_cosp = 2 * (w * y + x * z)
  54. local cosy_cosp = 1 - 2 * (y * y + z * z)
  55. local Byaw = math.atan2(siny_cosp, cosy_cosp) * 180 / math.pi
  56.  
  57. if Byaw < 0 then
  58. Byaw = Byaw + 360
  59. end
  60.  
  61. local Dyaw = (Byaw - Cyaw) % 360
  62.  
  63. -- Rotate cyclic input into rotor space
  64. local cyclicX, cyclicY = rotateCyclic(YAxis, XAxis, Dyaw)
  65.  
  66. -- Apply pitch to each blade (cyclic + collective), with sign correction
  67. front.setAngle(pitchSign.front * cyclicY + collectiveSign.front * rYAxis)
  68. back.setAngle(pitchSign.back * cyclicY + collectiveSign.back * rYAxis)
  69. left.setAngle(pitchSign.left * cyclicX + collectiveSign.left * rYAxis)
  70. right.setAngle(pitchSign.right * cyclicX + collectiveSign.right * rYAxis)
  71.  
  72. -- Send yaw to monitor
  73. local id = 8
  74. rednet.send(id, Byaw)
  75.  
  76. sleep(0)
  77. end
  78.  
Advertisement
Add Comment
Please, Sign In to add comment