kOS/init/rocket.ks

166 lines
3.6 KiB
Plaintext
Raw Normal View History

2021-08-02 01:34:19 +00:00
@lazyglobal off.
2021-08-02 04:20:19 +00:00
runoncepath("/lib/ui").
2021-07-21 09:24:46 +00:00
runoncepath("/lib/navigation").
runoncepath("/lib/throttle").
2021-08-02 01:46:17 +00:00
runoncepath("/lib/node").
2021-08-01 05:23:39 +00:00
runoncepath("/lib/stabilize_rocket").
2021-08-02 04:20:19 +00:00
runoncepath("/lib/launch_rocket").
2021-07-21 09:24:46 +00:00
clearguis().
2021-08-01 05:23:39 +00:00
global done is false.
on AG9 {
set done to true.
return true.
}
2021-07-21 09:24:46 +00:00
// Main UI.
local iface is gui(250, 300).
set iface:X to 200.
set iface:Y to 700.
2021-07-21 09:24:46 +00:00
// Main menu elements in here.
local top is iface:AddVLayout().
local row is makeRow(top).
local btn is row:AddButton("TERM").
2021-07-21 09:24:46 +00:00
set btn:TOGGLE to true.
set btn:ONTOGGLE to {
parameter d.
if d {
2021-07-21 09:24:46 +00:00
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
} else {
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").
2021-07-22 22:29:18 +00:00
}
2021-07-21 09:24:46 +00:00
}.
makeButton(row, "CONF", { stk:ShowOnly(panes["conf"]). }).
set row to makeRow(top).
2021-07-22 22:29:18 +00:00
makeButton(row, "HOVER", { Hover(). }).
makeButton(row, "LAND", { Land(). }).
2021-08-01 05:23:39 +00:00
set row to makeRow(top).
2021-08-01 05:23:39 +00:00
makeButton(row, "LNCH", { stk:ShowOnly(panes["launch"]). }).
2021-08-01 05:23:39 +00:00
makeButton(row, "NODE", {
2021-08-02 01:37:42 +00:00
if HASNODE {
set nodeDV:TEXT to NEXTNODE:DELTAV:MAG:ToString.
set nodeBT:TEXT to BurnTime(NEXTNODE:DELTAV:MAG):ToString.
} else {
set nodeDV:TEXT to "No Node".
set nodeBT:TEXT to "No Node".
2021-08-02 01:37:42 +00:00
}
stk:ShowOnly(panes["node"]).
}).
makeButton(row, "TWR", { stk:ShowOnly(panes["twr"]). }).
local stk is iface:AddStack().
local panes is Lex().
2021-07-19 07:43:07 +00:00
2021-07-22 22:29:18 +00:00
// Build launch menu
local top is stk:AddVLayout().
panes:Add("launch", top).
2021-08-02 01:37:42 +00:00
local box is top:AddScrollBox().
2021-07-21 09:24:46 +00:00
set row to makeRow(box).
row:AddLabel("Target Apoapsis").
local targetApo is row:AddTextField("80000"). // todo: config params should go into a nested lexicon
2021-07-21 09:24:46 +00:00
set row to makeRow(box).
row:AddLabel("Atmo TWR").
local targetTWR is row:AddTextField("1.6").
2021-07-21 09:24:46 +00:00
set row to makeRow(box).
row:AddLabel("Initial Pitch").
local initialPitch is row:AddTextField("85").
2021-07-21 09:24:46 +00:00
set row to makeRow(box).
row:AddLabel("Minimum Pitch").
local minimumPitch is row:AddTextField("5").
2021-07-21 09:24:46 +00:00
set row to makeRow(box).
row:AddLabel("Gravity Turn Alt").
local gravTurnStart is row:AddTextField("8000").
2021-07-21 09:24:46 +00:00
set row to makeRow(box).
row:AddLabel("Gravity Turn Pitch").
local gravPitch is row:AddTextField("75").
2021-07-21 09:24:46 +00:00
2021-08-02 01:45:47 +00:00
makeButton(top, "Execute", {
2021-08-02 04:20:19 +00:00
Launch(
2021-08-02 01:45:47 +00:00
targetApo:TEXT:ToNumber(),
gravTurnStart:TEXT:ToNumber(),
gravPitch:TEXT:ToNumber(),
initialPitch:TEXT:ToNumber(),
minimumPitch:TEXT:ToNumber()
).
}).
// End Launch Menu
// Build conf menu
local top is stk:AddVLayout().
panes:Add("conf", top).
set box to top:AddScrollbox().
set row to makeRow(box).
row:AddLabel("Torque Epsilon Max").
local maxEpsilon is row:AddTextField("0.001").
2021-07-21 09:24:46 +00:00
set row to makeRow(box).
row:AddLabel("Max Stopping Time").
local maxStopTime is row:AddTextField("2.0").
2021-07-21 09:24:46 +00:00
2021-08-02 01:45:47 +00:00
makeButton(top, "Apply", {
set STEERINGMANAGER:TORQUEEPSILONMAX to maxEpsilon:TEXT:ToNumber().
set STEERINGMANAGER:MAXSTOPPINGTIME to maxStopTime:TEXT:ToNumber().
2021-08-02 01:45:47 +00:00
}).
// end conf menu
2021-07-22 22:29:18 +00:00
// twr menu
local top is stk:AddVLayout().
panes:Add("twr", top).
2021-07-22 22:29:18 +00:00
set row to makeRow(top).
row:AddLabel("Target TWR").
local twrLock is row:AddTextField("1.6").
2021-08-02 01:45:47 +00:00
makeButton(top, "Lock TWR", {
local done is false.
on AG9 {
set done to true.
}
2021-08-01 05:23:39 +00:00
print "Locking throttle to target TWR.".
local tgt is twrLock:TEXT:ToNumber().
lock THROTTLE to ThrottleToTWR(tgt).
wait until done.
2021-08-01 05:23:39 +00:00
print "Throttle unlocked.".
2021-08-02 01:45:47 +00:00
}).
// end twr menu
2021-07-22 22:29:18 +00:00
2021-08-01 05:23:39 +00:00
// node menu
local top is stk:AddVLayout().
panes:Add("node", top).
2021-08-01 05:23:39 +00:00
set row to makeRow(top).
row:AddLabel("Node dV").
local nodeDV is row:AddLabel().
2021-08-01 05:23:39 +00:00
set row to makeRow(top).
row:AddLabel("Node Burn Time").
local nodeBT is row:AddLabel().
2021-08-01 05:23:39 +00:00
2021-08-02 01:45:47 +00:00
makeButton(top, "Execute", { ExecNode(). }).
2021-08-01 05:23:39 +00:00
// end node menu
iface:show().
wait until false.