@lazyglobal off. RunOncePath("/lib/ui"). RunOncePath("/lib/navigation"). RunOncePath("/lib/throttle"). RunOncePath("/lib/stabilize_rocket"). RunOncePath("/lib/launch_rocket"). RunOncePath("/lib/sensors"). RunOncePath("/lib/systems"). RunOncePath("/lib/reentry"). clearguis(). global done is false. on AG9 { set done to true. return true. } // Top-level menu structure. local iface is gui(250, 300). set iface:X to 200. set iface:Y to 750. local top is iface:AddVLayout(). local rows is list(MakeRow(top), MakeRow(top), MakeRow(top), MakeRow(top)). local stk is iface:AddStack(). // Buttons and menus. AddStockButtons(rows[0], "rocket"). MakeMenu( stk, MakeButton(rows[0], "Config"), List( List("Torque Epsilon Max", "SCALAR", "0.001"), List("Max Stopping Time", "SCALAR", "2.0") ), "Apply", { parameter options. set STEERINGMANAGER:TORQUEEPSILONMAX to options["Torque Epsilon Max"]:TEXT:ToNumber(). set STEERINGMANAGER:MAXSTOPPINGTIME to options["Max Stopping Time"]:TEXT:ToNumber(). } ). MakeToggle(rows[0], "Solar", { parameter d. SolarPanels(d). }). MakeButton(rows[0], "Ant", { Antennas(). }). MakeMenu( stk, MakeButton(rows[1], "Sensors"), List( List("Pressure", "RO", "-1"), List("Temperature", "RO", "-1"), List("Acceleration", "RO", "-1"), List("Gravity", "RO", "-1"), List("Light", "RO", "-1") ), "Refresh", refreshSensors@, refreshSensors@ ). MakeMenu( stk, MakeButton(rows[1], "Ground"), List( List("Burn Distance", "RO", "-1"), List("Stopping Time", "RO", "-1"), List("Stopping Distance", "RO", "-1"), List("Stopping dV", "RO", "-1") ), "", { parameter options. }, { parameter options. set options["Burn Distance"]:TEXT to TargetBurnDistance():TOSTRING. set options["Stopping dV"]:TEXT to SHIP:VELOCITY:SURFACE:MAG:TOSTRING. set options["Stopping Time"]:TEXT to BurnTime(SHIP:VELOCITY:SURFACE:MAG):TOSTRING. set options["Stopping Distance"]:TEXT to StoppingDistance():TOSTRING. } ). MakeButton(rows[1], "Hover", { Hover(). }). MakeButton(rows[1], "Land", { Land(). }). MakeMenu( stk, MakeButton(rows[2], "Launch"), List( List("Target Apoapsis", "SCALAR", "80000"), List("Kick Angle", "SCALAR", "30"), List("Kick Time", "SCALAR", "45"), List("Kick Start", "SCALAR", "100"), List("Atmo TWR", "SCALAR", "2.0"), List("Minimum Pitch", "SCALAR", "5"), List("Autostage", "BOOL", true) ), "Execute", { parameter options. Launch( options["Target Apoapsis"]:TEXT:ToNumber(), options["Atmo TWR"]:TEXT:ToNumber(), options["Minimum Pitch"]:TEXT:ToNumber(), options["Kick Angle"]:TEXT:ToNumber(), options["Kick Time"]:TEXT:ToNumber(), options["Kick Start"]:TEXT:ToNumber(), options["Autostage"]:PRESSED ). } ). MakeMenu( stk, MakeButton(rows[2], "Node"), List( List("Node dV", "RO", "0"), List("Node Burn Time", "RO", "0"), List("Node Lead Time", "RO", "0"), List("Burn Start ETA", "RO", "0") ), "Execute", { parameter options. ExecNode(). }, { parameter options. if HASNODE { local burnTime is BurnTime(NEXTNODE:DELTAV:MAG). local leadTime is BurnTime(NEXTNODE:DELTAV:MAG / 2). set options["Node dV"]:TEXT to NEXTNODE:DELTAV:MAG:ToString. set options["Node Burn Time"]:TEXT to burnTime:ToString. set options["Node Lead Time"]:TEXT to leadTime:ToString. set options["Burn Start ETA"]:TEXT to (NEXTNODE:ETA - leadTime):ToString. } else { set options["Node dV"]:TEXT to "No Node". set options["Node Burn Time"]:TEXT to "No Node". set options["Node Lead Time"]:TEXT to "No Node". set options["Burn Start ETA"]:TEXT to "No Node". } } ). MakeMenu( stk, MakeButton(rows[2], "TWR"), List( List("Target TWR", "SCALAR", "1.6") ), "Lock TWR", { parameter options. local done is false. print "Locking throttle to target TWR.". local tgt is options["Target TWR"]:TEXT:ToNumber(). lock THROTTLE to ThrottleToTWR(tgt). wait until done. print "Throttle unlocked.". set done to false. } ). MakeMenu( stk, MakeButton(rows[2], "Reentry"), List( List("Retract Antennae", "BOOL", true) ), "Execute", { parameter options. PerformReentry(options["Retract Antennae"]:PRESSED). } ). MakeButton( rows[3], "Pro", { set done to false. lock STEERING to SHIP:PROGRADE. wait until done. set done to false. } ). MakeButton( rows[3], "Ret", { set done to false. lock STEERING to SHIP:RETROGRADE. wait until done. set done to false. } ). MakeButton( rows[3], "Srf Pro", { set done to false. lock STEERING to SHIP:SRFPROGRADE. wait until done. set done to false. } ). MakeButton( rows[3], "Srf Ret", { set done to false. lock STEERING to SHIP:SRFRETROGRADE. wait until done. set done to false. } ). iface:show(). until SHIP:STATUS <> "PRELAUNCH" { if not CORE:MESSAGES:EMPTY { local msg is CORE:MESSAGES:Pop(). local data is msg:CONTENT. if data["command"] = "launch" { Launch( 80000, 2.0, 5.0, data["angle"], data["time"], data["start"], true ). } } wait 0.001. } wait until false. function refreshSensors { parameter options. set options["Pressure"]:TEXT to ReadSensor("PRES"):TOSTRING. set options["Temperature"]:TEXT to ReadSensor("TEMP"):TOSTRING. set options["Acceleration"]:TEXT to ReadSensor("ACC"):TOSTRING. set options["Gravity"]:TEXT to ReadSensor("GRAV"):TOSTRING. set options["Light"]:TEXT to ReadSensor("LIGHT"):TOSTRING. }