35 lines
913 B
Plaintext
35 lines
913 B
Plaintext
RunOncePath("lib/navball").
|
|
|
|
// Fly level toward the current compass heading.
|
|
function HoldHorizon {
|
|
parameter Kp is 0.02.
|
|
parameter Ki is 0.04.
|
|
parameter Kd is 0.0066.
|
|
|
|
SAS off.
|
|
|
|
local pitchPID is PidLoop(Kp, Ki, Kd).
|
|
|
|
// local rollPID is PidLoop(Kp, Ki, Kd).
|
|
// lock rollVec to VXCL(SHIP:FACING:FOREVECTOR, SHIP:FACING:TOPVECTOR).
|
|
// lock upVec to VXCL(SHIP:FACING:FOREVECTOR, SHIP:UP:FOREVECTOR).
|
|
|
|
local h is GetHeading().
|
|
|
|
local p is 0.
|
|
lock p to pitchPID:Update(TIME:SECONDS, SHIP:VERTICALSPEED).
|
|
lock STEERING to Heading(h, p, 0).
|
|
|
|
// until done {
|
|
// set SHIP:CONTROL:PITCH to pitchPID:Update(TIME:SECONDS, GetPitch(SHIP:SRFPROGRADE:FOREVECTOR)).
|
|
// set SHIP:CONTROL:ROLL to rollPID:Update(TIME:SECONDS, VAng(rollVec, upVec)).
|
|
// }
|
|
|
|
wait until done.
|
|
set done to false.
|
|
unlock STEERING.
|
|
SAS on.
|
|
// set SHIP:CONTROL:PITCH to 0.
|
|
// set SHIP:CONTROL:ROLL to 0.
|
|
}
|