From 3101aef1cc135d78116a24aac9bba5a4bd38a8e1 Mon Sep 17 00:00:00 2001 From: annabunches Date: Mon, 19 Jul 2021 04:46:05 -0400 Subject: [PATCH] Finally, code that works to orbit + creates a circ node. --- boot/rocket.ks | 5 ++++- bootstrap/rocket.ks | 2 +- launch.ks | 20 +++++++++++++------- lib/navigation.ks | 9 ++++----- ui/rocket.ks | 18 +++++++++++------- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/boot/rocket.ks b/boot/rocket.ks index 166229e..8cbf0ef 100644 --- a/boot/rocket.ks +++ b/boot/rocket.ks @@ -1,10 +1,13 @@ // rocketOS bootstrapping sequence +// To maximize space, remove this file first thing. The in-memory copy +// will still run. +deletepath("/boot/rocket"). + // Install software. runpath("0:/bootstrap/rocket"). // Set OS to boot and restart. set core:bootfilename to "/ui/rocket". -deletepath("/boot/rocket"). reboot. diff --git a/bootstrap/rocket.ks b/bootstrap/rocket.ks index e897c91..b739337 100644 --- a/bootstrap/rocket.ks +++ b/bootstrap/rocket.ks @@ -2,4 +2,4 @@ compile "0:/ui/rocket" to "1:/ui/rocket". compile "0:/lib/navigation" to "1:/lib/navigation". compile "0:/lib/throttle" to "1:/lib/throttle". compile "0:/launch" to "1:/launch". -copypath("0:/nextnode", "1:/nextnode"). // smaller when compiled +copypath("0:/execnode", "1:/execnode"). // smaller when compiled diff --git a/launch.ks b/launch.ks index 90c7a13..8f238e7 100644 --- a/launch.ks +++ b/launch.ks @@ -5,6 +5,7 @@ parameter APOAPSIS_TARGET is 80000. parameter GRAVITY_TURN_START is 8000. parameter GRAVITY_PITCH is 75. parameter INITIAL_PITCH is 85. +parameter MINIMUM_PITCH is 40. SensorCheck(). // Configure subsystems. @@ -36,15 +37,16 @@ lock STEERING to heading(90,90,270). stage. wait until SHIP:ALTITUDE > 200. -lock STEERING to heading(90, GRAVITY_PITCH, 270). +lock STEERING to heading(90, INITIAL_PITCH, 270). wait until SHIP:ALTITUDE > GRAVITY_TURN_START. print "Pitching for gravity turn". -// Perform initial pitch... +// Pitch over... lock STEERING to heading(90, GRAVITY_PITCH, 270). -// Wait until we have rotated to that pitch... +print ("Locked to heading " + STEERINGMANAGER:TARGET). // debug? +// Wait until we have rotated to (approximately) that pitch... wait until vectorangle( SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) @@ -61,17 +63,21 @@ until SHIP:ORBIT:APOAPSIS > 80000 { // todo: we may need different values for bodies other than Kerbin. local newHeading is lookdirup(SHIP:SRFPROGRADE:FOREVECTOR, heading(90, 0, 270):TOPVECTOR). - if GetPitch(newHeading:FOREVECTOR) < 40 { - set newHeading to heading(90, 40, 270). + if GetPitch(newHeading:FOREVECTOR) < MINIMUM_PITCH { + set newHeading to heading(90, MINIMUM_PITCH, 270). } lock STEERING to newHeading. wait 0.001. } -SHIP:ADD(CreateCircularizationNode(SHIP:ORBIT:ETA:APOAPSIS)). +lock THROTTLE to 0.0. +set SHIP:CONTROL:PILOTMAINTHROTTLE to 0. +wait 0.001. +print "Target apoapsis acquired. Creating maneuver node". + +AddCircularizationNode(). print "Releasing controls. Circularization maneuver added. Good luck, Kerman!". -set SHIP:CONTROL:PILOTMAINTHROTTLE to 0. unlock THROTTLE. unlock STEERING. SAS on. diff --git a/lib/navigation.ks b/lib/navigation.ks index 8e50c06..a154f11 100644 --- a/lib/navigation.ks +++ b/lib/navigation.ks @@ -6,18 +6,19 @@ function GetPitch { return 90 - vectorangle(SHIP:UP:FOREVECTOR, v). } -function CreateCircularizationNode { +function AddCircularizationNode { parameter usePeriapsis is false. local target is SHIP:ORBIT:APOAPSIS. - local t is SHIP:ORBIT:ETA:APOAPSIS. + local t is TIME + SHIP:ORBIT:ETA:APOAPSIS. if usePeriapsis { set target to SHIP:ORBIT:PERIAPSIS. set t to SHIP:ORBIT:ETA:PERIAPSIS. } local n is Node(t, 0, 0, 0). + add(n). // move fast until we pass our target. - until (usePeriapsis and n:ORBIT:APOAPSIS < target) or n:ORBIT:PERIAPSIS > target { + until (usePeriapsis and n:ORBIT:APOAPSIS <= target) or n:ORBIT:PERIAPSIS >= target { set n:PROGRADE to n:PROGRADE + 1. } @@ -25,6 +26,4 @@ function CreateCircularizationNode { until (usePeriapsis and n:ORBIT:APOAPSIS > target) or n:ORBIT:PERIAPSIS < target { set n:PROGRADE to n:PROGRADE - 0.01. } - - return n. } diff --git a/ui/rocket.ks b/ui/rocket.ks index 92ae973..9016142 100644 --- a/ui/rocket.ks +++ b/ui/rocket.ks @@ -2,26 +2,30 @@ function launchButtonPressed { run "launch"( targetApo:TEXT:ToNumber(), gravTurnStart:TEXT:ToNumber(), - initialPitch:TEXT:ToNumber() + gravPitch:TEXT:ToNumber(), + initialPitch:TEXT:ToNumber(), + minimumPitch:TEXT:ToNumber() ). } function nodeButtonPressed { - run "executenode". + run "execnode". } -// Button panel -CreateGUI(). - +// Main UI. local interface is gui(200). set interface:X to 200. -set interface:Y to 900. +set interface:Y to 800. // Launch button local hBox is interface:AddHBox(). hBox:AddLabel("Initial Pitch"). local initialPitch is hBox:AddTextField("85"). +local hBox is interface:AddHBox(). +hBox:AddLabel("Minimum Pitch"). +local minimumPitch is hBox:AddTextField("40"). + local hBox is interface:AddHBox(). hBox:AddLabel("Gravity Turn @"). local gravTurnStart is hBox:AddTextField("8000"). @@ -38,7 +42,7 @@ local launchButton is interface:AddButton("Launch"). set launchButton:onClick to launchButtonPressed@. local nodeButton is interface:AddButton("Execute Node"). -set launchButton:onClick to nodeButtonPressed@. +set nodeButton:onClick to nodeButtonPressed@. interface:show().