Compare commits

..

4 Commits

4 changed files with 76 additions and 7 deletions

View File

@ -92,8 +92,8 @@ function Launch {
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. // make sure these control updates get applied wait 0.001. // make sure these control updates get applied
add CreateCircularizationNode().
ExecNode(). insertionBurn(apoapsisTarget).
print "Ascent Complete.". print "Ascent Complete.".
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0. set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
@ -101,3 +101,54 @@ function Launch {
unlock STEERING. unlock STEERING.
SAS on. SAS on.
} }
// Calculate and perform the insertion burn for orbit.
// The reason to prefer this over CreateCircularizationNode() and ExecNode() is that the amount of RCS needed
// to vector into position during launch adjusts our orbit significantly. This gives us a "wait until" that
// serves the specific needs of launch.
// It also makes automated launches possible before maneuver nodes are unlocked.
//
// TODO: Refactor code reuse between this function and ExecNode().
//
// prerequisites:
// * Vessel is still behind the Apoapsis
// * Apoapsis is at the target height
function insertionBurn {
parameter apoapsisTarget.
// vector is prograde but only on the horizonal plane
print "Adjusting heading.".
local lock horizon is Vxcl(SHIP:UP:FOREVECTOR, SHIP:PROGRADE:FOREVECTOR).
lock STEERING to LookDirUp(horizon, SHIP:FACING:TOPVECTOR).
// calculate the deltaV to get us to the target velocity, for calculating burn start time.
local t is TIME + SHIP:ORBIT:ETA:APOAPSIS.
local Vc is sqrt(SHIP:BODY:MU/(PositionAt(SHIP, t) - SHIP:BODY:POSITION):MAG).
local dV is Vc - VelocityAt(SHIP, t):ORBIT:MAG.
if WillStage(dV) {
when FlameOut() then {
print "Flameout detected. Staging.".
stage.
}
}
// calculate the total burn time (Tb) and the burn start time (Ts)
local Tb is BurnTime(dV).
local Ts is TIME + SHIP:OBT:ETA:APOAPSIS - BurnTime(dV / 2).
// warp to the burn point
print "Waiting for burn window.".
wait until (VAng(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.5) OR (TIME > Ts).
if TIME < Ts - 2 {
KUNIVERSE:TIMEWARP:WarpTo(Ts:SECONDS - 2).
}
wait until SHIP:UNPACKED.
wait until TIME > Ts.
// burn until periapsis is clear
print "Circularizing orbit.".
lock THROTTLE to 1.0.
wait until SHIP:OBT:PERIAPSIS > apoapsisTarget.
lock THROTTLE to 0.0.
}

View File

@ -102,6 +102,9 @@ function BurnTime {
local lastStage is false. local lastStage is false.
// We allow a small tolerance to deal with potential floating point errors. // We allow a small tolerance to deal with potential floating point errors.
until totaldV <= 0.001 { until totaldV <= 0.001 {
if s < 0 {
print "Ran out of fuel with " + totaldV + " dV remaining".
}
local F is stageThrust(s). local F is stageThrust(s).
local Isp is stageISP(s). local Isp is stageISP(s).
local m is stageMass(s). local m is stageMass(s).

View File

@ -3,14 +3,20 @@
// stages, spools up the engines, and then "releases control" // stages, spools up the engines, and then "releases control"
// to the main ship computer. // to the main ship computer.
// //
// *** CONSTRUCTION NOTES ***
// If using this script, put the annabuncheskOS-launchpad.cfg file from the patches/ directory into your GameData/
// directory. This will ensure the launchpad has a high enough fuel flow rate for the spool-up sequence.
// If your lower stage uses engine plates, be sure to attach the launch pad to one of the *engine* bottom nodes,
// not the Engine Plate's bottom node. Otherwise fuel delivery won't work.
//
// *** TAGGING REQUIREMENTS *** // *** TAGGING REQUIREMENTS ***
// The launchpad object should have the "launchpad" tag. // The launchpad object should have the "launchpad" tag.
// The ship's main CPU (the one with launch functionality" should be tagged "shipcpu". // The ship's main CPU (the one with launch functionality" should be tagged "shipcpu".
// Fuel tanks with the "nofuel" tag will have *all* resources temporarily disabled during the pre-launch // Fuel tanks with the "nofuel" tag will have *all* resources temporarily disabled during the pre-launch
// sequence. The main ship computer must re-enable them after staging. NoFuelResources() in lib/systems is ideal // sequence. The main ship computer must re-enable them after staging. NoFuelResources() in lib/systems is ideal
// for this. // for this.
// Similarly, any crossfeed-capable decouplers tagged "prelaunch" will have crossfeed ENABLED during pre-launch. // Similarly, any crossfeed-capable decouplers tagged "prelaunch" will have crossfeed ENABLED during pre-launch.
// MainCPU should, again, disable these once it stages. PreLaunchCrossfeed() in lib/systems is your friend. // MainCPU should, again, disable these once it stages. PreLaunchCrossfeed() in lib/systems is your friend.
RunOncePath("/lib/systems"). RunOncePath("/lib/systems").
RunOncePath("/lib/ui"). RunOncePath("/lib/ui").

View File

@ -122,7 +122,9 @@ MakeMenu(
MakeButton(rows[2], "Node"), MakeButton(rows[2], "Node"),
List( List(
List("Node dV", "RO", "0"), List("Node dV", "RO", "0"),
List("Node Burn Time", "RO", "0") List("Node Burn Time", "RO", "0"),
List("Node Lead Time", "RO", "0"),
List("Burn Start ETA", "RO", "0")
), ),
"Execute", "Execute",
{ {
@ -132,11 +134,18 @@ MakeMenu(
{ {
parameter options. parameter options.
if HASNODE { if HASNODE {
local burnTime is BurnTime(NEXTNODE:DELTAV:MAG).
local leadTime is BurnTime(NEXTNODE:DELTAV:MAG / 2).
set options["Node dV"]:TEXT to NEXTNODE:DELTAV:MAG:ToString. set options["Node dV"]:TEXT to NEXTNODE:DELTAV:MAG:ToString.
set options["Node Burn Time"]:TEXT to BurnTime(NEXTNODE:DELTAV:MAG):ToString. set options["Node Burn Time"]:TEXT to burnTime:ToString.
set options["Node Lead Time"]:TEXT to leadTime:ToString.
set options["Burn Start ETA"]:TEXT to (NEXTNODE:ETA - leadTime):ToString.
} else { } else {
set options["Node dV"]:TEXT to "No Node". set options["Node dV"]:TEXT to "No Node".
set options["Node Burn Time"]:TEXT to "No Node". set options["Node Burn Time"]:TEXT to "No Node".
set options["Node Lead Time"]:TEXT to "No Node".
set options["Burn Start ETA"]:TEXT to "No Node".
} }
} }
). ).