added orbit correction + mqx q throttle moderation

This commit is contained in:
2026-05-05 03:34:55 -04:00
parent 73868e47db
commit b554b94428
20 changed files with 186 additions and 39 deletions
+1
View File
@@ -0,0 +1 @@
*.ksm
+2 -2
View File
@@ -6,7 +6,7 @@ if status = "PRELAUNCH" {
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
set profile to 0.7.
set profile to 0.6.
set turn_start to 1000.
set target_orbit to 100000.
@@ -14,7 +14,7 @@ if status = "PRELAUNCH" {
ag1 on.
}
Ascent(target_orbit, turn_start, profile, 3).
Ascent(target_orbit, turn_start, profile, 3, 0).
wait 30.
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -4,7 +4,7 @@ WaitForEngineStart().
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
set profile to 0.7.
set profile to 0.5.
set turn_start to 1000.
set target_orbit to 120000.
+2 -2
View File
@@ -6,9 +6,9 @@ if status = "PRELAUNCH" {
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
print "Enter Launch Profile: ".
set profile to terminal_input_number(22, 0, 4, 0.7).
set profile to terminal_input_number(22, 0, 6, 0.4).
print "Verical Ascent: ".
set turn_start to terminal_input_number(16, 1, 6, 1000).
set turn_start to terminal_input_number(16, 1, 6, 500).
print "Target Orbit: ".
set target_orbit to terminal_input_number(14, 2, 8, 96000).
print "Inclination: ".
BIN
View File
Binary file not shown.
+8 -3
View File
@@ -6,14 +6,19 @@ if status = "PRELAUNCH" {
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
set profile to 0.7.
set turn_start to 1000.
set target_orbit to 960000.
set turn_start to 500.
set target_orbit to 96000.
set circ to 3.
if ship:name = "Hazuki 3.5" {
set profile to 0.4.
}
when altitude > 80000 then {
ag1 on.
}
Ascent(target_orbit, turn_start, profile, 3).
Ascent(target_orbit, turn_start, profile, circ).
wait 30.
BIN
View File
Binary file not shown.
+100 -29
View File
@@ -8,41 +8,44 @@ 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).
@@ -50,7 +53,7 @@ declare function Ascent{
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().
}
@@ -302,3 +330,46 @@ local function RenderStatusBar{
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.
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+69
View File
@@ -174,6 +174,75 @@ function CalculateMultiStageBurnDuration{
}
}
function CalculateMultiStageBurnDurationV2{
parameter dv.
if ship:STAGEDELTAV(ship:stagenum):current >= dv {
return CalculateBurnDuration(dv, GetIsp(), ship:mass, GetMaxMassFlow()).
}else{
local bT is 0.
local remDv is dv.
from {local s is ship:stagenum. } until s = -1 step { set s to s-1.} do {
if remDv <= 0 {
return bT.
}
local cdv is ship:stagedeltav(s):current.
local cmass is GetMassOfStage(s).
local cflow is GetMaxMassFlowForStage(s).
local cisp is GetIspForStage(s).
local sdv is 0.
if cdv >= remDv {
set sdv to remDv.
}else{
set sdv to cdv.
}
set bT to bT + CalculateBurnDuration(sdv, cisp, cmass, cflow).
set remDv to remDv - cdv.
}
return bT.
}
}
function GetPerStageBurnData{
parameter pressure is 0.
local data is list().
local i is 0.
until i >= ship:stagenum {
data:add(lex()).
set data[i]["dv"] to ship:stagedeltav(i):current.
set i to i + 1.
}
LIST PARTS IN allP.
for p in allP {
IF p:ISTYPE("Engine")
{
local t is p:POSSIBLETHRUSTAT(pressure).
if data[p:stage]:haskey("thrust") {
set t to t + data[p:stage]["thrust"].
}
set data[p:stage]["thrust"] to t.
}
if p:DECOUPLEDIN < p:stage or p:DECOUPLEDIN = p:stage {
local m is p:mass.
print "s: " + p:stage + " d: " + p:DECOUPLEDIN + " n: " + p:name.
local s is max(0, p:stage).
if data[s]:haskey("mass") {
set m to m + data[s]["mass"].
}
set data[s]["mass"] to m.
}
}
set i to 0.
until i >= ship:stagenum {
if i = 0 {
set data[i]["totalMass"] to data[i]["mass"].
} else {
set data[i]["totalMass"] to data[i]["mass"] + data[i - 1]["totalMass"].
}
set i to i+1.
}
return data.
}
function GetThrustOfStage {
parameter st, p is 0.
Binary file not shown.
+2 -1
View File
@@ -2,4 +2,5 @@ import("library/lib_ascent").
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
Ascent(95000, 1000, 0.7, 3).
GetPerStageBurnData().
BIN
View File
Binary file not shown.