From a4d79c98264f87982fbe538ec6c26de7b5694f46 Mon Sep 17 00:00:00 2001 From: annabunches Date: Sun, 1 Aug 2021 17:53:09 -0400 Subject: [PATCH] Refactor and clean up lots of code. --- boot/helicopter.ks | 5 ++--- boot/helicopter_debug.ks | 5 ++--- boot/rocket.ks | 8 ++++---- boot/rocket_debug.ks | 5 +++-- helicopter/hover.ks | 4 ---- helicopter/init.ks => init/helicopter.ks | 14 +++++++------- rocket/init.ks => init/rocket.ks | 0 lib/{control.ks => stabilize_helicopter.ks} | 11 ++++++----- lib/stabilize_rocket.ks | 10 ++++++---- 9 files changed, 30 insertions(+), 32 deletions(-) delete mode 100644 helicopter/hover.ks rename helicopter/init.ks => init/helicopter.ks (94%) rename rocket/init.ks => init/rocket.ks (100%) rename lib/{control.ks => stabilize_helicopter.ks} (86%) diff --git a/boot/helicopter.ks b/boot/helicopter.ks index 53764ad..a276592 100644 --- a/boot/helicopter.ks +++ b/boot/helicopter.ks @@ -1,8 +1,7 @@ deletepath("/boot/helicopter"). -copypath("0:/lib/control", "1:/lib/control"). -copypath("0:/helicopter/hover", "1:/hover"). -copypath("0:/helicopter/init", "1:/init"). +compile "0:/lib/stabilize_helicopter" to "1:/lib/". +comiple "0:/init/helicopter" to "1:/init". // Set OS to boot and restart. set core:bootfilename to "/init". diff --git a/boot/helicopter_debug.ks b/boot/helicopter_debug.ks index fd7c96d..21c206f 100644 --- a/boot/helicopter_debug.ks +++ b/boot/helicopter_debug.ks @@ -1,6 +1,5 @@ -copypath("0:/lib/control", "1:/lib/control"). -copypath("0:/helicopter/hover", "1:/hover"). -copypath("0:/helicopter/init", "1:/init"). +copypath("0:/lib/stabilize_helicopter", "1:/lib/stabilize_helicopter"). +copypath("0:/init/helicopter", "1:/init"). CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal"). run "1:/init". diff --git a/boot/rocket.ks b/boot/rocket.ks index dc67b70..c982fb2 100644 --- a/boot/rocket.ks +++ b/boot/rocket.ks @@ -5,10 +5,10 @@ deletepath("/boot/rocket"). // Install software. -compile "0:/lib/navigation" to "1:/lib/navigation". -compile "0:/lib/throttle" to "1:/lib/throttle". -compile "0:/lib/stabilize_rocket" to "1:/lib/stabilize_rocket". -compile "0:/rocket/init" to "1:/init". +compile "0:/lib/navigation" to "1:/lib/". +compile "0:/lib/throttle" to "1:/lib/". +compile "0:/lib/stabilize_rocket" to "1:/lib/". +compile "0:/init/rocket" to "1:/init". compile "0:/rocket/launch" to "1:/launch". copypath("0:/rocket/execnode", "1:/execnode"). diff --git a/boot/rocket_debug.ks b/boot/rocket_debug.ks index 76dfafa..e81e02c 100644 --- a/boot/rocket_debug.ks +++ b/boot/rocket_debug.ks @@ -2,8 +2,9 @@ copypath("0:/lib/navigation", "1:/lib/navigation"). copypath("0:/lib/throttle", "1:/lib/throttle"). copypath("0:/lib/stabilize_rocket", "1:/lib/stabilize_rocket"). -copypath("0:/rocket/init", "1:/init"). +copypath("0:/init/rocket", "1:/init"). copypath("0:/rocket/launch", "1:/launch"). copypath("0:/rocket/execnode", "1:/execnode"). -run "init". +CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal"). +run "1:/init". diff --git a/helicopter/hover.ks b/helicopter/hover.ks deleted file mode 100644 index 93946f1..0000000 --- a/helicopter/hover.ks +++ /dev/null @@ -1,4 +0,0 @@ -// This script assumes you have bound collective (aka deploy angle) to main throttle. -runoncepath("lib/control"). - -PointStabilizeH(). diff --git a/helicopter/init.ks b/init/helicopter.ks similarity index 94% rename from helicopter/init.ks rename to init/helicopter.ks index 6723694..3144d72 100644 --- a/helicopter/init.ks +++ b/init/helicopter.ks @@ -3,9 +3,15 @@ // * AG9 is unmapped. // * Main throttle controls collective. -runoncepath("lib/control"). +runoncepath("lib/stabilize_helicopter"). global done is false. +on AG9 { + set done to true. + return true. +} + +clearguis(). // Main UI. local interface is gui(250, 300). @@ -32,12 +38,6 @@ set x:AddButton("LAND"):onClick to { PointStabilizeH(-5). }. - -on AG9 { - set done to true. - return true. -} - interface:show(). wait until false. diff --git a/rocket/init.ks b/init/rocket.ks similarity index 100% rename from rocket/init.ks rename to init/rocket.ks diff --git a/lib/control.ks b/lib/stabilize_helicopter.ks similarity index 86% rename from lib/control.ks rename to lib/stabilize_helicopter.ks index e6a31a7..ca1b0d5 100644 --- a/lib/control.ks +++ b/lib/stabilize_helicopter.ks @@ -1,14 +1,15 @@ -// functions that execute comprehensive control schemes. +// Provides stabilization functions, including Hover. // -// These typically assume a global variable 'done' that will be -// set externally when they should return. - +// Must define a global variable 'done', which can be set to true to cancel +// control functions. +// +// Do not include both this and stabilize_rocket.ks in one program. // Helicopter-style point stability control. // Hover, ascend, or descend at a fixed rate. // Adjusts the throttle to control ascent or descent. // Adjusts pitch and roll to maintain zero lateral velocity. -function PointStabilizeH { +function Hover { parameter vertSpeed is 0.0. set done to false. diff --git a/lib/stabilize_rocket.ks b/lib/stabilize_rocket.ks index 1dbafbc..15c1465 100644 --- a/lib/stabilize_rocket.ks +++ b/lib/stabilize_rocket.ks @@ -1,10 +1,12 @@ // Provides stabilization functions, including Hover. -// Control functions can be canceled by actuating Action Group 9. - +// +// Must define a global variable 'done', which can be set to true to cancel +// control functions. +// +// Do not include both this and stabilize_helicopter.ks in one program. // Stabilizes a rocket relative to the surface, with optional vertical -// velocity. Do not include both this and stabilize_helicopter.ks in one -// program. +// velocity. function Hover { parameter vertSpeed is 0.0.