diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88bf31b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.ksm \ No newline at end of file diff --git a/ayame.ks b/ayame.ks index f8ee633..194772f 100644 --- a/ayame.ks +++ b/ayame.ks @@ -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. diff --git a/ayame.ksm b/ayame.ksm index 82512b9..1c10e14 100644 Binary files a/ayame.ksm and b/ayame.ksm differ diff --git a/faris5.ks b/faris5.ks index 767e99a..3dcb1b3 100644 --- a/faris5.ks +++ b/faris5.ks @@ -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. diff --git a/genericOrbit.ks b/genericOrbit.ks index 2d6760a..1cefcf4 100644 --- a/genericOrbit.ks +++ b/genericOrbit.ks @@ -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: ". diff --git a/genericOrbit.ksm b/genericOrbit.ksm index 290018f..ad61912 100644 Binary files a/genericOrbit.ksm and b/genericOrbit.ksm differ diff --git a/hazuki.ks b/hazuki.ks index 167c291..5e42ff3 100644 --- a/hazuki.ks +++ b/hazuki.ks @@ -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. diff --git a/hazuki.ksm b/hazuki.ksm index 19c13c9..6b7988f 100644 Binary files a/hazuki.ksm and b/hazuki.ksm differ diff --git a/library/lib_ascent.ks b/library/lib_ascent.ks index 5f10748..f258958 100644 --- a/library/lib_ascent.ks +++ b/library/lib_ascent.ks @@ -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. + } } \ No newline at end of file diff --git a/library/lib_ascent.ksm b/library/lib_ascent.ksm index 1264f9c..c9bf3bf 100644 Binary files a/library/lib_ascent.ksm and b/library/lib_ascent.ksm differ diff --git a/library/lib_gui.ksm b/library/lib_gui.ksm index 1dd007c..d9c5c20 100644 Binary files a/library/lib_gui.ksm and b/library/lib_gui.ksm differ diff --git a/library/lib_import.ksm b/library/lib_import.ksm index 4a988bb..ccc97eb 100644 Binary files a/library/lib_import.ksm and b/library/lib_import.ksm differ diff --git a/library/lib_math.ksm b/library/lib_math.ksm index 4f0c9c6..d660d77 100644 Binary files a/library/lib_math.ksm and b/library/lib_math.ksm differ diff --git a/library/lib_num_to_formatted_str.ksm b/library/lib_num_to_formatted_str.ksm index ed47600..a555607 100644 Binary files a/library/lib_num_to_formatted_str.ksm and b/library/lib_num_to_formatted_str.ksm differ diff --git a/library/lib_orbits.ksm b/library/lib_orbits.ksm index 221a4db..49cebb2 100644 Binary files a/library/lib_orbits.ksm and b/library/lib_orbits.ksm differ diff --git a/library/lib_staging.ksm b/library/lib_staging.ksm index 75f5590..5848e47 100644 Binary files a/library/lib_staging.ksm and b/library/lib_staging.ksm differ diff --git a/library/lib_vessel_utils.ks b/library/lib_vessel_utils.ks index f306083..1a43f42 100644 --- a/library/lib_vessel_utils.ks +++ b/library/lib_vessel_utils.ks @@ -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. diff --git a/library/lib_vessel_utils.ksm b/library/lib_vessel_utils.ksm index e996b9d..dfae5c1 100644 Binary files a/library/lib_vessel_utils.ksm and b/library/lib_vessel_utils.ksm differ diff --git a/tests.ks b/tests.ks index 237cd33..c4a90a3 100644 --- a/tests.ks +++ b/tests.ks @@ -2,4 +2,5 @@ import("library/lib_ascent"). CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal"). -Ascent(95000, 1000, 0.7, 3). + +GetPerStageBurnData(). \ No newline at end of file diff --git a/tests.ksm b/tests.ksm index e81e6db..94bfc87 100644 Binary files a/tests.ksm and b/tests.ksm differ