Simplify lots of code in the launch sequence.
This commit is contained in:
parent
401f51425f
commit
642e5b17c5
41
launch.ks
41
launch.ks
|
@ -1,3 +1,4 @@
|
||||||
|
// runoncepath("lib/sensors").
|
||||||
runoncepath("lib/throttle").
|
runoncepath("lib/throttle").
|
||||||
runoncepath("lib/navigation").
|
runoncepath("lib/navigation").
|
||||||
|
|
||||||
|
@ -5,8 +6,9 @@ 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.
|
parameter MINIMUM_PITCH is 5.
|
||||||
SensorCheck().
|
|
||||||
|
local ATMO_TWR is 1.6.
|
||||||
|
|
||||||
// Configure subsystems.
|
// Configure subsystems.
|
||||||
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
|
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
|
||||||
|
@ -23,57 +25,52 @@ from { local x is 5. } until x = 0 step { set x to x - 1. } do {
|
||||||
// Hold throttle to maintain 1.5 TWR.
|
// Hold throttle to maintain 1.5 TWR.
|
||||||
// We do *not* use a PID Loop here because we can
|
// We do *not* use a PID Loop here because we can
|
||||||
// calculate the correct value discretely.
|
// calculate the correct value discretely.
|
||||||
lock THROTTLE to ThrottleToTWR(1.5).
|
lock THROTTLE to ThrottleToTWR(ATMO_TWR).
|
||||||
|
print "Throttling to maintain a TWR of " + ATMO_TWR.
|
||||||
|
|
||||||
// Main ascent control.
|
// Main ascent control.
|
||||||
lock THROTTLE to 1.0.
|
|
||||||
lock STEERING to heading(90,90,270).
|
lock STEERING to heading(90,90,270).
|
||||||
stage.
|
stage.
|
||||||
|
|
||||||
wait until SHIP:ALTITUDE > 200.
|
wait until SHIP:ALTITUDE > 200.
|
||||||
lock STEERING to heading(90, INITIAL_PITCH, 270).
|
|
||||||
|
|
||||||
|
print "Vectoring away from launchpad".
|
||||||
|
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".
|
||||||
|
|
||||||
// Pitch over...
|
// Pitch over...
|
||||||
lock STEERING to heading(90, GRAVITY_PITCH, 270).
|
lock STEERING to heading(90, GRAVITY_PITCH, 270).
|
||||||
print ("Locked to heading " + STEERINGMANAGER:TARGET). // debug?
|
|
||||||
// Wait until we have rotated to (approximately) that pitch...
|
// 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)
|
||||||
< 0.5.
|
< 0.5.
|
||||||
|
|
||||||
// then wait until Prograde catches up.
|
// then wait until Prograde catches up.
|
||||||
wait until vectorangle(
|
wait until vectorangle(
|
||||||
SHIP:SRFPROGRADE:FOREVECTOR,
|
SHIP:SRFPROGRADE:FOREVECTOR,
|
||||||
STEERINGMANAGER:TARGET:FOREVECTOR)
|
STEERINGMANAGER:TARGET:FOREVECTOR)
|
||||||
< 0.5.
|
< 0.5.
|
||||||
|
|
||||||
print "Locking to prograde".
|
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.
|
||||||
|
|
||||||
until SHIP:ORBIT:APOAPSIS > 80000 {
|
lock THROTTLE to 1.0.
|
||||||
// todo: we may need different values for bodies other than Kerbin.
|
wait until SHIP:ORBIT:APOAPSIS > APOAPSIS_TARGET.
|
||||||
local newHeading is lookdirup(SHIP:SRFPROGRADE:FOREVECTOR,
|
|
||||||
heading(90, 0, 270):TOPVECTOR).
|
|
||||||
if GetPitch(newHeading:FOREVECTOR) < MINIMUM_PITCH {
|
|
||||||
set newHeading to heading(90, MINIMUM_PITCH, 270).
|
|
||||||
}
|
|
||||||
lock STEERING to newHeading.
|
|
||||||
wait 0.001.
|
|
||||||
}
|
|
||||||
|
|
||||||
lock THROTTLE to 0.0.
|
lock THROTTLE to 0.0.
|
||||||
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
|
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
|
||||||
wait 0.001.
|
wait 0.001. // make sure these control updates get applied
|
||||||
|
|
||||||
print "Target apoapsis acquired. Creating maneuver node".
|
print "Target apoapsis acquired. Creating maneuver node".
|
||||||
|
|
||||||
AddCircularizationNode().
|
AddCircularizationNode().
|
||||||
|
|
||||||
print "Releasing controls. Circularization maneuver added. Good luck, Kerman!".
|
print "Releasing controls. Circularization maneuver added. Good luck, Kerman!".
|
||||||
unlock THROTTLE.
|
unlock THROTTLE.
|
||||||
unlock STEERING.
|
unlock STEERING.
|
||||||
SAS on.
|
SAS on.
|
||||||
wait 5.
|
wait 5.
|
||||||
|
|
||||||
|
// todo - automatically execute the node
|
||||||
|
|
||||||
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").
|
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").
|
||||||
|
|
|
@ -6,6 +6,18 @@ function GetPitch {
|
||||||
return 90 - vectorangle(SHIP:UP:FOREVECTOR, v).
|
return 90 - vectorangle(SHIP:UP:FOREVECTOR, v).
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function GetAscentVector {
|
||||||
|
parameter minPitch.
|
||||||
|
// face prograde, but hold a solid eastern heading and don't
|
||||||
|
// rotate the ship
|
||||||
|
local newHeading is lookdirup(SHIP:SRFPROGRADE:FOREVECTOR,
|
||||||
|
heading(90, 0, 270):TOPVECTOR).
|
||||||
|
if GetPitch(newHeading:FOREVECTOR) < minPitch {
|
||||||
|
set newHeading to heading(90, minPitch, 270).
|
||||||
|
}
|
||||||
|
return newHeading.
|
||||||
|
}
|
||||||
|
|
||||||
function AddCircularizationNode {
|
function AddCircularizationNode {
|
||||||
parameter usePeriapsis is false.
|
parameter usePeriapsis is false.
|
||||||
local target is SHIP:ORBIT:APOAPSIS.
|
local target is SHIP:ORBIT:APOAPSIS.
|
||||||
|
|
|
@ -2,14 +2,7 @@
|
||||||
@lazyglobal off.
|
@lazyglobal off.
|
||||||
|
|
||||||
local G is 9.81.
|
local G is 9.81.
|
||||||
lock G to GetGravAcc().
|
lock G to SHIP:BODY:MU / ((SHIP:BODY:RADIUS+SHIP:ALTITUDE)^2).
|
||||||
|
|
||||||
function GetGravAcc {
|
|
||||||
if HAS_GRAV_SENSOR = true {
|
|
||||||
return SHIP:SENSORS:GRAV:MAG.
|
|
||||||
}
|
|
||||||
return SHIP:BODY:MU / ((SHIP:BODY:RADIUS+SHIP:ALTITUDE)^2).
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the throttle value you should use to achieve the
|
// Returns the throttle value you should use to achieve the
|
||||||
// target TWR. If TWR can't be achieved, returns 1.0. (full throttle)
|
// target TWR. If TWR can't be achieved, returns 1.0. (full throttle)
|
||||||
|
@ -27,22 +20,6 @@ function TWR {
|
||||||
return t/(m*G).
|
return t/(m*G).
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for various sensors and set appropriate global constants.
|
|
||||||
// Currently only checks for grav sensor, as that's the only one used by this library.
|
|
||||||
global HAS_GRAV_SENSOR is false.
|
|
||||||
function SensorCheck {
|
|
||||||
local SensorList is 0.
|
|
||||||
list SENSORS in SensorList.
|
|
||||||
for s in SensorList {
|
|
||||||
if s:type = "grav" {
|
|
||||||
print "Gravometric sensor detected".
|
|
||||||
set HAS_GRAV_SENSOR to true.
|
|
||||||
return.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set HAS_GRAV_SENSOR to false.
|
|
||||||
}
|
|
||||||
|
|
||||||
function BurnTime {
|
function BurnTime {
|
||||||
parameter dV.
|
parameter dV.
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ local initialPitch is hBox:AddTextField("85").
|
||||||
|
|
||||||
local hBox is interface:AddHBox().
|
local hBox is interface:AddHBox().
|
||||||
hBox:AddLabel("Minimum Pitch").
|
hBox:AddLabel("Minimum Pitch").
|
||||||
local minimumPitch is hBox:AddTextField("40").
|
local minimumPitch is hBox:AddTextField("5").
|
||||||
|
|
||||||
local hBox is interface:AddHBox().
|
local hBox is interface:AddHBox().
|
||||||
hBox:AddLabel("Gravity Turn @").
|
hBox:AddLabel("Gravity Turn @").
|
||||||
|
|
Loading…
Reference in New Issue
Block a user