import("library/lib_staging"). import("library/lib_math"). import("library/lib_vessel_utils"). import("library/lib_orbits"). declare function Ascent{ parameter targetOrbit is 100000. parameter vericalAscent is 1000. parameter ascentProfile is 1.2. parameter circ is 1. parameter inc is 0. print "Params (" + targetOrbit + ", " + vericalAscent + ", " + ascentProfile + ", " + circ + ", " + inc + ")". print "Vertical Climb to " + vericalAscent. set tgtPitch to 90. set isDone to false. lock throttle to 1. local head to 90 + inc. lock steering to heading(head, tgtPitch, 270). local lock asccent_prog to Map(apoapsis, 0, targetOrbit, 0.0, 1.0). wait until altitude > vericalAscent and asccent_prog > 0. print "Start Gravity turn. Target Apoapsis: " + targetOrbit. local lock ease to EaseOutExp(asccent_prog, ascentProfile). local lock tgtPitch to (1 - ease) * 90. when periapsis < targetOrbit then { print "P: " + round(asccent_prog, 2) + " T:" + round(ease, 2) + " Pitch: " + round(tgtPitch, 2) + " " at(0, 3). print "Ap: " + round(apoapsis, 2) + " Pe:" + round(periapsis, 2) + " Alt: " + round(altitude, 2) + " " at(0, 4). wait 0.1. if not isDone{ preserve. } } //Auto Staging when periapsis < targetOrbit then{ AutoStage(). wait 0.01. if not isDone{ preserve. } } wait until apoapsis >= targetOrbit. unlock tgt_pitch. lock tgtPitch to 0. unlock steering. if circ = 1 { CircularizeBrute(targetOrbit, head). }else if circ = 2{ Circularize(targetOrbit, head). }else if circ = 3 { lock steering to heading(head, 0, 270). CreateCircularizationNode(apoapsis). } set isDone to true. unlock steering. unlock throttle. wait until throttle = 0. } local function Circularize{ parameter tgt. parameter head. lock throttle to 0. lock steering to heading(head, 0, 270). local warpTime is eta:apoapsis. local burnDv is CalculateCircularizationDV(tgt, orbit:semimajoraxis). local burnDuration is CalculateMultiStageBurnDuration(burnDv). local remDv is ship:deltav:current - burnDv. print "Warping to Circularization. " + round(burnDv) + "m/s. T: " + round(burnDuration, 2) + "s" at(0, 5). print "Final Dv expected: " + remDv + "m/s". set warpTime to warpTime - burnDuration /2. if warpTime > 0 { wait until throttle = 0. wait 0.01. //Wait for accelleration to stop set warpmode to "physics". warpTo(time:seconds + warpTime - 3). wait until eta:apoapsis >= burnDuration /2. } lock throttle to 1. // wait burnDuration. wait until periapsis >= tgt. lock throttle to 0. wait 0.01. } local function CircularizeBrute{ parameter tgt. parameter head. lock throttle to 1. lock steering to heading(head, 0, 270). wait until periapsis >= tgt. lock throttle to 0. } local function CreateCircularizationNode{ parameter tgt. lock throttle to 0. wait until altitude > 80000. local burnDv is CalculateCircularizationDV(tgt, orbit:semimajoraxis). set circNode to Node(eta:apoapsis, 0, 0, burnDv). add circNode. }