From 081fcb361858c0101f756ba9c8f93a3064307235 Mon Sep 17 00:00:00 2001 From: annabunches Date: Wed, 25 Aug 2021 01:11:29 -0400 Subject: [PATCH] Set up code for quickly handling antennas and solar panels. --- boot/simustrap.ks | 29 ++++++++++++++++++++++ lib/reentry.ks | 10 ++++---- lib/systems.ks | 25 +++++++++++++++++++ lib/ui.ks | 17 ++++++++++--- prog/rocket.ks | 63 +++++++++++++++++++++++++++-------------------- 5 files changed, 108 insertions(+), 36 deletions(-) create mode 100644 boot/simustrap.ks create mode 100644 lib/systems.ks diff --git a/boot/simustrap.ks b/boot/simustrap.ks new file mode 100644 index 0000000..eec7c70 --- /dev/null +++ b/boot/simustrap.ks @@ -0,0 +1,29 @@ +function Antennas { + parameter enable is true. + + local eventName is "Activate". + if not enable { + set eventName to "Deactivate". + } + + for p in SHIP:PARTS { + if p:MODULES:Find("ModuleRTAntenna") > -1 and p:GetModule("ModuleRTAntenna"):ALLEVENTNAMES:Find(eventName) > -1 { + p:GetModule("ModuleRTAntenna"):DoEvent(eventName). + } + } +} + +function SolarPanels { + parameter enable is true. + + if enable { + PANELS on. + } else { + PANELS off. + } +} + +wait until SHIP:UNPACKED. +wait 5.0. +Antennas(). +SolarPanels(). diff --git a/lib/reentry.ks b/lib/reentry.ks index d56b25f..a716832 100644 --- a/lib/reentry.ks +++ b/lib/reentry.ks @@ -2,11 +2,15 @@ // Assumes stage 0 contains only parachutes. // Primarily written for small science payload probes. +RunOncePath("lib/systems"). + function PerformReentry { parameter retractAntennae is true. SAS off. + print "Reentry mode activated. Control permanently locked.". + // stage until only stage 0 remains. until STAGE:NUMBER <= 1 { stage. @@ -15,11 +19,7 @@ function PerformReentry { lock STEERING to SHIP:SRFRETROGRADE. if retractAntennae { - for p in SHIP:PARTS { - if p:MODULES:Find("ModuleRTAntenna") > -1 and p:GetModule("ModuleRTAntenna"):ALLEVENTNAMES:Find("Deactivate") > -1 { - p:GetModule("ModuleRTAntenna"):DoEvent("Deactivate"). - } - } + Antennas(false). } when SHIP:ALTITUDE - SHIP:GEOPOSITION:TERRAINHEIGHT < 2500 then { diff --git a/lib/systems.ks b/lib/systems.ks new file mode 100644 index 0000000..31561d1 --- /dev/null +++ b/lib/systems.ks @@ -0,0 +1,25 @@ + +function Antennas { + parameter enable is true. + + local eventName is "Activate". + if not enable { + set eventName to "Deactivate". + } + + for p in SHIP:PARTS { + if p:MODULES:Find("ModuleRTAntenna") > -1 and p:GetModule("ModuleRTAntenna"):ALLEVENTNAMES:Find(eventName) > -1 { + p:GetModule("ModuleRTAntenna"):DoEvent(eventName). + } + } +} + +function SolarPanels { + parameter enable is true. + + if enable { + PANELS on. + } else { + PANELS off. + } +} diff --git a/lib/ui.ks b/lib/ui.ks index 604e322..29d81c4 100644 --- a/lib/ui.ks +++ b/lib/ui.ks @@ -13,6 +13,17 @@ function MakeButton { return b. } +function MakeToggle { + parameter p. + parameter l. + parameter f. + + local btn is p:AddButton(l). + set btn:TOGGLE to true. + set btn:onClick to f. + return btn. +} + function MakeMenu { parameter stack. // the stack where menu stuff goes parameter btn. // the button that should show this menu @@ -58,9 +69,7 @@ function AddStockButtons { parameter row. parameter bootname. - local btn is row:AddButton("Term"). - set btn:TOGGLE to true. - set btn:ONTOGGLE to { + MakeToggle(row, "Term", { parameter d. if d { @@ -68,7 +77,7 @@ function AddStockButtons { } else { CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal"). } - }. + }). MakeButton(row, "Update", { switch to 0. diff --git a/prog/rocket.ks b/prog/rocket.ks index 7a664d9..5d884ba 100644 --- a/prog/rocket.ks +++ b/prog/rocket.ks @@ -6,6 +6,7 @@ RunOncePath("/lib/throttle"). RunOncePath("/lib/stabilize_rocket"). RunOncePath("/lib/launch_rocket"). RunOncePath("/lib/sensors"). +RunOncePath("/lib/systems"). RunOncePath("/lib/reentry"). clearguis(). @@ -29,7 +30,31 @@ AddStockButtons(rows[0], "rocket"). MakeMenu( stk, - MakeButton(rows[0], "SENS"), + 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"), @@ -44,7 +69,7 @@ MakeMenu( MakeMenu( stk, - MakeButton(rows[0], "GRND"), + MakeButton(rows[1], "Ground"), List( List("Burn Distance", "RO", "-1"), List("Stopping Time", "RO", "-1"), @@ -61,29 +86,16 @@ MakeMenu( set options["Stopping Distance"]:TEXT to StoppingDistance():TOSTRING. } ). - -MakeMenu( - stk, - MakeButton(rows[1], "REENTRY"), - List( - List("Retract Antennae", "BOOL", true) - ), - "Execute", - { - parameter options. - PerformReentry(options["Retract Antennae"]:PRESSED). - } -). -MakeButton(rows[1], "HOVER", { Hover(). }). -MakeButton(rows[1], "LAND", { Land(). }). +MakeButton(rows[1], "Hover", { Hover(). }). +MakeButton(rows[1], "Land", { Land(). }). MakeMenu( stk, - MakeButton(rows[2], "LNCH"), + MakeButton(rows[2], "Launch"), List( List("Target Apoapsis", "SCALAR", "80000"), - List("Initial Pitch", "SCALAR", "20"), + List("Initial Pitch", "SCALAR", "30"), List("Pitch Time", "SCALAR", "45"), List("Atmo TWR", "SCALAR", "2.0"), List("Minimum Pitch", "SCALAR", "5"), @@ -105,7 +117,7 @@ MakeMenu( MakeMenu( stk, - MakeButton(rows[2], "NODE"), + MakeButton(rows[2], "Node"), List( List("Node dV", "RO", "0"), List("Node Burn Time", "RO", "0") @@ -148,20 +160,17 @@ MakeMenu( MakeMenu( stk, - MakeButton(rows[2], "Config"), + MakeButton(rows[2], "Reentry"), List( - List("Torque Epsilon Max", "SCALAR", "0.001"), - List("Max Stopping Time", "SCALAR", "2.0") + List("Retract Antennae", "BOOL", true) ), - "Apply", + "Execute", { parameter options. - set STEERINGMANAGER:TORQUEEPSILONMAX to options["Torque Epsilon Max"]:TEXT:ToNumber(). - set STEERINGMANAGER:MAXSTOPPINGTIME to options["Max Stopping Time"]:TEXT:ToNumber(). + PerformReentry(options["Retract Antennae"]:PRESSED). } ). - iface:show(). wait until false.