Finally, code that works to orbit + creates a circ node.

This commit is contained in:
Anna Rose 2021-07-19 04:46:05 -04:00
parent 6f9537547f
commit 3101aef1cc
5 changed files with 33 additions and 21 deletions

View File

@ -1,10 +1,13 @@
// rocketOS bootstrapping sequence // rocketOS bootstrapping sequence
// To maximize space, remove this file first thing. The in-memory copy
// will still run.
deletepath("/boot/rocket").
// Install software. // Install software.
runpath("0:/bootstrap/rocket"). runpath("0:/bootstrap/rocket").
// Set OS to boot and restart. // Set OS to boot and restart.
set core:bootfilename to "/ui/rocket". set core:bootfilename to "/ui/rocket".
deletepath("/boot/rocket").
reboot. reboot.

View File

@ -2,4 +2,4 @@ compile "0:/ui/rocket" to "1:/ui/rocket".
compile "0:/lib/navigation" to "1:/lib/navigation". compile "0:/lib/navigation" to "1:/lib/navigation".
compile "0:/lib/throttle" to "1:/lib/throttle". compile "0:/lib/throttle" to "1:/lib/throttle".
compile "0:/launch" to "1:/launch". compile "0:/launch" to "1:/launch".
copypath("0:/nextnode", "1:/nextnode"). // smaller when compiled copypath("0:/execnode", "1:/execnode"). // smaller when compiled

View File

@ -5,6 +5,7 @@ parameter APOAPSIS_TARGET is 80000.
parameter GRAVITY_TURN_START is 8000. parameter GRAVITY_TURN_START is 8000.
parameter GRAVITY_PITCH is 75. parameter GRAVITY_PITCH is 75.
parameter INITIAL_PITCH is 85. parameter INITIAL_PITCH is 85.
parameter MINIMUM_PITCH is 40.
SensorCheck(). SensorCheck().
// Configure subsystems. // Configure subsystems.
@ -36,15 +37,16 @@ lock STEERING to heading(90,90,270).
stage. stage.
wait until SHIP:ALTITUDE > 200. 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. wait until SHIP:ALTITUDE > GRAVITY_TURN_START.
print "Pitching for gravity turn". print "Pitching for gravity turn".
// Perform initial pitch... // Pitch over...
lock STEERING to heading(90, GRAVITY_PITCH, 270). 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( wait until vectorangle(
SHIP:FACING:FOREVECTOR, SHIP:FACING:FOREVECTOR,
STEERINGMANAGER:TARGET:FOREVECTOR) STEERINGMANAGER:TARGET:FOREVECTOR)
@ -61,17 +63,21 @@ until SHIP:ORBIT:APOAPSIS > 80000 {
// todo: we may need different values for bodies other than Kerbin. // todo: we may need different values for bodies other than Kerbin.
local newHeading is lookdirup(SHIP:SRFPROGRADE:FOREVECTOR, local newHeading is lookdirup(SHIP:SRFPROGRADE:FOREVECTOR,
heading(90, 0, 270):TOPVECTOR). heading(90, 0, 270):TOPVECTOR).
if GetPitch(newHeading:FOREVECTOR) < 40 { if GetPitch(newHeading:FOREVECTOR) < MINIMUM_PITCH {
set newHeading to heading(90, 40, 270). set newHeading to heading(90, MINIMUM_PITCH, 270).
} }
lock STEERING to newHeading. lock STEERING to newHeading.
wait 0.001. 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!". print "Releasing controls. Circularization maneuver added. Good luck, Kerman!".
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
unlock THROTTLE. unlock THROTTLE.
unlock STEERING. unlock STEERING.
SAS on. SAS on.

View File

@ -6,18 +6,19 @@ function GetPitch {
return 90 - vectorangle(SHIP:UP:FOREVECTOR, v). return 90 - vectorangle(SHIP:UP:FOREVECTOR, v).
} }
function CreateCircularizationNode { function AddCircularizationNode {
parameter usePeriapsis is false. parameter usePeriapsis is false.
local target is SHIP:ORBIT:APOAPSIS. local target is SHIP:ORBIT:APOAPSIS.
local t is SHIP:ORBIT:ETA:APOAPSIS. local t is TIME + SHIP:ORBIT:ETA:APOAPSIS.
if usePeriapsis { if usePeriapsis {
set target to SHIP:ORBIT:PERIAPSIS. set target to SHIP:ORBIT:PERIAPSIS.
set t to SHIP:ORBIT:ETA:PERIAPSIS. set t to SHIP:ORBIT:ETA:PERIAPSIS.
} }
local n is Node(t, 0, 0, 0). local n is Node(t, 0, 0, 0).
add(n).
// move fast until we pass our target. // 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. 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 { until (usePeriapsis and n:ORBIT:APOAPSIS > target) or n:ORBIT:PERIAPSIS < target {
set n:PROGRADE to n:PROGRADE - 0.01. set n:PROGRADE to n:PROGRADE - 0.01.
} }
return n.
} }

View File

@ -2,26 +2,30 @@ function launchButtonPressed {
run "launch"( run "launch"(
targetApo:TEXT:ToNumber(), targetApo:TEXT:ToNumber(),
gravTurnStart:TEXT:ToNumber(), gravTurnStart:TEXT:ToNumber(),
initialPitch:TEXT:ToNumber() gravPitch:TEXT:ToNumber(),
initialPitch:TEXT:ToNumber(),
minimumPitch:TEXT:ToNumber()
). ).
} }
function nodeButtonPressed { function nodeButtonPressed {
run "executenode". run "execnode".
} }
// Button panel // Main UI.
CreateGUI().
local interface is gui(200). local interface is gui(200).
set interface:X to 200. set interface:X to 200.
set interface:Y to 900. set interface:Y to 800.
// Launch button // Launch button
local hBox is interface:AddHBox(). local hBox is interface:AddHBox().
hBox:AddLabel("Initial Pitch"). hBox:AddLabel("Initial Pitch").
local initialPitch is hBox:AddTextField("85"). 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(). local hBox is interface:AddHBox().
hBox:AddLabel("Gravity Turn @"). hBox:AddLabel("Gravity Turn @").
local gravTurnStart is hBox:AddTextField("8000"). local gravTurnStart is hBox:AddTextField("8000").
@ -38,7 +42,7 @@ local launchButton is interface:AddButton("Launch").
set launchButton:onClick to launchButtonPressed@. set launchButton:onClick to launchButtonPressed@.
local nodeButton is interface:AddButton("Execute Node"). local nodeButton is interface:AddButton("Execute Node").
set launchButton:onClick to nodeButtonPressed@. set nodeButton:onClick to nodeButtonPressed@.
interface:show(). interface:show().