added orbit correction + mqx q throttle moderation
This commit is contained in:
+101
-30
@@ -8,49 +8,52 @@ import("library/lib_gui").
|
||||
declare ASCENT_STATE is "Pre-Launch".
|
||||
|
||||
declare function Ascent{
|
||||
parameter targetOrbit is 100000,
|
||||
local parameter targetOrbit is 100000,
|
||||
vericalAscent is 1000,
|
||||
ascentProfile is 1.2,
|
||||
circ is 1,
|
||||
inc is 0.
|
||||
inc is 0,
|
||||
maxQ is 15.
|
||||
|
||||
// local tgtOrbitSI is si_formatting(targetOrbit, "m").
|
||||
local vericalAscentSI is si_formatting(vericalAscent, "m").
|
||||
|
||||
set tgtPitch to 90.
|
||||
local head to 90 + inc.
|
||||
|
||||
lock throttle to 1.
|
||||
lock throttle to GetThrottle(maxQ).
|
||||
lock tgtPitch to 00.
|
||||
PrepareHUD(targetOrbit, vericalAscent, ascentProfile, circ, inc).
|
||||
|
||||
|
||||
//HUD
|
||||
when true then {
|
||||
RenderHUD(vericalAscentSI, tgtPitch).
|
||||
wait 0.01.
|
||||
if ASCENT_STATE <> "DONE" {
|
||||
if ASCENT_STATE <> "Done" {
|
||||
preserve.
|
||||
}
|
||||
}
|
||||
WaitForEngineStart().
|
||||
|
||||
lock steering to heading(90, 90, 270).
|
||||
|
||||
|
||||
lock steering to heading(head, tgtPitch, 270).
|
||||
|
||||
local lock asccent_prog to Map(apoapsis, 0, targetOrbit, 0.0, 1.0).
|
||||
local lock asccent_prog to Map(apoapsis, vericalAscent, targetOrbit, 0.0, 1.0).
|
||||
|
||||
SetState("Vertical Ascent").
|
||||
wait until altitude > vericalAscent and asccent_prog > 0.
|
||||
|
||||
SetState("Gravity Turn").
|
||||
local lock ease to EaseOutExp(asccent_prog, ascentProfile).
|
||||
lock ease to EaseOutExp(asccent_prog, ascentProfile).
|
||||
lock tgtPitch to (1 - ease) * 90.
|
||||
lock steering to heading(head, tgtPitch, 270).
|
||||
|
||||
|
||||
|
||||
|
||||
//Auto Staging
|
||||
when periapsis < targetOrbit then{
|
||||
AutoStage().
|
||||
wait 0.01.
|
||||
if ASCENT_STATE <> "DONE" {
|
||||
if ASCENT_STATE <> "Done" {
|
||||
preserve.
|
||||
}
|
||||
}
|
||||
@@ -74,6 +77,11 @@ declare function Ascent{
|
||||
CreateCircularizationNode(apoapsis).
|
||||
}
|
||||
|
||||
if periapsis < 80000 {
|
||||
SetState("Orbit Correction").
|
||||
FixOrbitalInsertion().
|
||||
}
|
||||
|
||||
SetState("Done").
|
||||
unlock steering.
|
||||
unlock throttle.
|
||||
@@ -81,6 +89,17 @@ declare function Ascent{
|
||||
wait until throttle = 0.
|
||||
}
|
||||
|
||||
|
||||
local function GetThrottle{
|
||||
local parameter maxQ.
|
||||
lock curQ to ship:q * constant:ATMtokPa.
|
||||
if curQ > maxQ {
|
||||
return min(1, max(0.5, Map(curQ, maxQ, maxQ * 1.2, 1, 0))).
|
||||
}else {
|
||||
return 1.
|
||||
}
|
||||
}
|
||||
|
||||
local function Circularize{
|
||||
parameter tgt, head.
|
||||
|
||||
@@ -114,8 +133,9 @@ local function Circularize{
|
||||
local function CircularizeBrute{
|
||||
parameter tgt, head.
|
||||
lock throttle to 1.
|
||||
lock steering to heading(head, 0, 270).
|
||||
wait until periapsis >= tgt.
|
||||
local lock aoa to vAng(heading(head, 0, 270):forevector, ship:velocity:surface).
|
||||
lock steering to heading(head, -aoa, 270).
|
||||
wait until periapsis >= 80000.
|
||||
lock throttle to 0.
|
||||
}
|
||||
|
||||
@@ -133,7 +153,7 @@ local function CreateCircularizationNode{
|
||||
PrintRightAligned(c, 12, c - 2, burnDurationSI).
|
||||
if hasNode {
|
||||
PrintRightAligned(2, 13, c - 4, si_formatting(nextNode:deltav:mag, "m/s")).
|
||||
PrintRightAligned(c, 13, c - 2, time_formatting(circNode:eta - burnDuration /2, 0, 0, true, false)).
|
||||
PrintRightAligned(c, 13, c - 2, time_formatting(nextNode:eta - burnDuration /2, 0, 0, true, false)).
|
||||
}
|
||||
wait 0.01.
|
||||
if ASCENT_STATE = "Circularization" {
|
||||
@@ -150,11 +170,18 @@ local function CreateCircularizationNode{
|
||||
lock steering to circNode:burnvector.
|
||||
set burnDuration to CalculateMultiStageBurnDuration(burnDv).
|
||||
set burnDurationSI to time_formatting(burnDuration).
|
||||
local burnStart is circNode:eta - burnDuration /2.
|
||||
if burnStart > 10 {
|
||||
warpTo(time:seconds + burnStart - 10).
|
||||
}
|
||||
|
||||
wait until circNode:eta <= burnDuration /2.
|
||||
lock throttle to 1.
|
||||
wait until nextNode:deltav:mag <= 10.
|
||||
lock throttle to 0.25.
|
||||
wait until NEXTNODE:deltav:mag <= 1.
|
||||
wait until nextNode:deltav:mag <= max(20, burnDv * 0.1).
|
||||
lock throttle to 0.75.
|
||||
wait until NEXTNODE:deltav:mag <= max(10, burnDv * 0.05).
|
||||
lock throttle to 0.4.
|
||||
wait until NEXTNODE:deltav:mag <= max(1, burnDv * 0.01).
|
||||
lock throttle to 0.
|
||||
unlock steering.
|
||||
remove nextNode.
|
||||
@@ -196,6 +223,7 @@ local function PrepareHUD{
|
||||
PrepareGuidanceHUD().
|
||||
}
|
||||
|
||||
|
||||
local function PrepareOrbitHUD{
|
||||
local c is terminal:width /2.
|
||||
print "Altitude:" at (2, 6).
|
||||
@@ -224,12 +252,12 @@ local function PrepareGuidanceHUD{
|
||||
print "AoA:" at (c, 13).
|
||||
}else if ASCENT_STATE = "Circularization" {
|
||||
|
||||
}else if ASCENT_STATE = "Orbit Correction" {
|
||||
print "Not yet in orbit! Attempting to Correct..." at (2, 12).
|
||||
|
||||
}else if ASCENT_STATE = "Done" {
|
||||
if periapsis > 80000 {
|
||||
print "Orbit Achieved" at (2, 12).
|
||||
} else{
|
||||
print "Not yet in orbit! Perform corrections manually!" at (2, 12).
|
||||
}
|
||||
print "Orbit Achieved" at (2, 12).
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +273,7 @@ local function PrepareCircNodeHUD{
|
||||
|
||||
local function RenderHUD{
|
||||
parameter veriticalAscSI.
|
||||
parameter tgtPitch.
|
||||
parameter tgtPitch is 0.
|
||||
|
||||
local c is terminal:width /2.
|
||||
//Orbit Section
|
||||
@@ -272,11 +300,11 @@ local function RenderHUD{
|
||||
}else if ASCENT_STATE = "Gravity Turn" {
|
||||
local curPitch is 90 - VANG(ship:up:forevector, ship:facing:forevector).
|
||||
local aoa is vAng(ship:facing:vector, ship:velocity:surface).
|
||||
local dPitch is tgtPitch - curPitch.
|
||||
PrintRightAligned(2, 12, c - 4, round(tgtPitch, 2) + "°").
|
||||
PrintRightAligned(c, 12, c - 2, round(curPitch, 2) + "°").
|
||||
PrintRightAligned(2, 13, c - 4, round(dPitch, 2) + "°").
|
||||
PrintRightAligned(c, 13, c - 2, round(aoa, 2) + "°").
|
||||
local dPitch is curPitch - tgtPitch.
|
||||
PrintRightAligned(2, 12, c - 4, " " + round(tgtPitch, 2) + "°").
|
||||
PrintRightAligned(c, 12, c - 2, " " + round(curPitch, 2) + "°").
|
||||
PrintRightAligned(2, 13, c - 4, " " + round(dPitch, 2) + "°").
|
||||
PrintRightAligned(c, 13, c - 2, " " + round(aoa, 2) + "°").
|
||||
}else if ASCENT_STATE = "Circularization" {
|
||||
|
||||
}else if ASCENT_STATE = "Done" {
|
||||
@@ -293,7 +321,7 @@ local function SetState{
|
||||
parameter stateText.
|
||||
set ASCENT_STATE to stateText.
|
||||
ClearArea(2, 11, terminal:width - 4, 6, " ").
|
||||
PrintCentered(0, 11, terminal:width, "Guidance - " + ASCENT_STATE).
|
||||
PrintCentered(2, 11, terminal:width - 4, "Guidance - " + ASCENT_STATE).
|
||||
PrepareGuidanceHUD().
|
||||
}
|
||||
|
||||
@@ -301,4 +329,47 @@ local function RenderStatusBar{
|
||||
// ClearArea(2, terminal:height - 3, terminal:width - 4, 1, " ").
|
||||
print "Status: " + status + " " at (2, terminal:height - 3) .
|
||||
PrintRightAligned(2, terminal:height - 3, terminal:width - 4, ship:NAME + " - " + ship:type).
|
||||
}
|
||||
|
||||
local function FixOrbitalInsertion{
|
||||
local parameter tgtAlt.
|
||||
// Ap is behind ship
|
||||
if eta:apoapsis < orbit:period / 2 {
|
||||
print "Performing Radial Correction..." at (2, 13).
|
||||
lock steering to up.
|
||||
wait until vAng(ship:facing:forevector, up:forevector) < 2.
|
||||
lock throttle to 0.2.
|
||||
wait until eta:apoapsis <= orbit:period / 2.
|
||||
lock throttle to 0.
|
||||
lock steering to prograde.
|
||||
wait until vAng(ship:facing:forevector, prograde:forevector) < 2.
|
||||
lock throttle to Map(periapsis, 0, tgtAlt, 1, 0.1).
|
||||
wait until periapsis > tgtAlt.
|
||||
lock throttle to 0.
|
||||
}else{
|
||||
//Ap is ahead
|
||||
print "Performing Circularization Correction..." at (2, 13).
|
||||
local burnDv is CalculateCircularizationDV(tgtAlt, orbit:semimajoraxis).
|
||||
local burnDuration to CalculateBurnDuration(burnDv).
|
||||
local circNode is Node(time:seconds + eta:apoapsis, 0, 0, burnDv).
|
||||
add circNode.
|
||||
wait 0.01.
|
||||
lock steering to circNode:burnvector.
|
||||
local burnStart is circNode:eta - burnDuration /2.
|
||||
if burnStart > 10 {
|
||||
warpTo(time:seconds + burnStart - 10).
|
||||
}
|
||||
wait until circNode:eta <= burnDuration /2.
|
||||
lock throttle to 1.
|
||||
wait until nextNode:deltav:mag <= max(20, burnDv * 0.1).
|
||||
lock throttle to 0.75.
|
||||
wait until NEXTNODE:deltav:mag <= max(10, burnDv * 0.05).
|
||||
lock throttle to 0.4.
|
||||
wait until NEXTNODE:deltav:mag <= max(1, burnDv * 0.01).
|
||||
lock throttle to 0.
|
||||
unlock steering.
|
||||
remove nextNode.
|
||||
wait 0.01.
|
||||
wait until throttle = 0.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user