kOS/prog/aircraft.ks

89 lines
1.6 KiB
Plaintext
Raw Permalink Normal View History

RunOncePath("lib/flap_control").
RunOncePath("lib/stabilize_aircraft").
RunOncePath("lib/ui").
clearguis().
global done is false.
on AG9 {
set done to true.
return true.
}
2021-08-25 02:35:49 +00:00
global takeoffAngle is 15.
global landingAngle is 30.
function landingMode {
print "Setting flaps to landing mode.".
2021-08-25 02:35:49 +00:00
SetFlapAngle(landingAngle).
when SHIP:VELOCITY:SURFACE:MAG < 0.1 then {
takeoffMode().
}
}
function takeoffMode {
print "Setting flaps to takeoff mode.".
2021-08-25 02:35:49 +00:00
SetFlapAngle(takeoffAngle).
on GEAR {
if GEAR = true {
return true.
}
landingMode().
}
}
if SHIP:STATUS = "LANDED" or SHIP:STATUS = "PRELAUNCH" {
takeoffMode().
} else {
landingMode().
}
// Top-level elements.
local iface is gui(250, 300).
set iface:X to 200.
set iface:Y to 700.
local top is iface:AddVLayout().
local rows is List(MakeRow(top), MakeRow(top)).
local stk is iface:AddStack().
AddStockButtons(rows[0], "aircraft").
2021-08-25 02:35:49 +00:00
MakeMenu(
stk,
MakeButton(rows[0], "Config"),
List(
List("Takeoff Flap Angle", "SCALAR", "15"),
List("Landing Flap Angle", "SCALAR", "30")
),
"Apply",
{
parameter options.
set takeoffAngle to options["Takeoff Flap Angle"]:TEXT:ToNumber().
set landingAngle to options["Landing Flap Angle"]:TEXT:ToNumber().
}
).
MakeMenu(
stk,
MakeButton(rows[1], "Level"),
List(
List("Kp", "SCALAR", "0.02"),
List("Ki", "SCALAR", "0.01"),
List("Kd", "SCALAR", "1")
),
"Execute",
{
parameter options.
HoldHorizon(
options["Kp"]:TEXT:ToNumber(),
options["Ki"]:TEXT:ToNumber(),
options["Kd"]:TEXT:ToNumber()
).
}
).
iface:show().
wait until false.