Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- des = tonumber(read())
- Kp = 0.005
- Ki = 0.5
- Kd = 0.01
- prevI = 0
- prevError = 0
- iteration = 0.05 --1 tickcan yo
- local function altitudeHold(desired, cur, kp, ki, kd)
- current = cur
- altError = desired - current
- P = kp * altError
- I = (prevI + altError) * ki
- D = (altError - prevError) * kd
- out = P + I + D
- prevI = I
- prevError = altError
- return out, current
- end
- val = 0
- while true do
- alt = ship.getWorldspacePosition().y
- control = altitudeHold(des, alt, Kp, Ki, Kd)
- val = val + control * iteration
- print("Current Value: " .. current .. " | Control Signal: " .. string.format("%.2f", val))
- if val <= 2 then
- val = 2
- elseif val >= 14 then
- val = 14
- end
- redstone.setAnalogOutput("right", 15- val)
- sleep(iteration)
- end
Advertisement
Add Comment
Please, Sign In to add comment