Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- peripheral.find("modem", rednet.open)
- print(os.getComputerID()) -- getID
- local monitor = peripheral.find("monitor")
- local back = peripheral.wrap("back")
- local front = peripheral.wrap("front")
- local left = peripheral.wrap("left")
- local right = peripheral.wrap("right")
- -- Blade-specific pitch direction multipliers (for cyclic input)
- local pitchSign = {
- front = 1,
- back = 1,
- left = 1,
- right = 1
- }
- -- Blade-specific collective pitch direction multipliers (corrected)
- local collectiveSign = {
- front = -1,
- back = 1,
- left = -1,
- right = 1
- }
- -- Blade direction vectors (fixed in rotor space)
- local bladeDirs = {
- front = {x = 0, y = 1},
- back = {x = 0, y = -1},
- left = {x = -1, y = 0},
- right = {x = 1, y = 0}
- }
- -- Rotate cyclic vector into rotor space
- local function rotateCyclic(x, y, angleDeg)
- local rad = math.rad(-angleDeg) -- negative to align with rotor orientation
- local cosA = math.cos(rad)
- local sinA = math.sin(rad)
- return x * cosA - y * sinA, x * sinA + y * cosA
- end
- while true do
- local id, Cyaw = rednet.receive()
- local id, XAxis = rednet.receive()
- local id, YAxis = rednet.receive()
- local id, rYAxis = rednet.receive()
- -- Get current yaw from quaternion
- local q = ship.getQuaternion()
- local w, x, y, z = q.w, q.x, q.y, q.z
- local siny_cosp = 2 * (w * y + x * z)
- local cosy_cosp = 1 - 2 * (y * y + z * z)
- local Byaw = math.atan2(siny_cosp, cosy_cosp) * 180 / math.pi
- if Byaw < 0 then
- Byaw = Byaw + 360
- end
- local Dyaw = (Byaw - Cyaw) % 360
- -- Rotate cyclic input into rotor space
- local cyclicX, cyclicY = rotateCyclic(YAxis, XAxis, Dyaw)
- -- Apply pitch to each blade (cyclic + collective), with sign correction
- front.setAngle(pitchSign.front * cyclicY + collectiveSign.front * rYAxis)
- back.setAngle(pitchSign.back * cyclicY + collectiveSign.back * rYAxis)
- left.setAngle(pitchSign.left * cyclicX + collectiveSign.left * rYAxis)
- right.setAngle(pitchSign.right * cyclicX + collectiveSign.right * rYAxis)
- -- Send yaw to monitor
- local id = 8
- rednet.send(id, Byaw)
- sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment