Move launch script to a library.
This commit is contained in:
parent
b4ac0b0325
commit
981ce4e7f9
|
@ -3,10 +3,11 @@ runoncepath("0:/lib/boot").
|
|||
parameter debug is false.
|
||||
|
||||
local compiled is list(
|
||||
"/lib/launch_rocket",
|
||||
"/lib/navigation",
|
||||
"/lib/throttle",
|
||||
"/lib/node",
|
||||
"/lib/stabilize_rocket",
|
||||
"/lib/node"
|
||||
"/lib/throttle"
|
||||
).
|
||||
|
||||
local copied is list(
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
@lazyglobal off.
|
||||
|
||||
runoncepath("/lib/ui").
|
||||
runoncepath("/lib/navigation").
|
||||
runoncepath("/lib/throttle").
|
||||
runoncepath("/lib/node").
|
||||
runoncepath("/lib/stabilize_rocket").
|
||||
runoncepath("/lib/ui").
|
||||
runoncepath("/lib/launch_rocket").
|
||||
|
||||
clearguis().
|
||||
|
||||
|
@ -90,7 +91,7 @@ row:AddLabel("Gravity Turn Pitch").
|
|||
local gravPitch is row:AddTextField("75").
|
||||
|
||||
makeButton(top, "Execute", {
|
||||
run "/launch"(
|
||||
Launch(
|
||||
targetApo:TEXT:ToNumber(),
|
||||
gravTurnStart:TEXT:ToNumber(),
|
||||
gravPitch:TEXT:ToNumber(),
|
||||
|
|
71
lib/launch_rocket.ks
Normal file
71
lib/launch_rocket.ks
Normal file
|
@ -0,0 +1,71 @@
|
|||
runoncepath("lib/throttle").
|
||||
runoncepath("lib/navigation").
|
||||
runoncepath("lib/node").
|
||||
|
||||
function Launch {
|
||||
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 5.
|
||||
|
||||
local ATMO_TWR is 1.6.
|
||||
|
||||
// Configure subsystems.
|
||||
RCS off.
|
||||
SAS off.
|
||||
|
||||
// Countdowns are cute.
|
||||
print "Initiating automated launch sequence.".
|
||||
from { local x is 5. } until x = 0 step { set x to x - 1. } do {
|
||||
print "..." + x.
|
||||
wait 0.5.
|
||||
}
|
||||
|
||||
// Hold throttle to maintain 1.5 TWR.
|
||||
// We do *not* use a PID Loop here because we can
|
||||
// calculate the correct value discretely.
|
||||
lock THROTTLE to ThrottleToTWR(ATMO_TWR).
|
||||
print "Throttling to maintain a TWR of " + ATMO_TWR.
|
||||
|
||||
// Main ascent control.
|
||||
lock STEERING to heading(90,90,270).
|
||||
stage.
|
||||
wait until SHIP:ALTITUDE > 200.
|
||||
|
||||
print "Vectoring away from launchpad.".
|
||||
lock STEERING to heading(90, INITIAL_PITCH, 270).
|
||||
wait until SHIP:ALTITUDE > GRAVITY_TURN_START.
|
||||
|
||||
print "Pitching for gravity turn.".
|
||||
// Pitch over...
|
||||
lock STEERING to heading(90, GRAVITY_PITCH, 270).
|
||||
// Wait until we have rotated to (approximately) that pitch...
|
||||
wait until vectorangle(
|
||||
SHIP:FACING:FOREVECTOR,
|
||||
STEERINGMANAGER:TARGET:FOREVECTOR)
|
||||
< 0.5.
|
||||
|
||||
// then wait until Prograde catches up (or passes us).
|
||||
local targetPitch is GetPitch(STEERINGMANAGER:TARGET:FOREVECTOR).
|
||||
wait until GetPitch(SHIP:SRFPROGRADE:FOREVECTOR) <= targetPitch.
|
||||
|
||||
print "Locking to prograde, letting gravity do the hard work.".
|
||||
lock STEERING to GetAscentVector(MINIMUM_PITCH).
|
||||
wait until SHIP:ALTITUDE > 32000. // todo: if we have a pressure sensor we can use it to decide when to kick the throttle up instead, neat solution for e.g. Duna and Eve.
|
||||
|
||||
lock THROTTLE to 1.0.
|
||||
wait until SHIP:ORBIT:APOAPSIS > APOAPSIS_TARGET.
|
||||
|
||||
lock THROTTLE to 0.0.
|
||||
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
|
||||
wait 0.001. // make sure these control updates get applied
|
||||
|
||||
print "Target apoapsis acquired. Creating maneuver node.".
|
||||
add CreateCircularizationNode().
|
||||
ExecNode().
|
||||
print "Orbit acquired. Releasing controls. Good luck, Kerman.".
|
||||
unlock THROTTLE.
|
||||
unlock STEERING.
|
||||
SAS on.
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
runoncepath("lib/throttle").
|
||||
runoncepath("lib/navigation").
|
||||
runoncepath("lib/node").
|
||||
|
||||
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 5.
|
||||
|
||||
local ATMO_TWR is 1.6.
|
||||
|
||||
// Configure subsystems.
|
||||
RCS off.
|
||||
SAS off.
|
||||
|
||||
// Countdowns are cute.
|
||||
print "Initiating automated launch sequence.".
|
||||
from { local x is 5. } until x = 0 step { set x to x - 1. } do {
|
||||
print "..." + x.
|
||||
wait 0.5.
|
||||
}
|
||||
|
||||
// Hold throttle to maintain 1.5 TWR.
|
||||
// We do *not* use a PID Loop here because we can
|
||||
// calculate the correct value discretely.
|
||||
lock THROTTLE to ThrottleToTWR(ATMO_TWR).
|
||||
print "Throttling to maintain a TWR of " + ATMO_TWR.
|
||||
|
||||
// Main ascent control.
|
||||
lock STEERING to heading(90,90,270).
|
||||
stage.
|
||||
wait until SHIP:ALTITUDE > 200.
|
||||
|
||||
print "Vectoring away from launchpad.".
|
||||
lock STEERING to heading(90, INITIAL_PITCH, 270).
|
||||
wait until SHIP:ALTITUDE > GRAVITY_TURN_START.
|
||||
|
||||
print "Pitching for gravity turn.".
|
||||
// Pitch over...
|
||||
lock STEERING to heading(90, GRAVITY_PITCH, 270).
|
||||
// Wait until we have rotated to (approximately) that pitch...
|
||||
wait until vectorangle(
|
||||
SHIP:FACING:FOREVECTOR,
|
||||
STEERINGMANAGER:TARGET:FOREVECTOR)
|
||||
< 0.5.
|
||||
|
||||
// then wait until Prograde catches up (or passes us).
|
||||
local targetPitch is GetPitch(STEERINGMANAGER:TARGET:FOREVECTOR).
|
||||
wait until GetPitch(SHIP:SRFPROGRADE:FOREVECTOR) <= targetPitch.
|
||||
|
||||
print "Locking to prograde, letting gravity do the hard work.".
|
||||
lock STEERING to GetAscentVector(MINIMUM_PITCH).
|
||||
wait until SHIP:ALTITUDE > 32000. // todo: if we have a pressure sensor we can use it to decide when to kick the throttle up instead, neat solution for e.g. Duna and Eve.
|
||||
|
||||
lock THROTTLE to 1.0.
|
||||
wait until SHIP:ORBIT:APOAPSIS > APOAPSIS_TARGET.
|
||||
|
||||
lock THROTTLE to 0.0.
|
||||
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
|
||||
wait 0.001. // make sure these control updates get applied
|
||||
|
||||
print "Target apoapsis acquired. Creating maneuver node.".
|
||||
add CreateCircularizationNode().
|
||||
ExecNode().
|
||||
print "Orbit acquired. Releasing controls. Good luck, Kerman.".
|
||||
unlock THROTTLE.
|
||||
unlock STEERING.
|
||||
SAS on.
|
Loading…
Reference in New Issue
Block a user