diff --git a/ayame.ks b/ayame.ks index 4a30e68..f8ee633 100644 --- a/ayame.ks +++ b/ayame.ks @@ -8,7 +8,7 @@ if status = "PRELAUNCH" { set profile to 0.7. set turn_start to 1000. - set target_orbit to 120000. + set target_orbit to 100000. when altitude > 80000 then { ag1 on. @@ -16,6 +16,8 @@ if status = "PRELAUNCH" { Ascent(target_orbit, turn_start, profile, 3). + wait 30. + SET V0 TO GETVOICE(0). V0:PLAY( NOTE(400, 2.5) ). diff --git a/ayame.ksm b/ayame.ksm new file mode 100644 index 0000000..82512b9 Binary files /dev/null and b/ayame.ksm differ diff --git a/defaults.ks b/defaults.ks index 642ffd3..f0bcf62 100644 --- a/defaults.ks +++ b/defaults.ks @@ -1,4 +1,7 @@ set terminal:charheight to 20. - -copyPath("0:/library/lib_import", "1:/library/lib_import"). -run "library/lib_import". \ No newline at end of file +if status = "PRELAUNCH" +{ + compile "0:/library/lib_import.ks" to "0:/library/lib_import.ksm". + copyPath("0:/library/lib_import.ksm", "1:/library/lib_import.ksm"). +} +runOncePath("library/lib_import"). \ No newline at end of file diff --git a/genericOrbit.ks b/genericOrbit.ks index 96b8239..2d6760a 100644 --- a/genericOrbit.ks +++ b/genericOrbit.ks @@ -10,20 +10,19 @@ if status = "PRELAUNCH" { print "Verical Ascent: ". set turn_start to terminal_input_number(16, 1, 6, 1000). print "Target Orbit: ". - set target_orbit to terminal_input_number(14, 2, 8, 120000). + set target_orbit to terminal_input_number(14, 2, 8, 96000). print "Inclination: ". set inclination to terminal_input_number(13, 3, 8, 0). print "Circularization: ". set circ to terminal_input_number(17, 4, 8, 3). - print "Waiting for Engine Start...". - WaitForEngineStart(). clearScreen. sas off. Ascent(target_orbit:toscalar(0), turn_start:toscalar(0), profile:toscalar(0), circ:toscalar(0), inclination:toscalar(0)). + wait 30. CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal"). sas on. SHUTDOWN. diff --git a/genericOrbit.ksm b/genericOrbit.ksm new file mode 100644 index 0000000..290018f Binary files /dev/null and b/genericOrbit.ksm differ diff --git a/hazuki.ks b/hazuki.ks index c56b6d6..167c291 100644 --- a/hazuki.ks +++ b/hazuki.ks @@ -7,7 +7,7 @@ if status = "PRELAUNCH" { set profile to 0.7. set turn_start to 1000. - set target_orbit to 100000. + set target_orbit to 960000. when altitude > 80000 then { ag1 on. @@ -15,6 +15,8 @@ if status = "PRELAUNCH" { Ascent(target_orbit, turn_start, profile, 3). + wait 30. + print "Orbit Achieved, Releasing Controls". CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal"). SHUTDOWN. diff --git a/hazuki.ksm b/hazuki.ksm new file mode 100644 index 0000000..19c13c9 Binary files /dev/null and b/hazuki.ksm differ diff --git a/library/defaults.ks b/library/defaults.ks new file mode 100644 index 0000000..2482de8 --- /dev/null +++ b/library/defaults.ks @@ -0,0 +1,4 @@ +set terminal:charheight to 20. +compile "0:/library/lib_import.ks" to "0:/library/lib_import.ksm". +copyPath("0:/library/lib_import.ksm", "1:/library/lib_import.ksm"). +run "library/lib_import". \ No newline at end of file diff --git a/library/lib_ascent.ks b/library/lib_ascent.ks index 43447ac..5f10748 100644 --- a/library/lib_ascent.ks +++ b/library/lib_ascent.ks @@ -2,57 +2,69 @@ import("library/lib_staging"). import("library/lib_math"). import("library/lib_vessel_utils"). import("library/lib_orbits"). +import("library/lib_num_to_formatted_str"). +import("library/lib_gui"). + +declare ASCENT_STATE is "Pre-Launch". declare function Ascent{ - parameter targetOrbit is 100000. - parameter vericalAscent is 1000. - parameter ascentProfile is 1.2. - parameter circ is 1. - parameter inc is 0. + parameter targetOrbit is 100000, + vericalAscent is 1000, + ascentProfile is 1.2, + circ is 1, + inc is 0. - print "Params (" + targetOrbit + ", " + vericalAscent + ", " + ascentProfile + ", " + circ + ", " + inc + ")". - print "Vertical Climb to " + vericalAscent. + // local tgtOrbitSI is si_formatting(targetOrbit, "m"). + local vericalAscentSI is si_formatting(vericalAscent, "m"). set tgtPitch to 90. - set isDone to false. + local head to 90 + inc. lock throttle to 1. - local head to 90 + inc. + PrepareHUD(targetOrbit, vericalAscent, ascentProfile, circ, inc). + when true then { + RenderHUD(vericalAscentSI, tgtPitch). + wait 0.01. + if ASCENT_STATE <> "DONE" { + preserve. + } + } + WaitForEngineStart(). + + lock steering to heading(head, tgtPitch, 270). local lock asccent_prog to Map(apoapsis, 0, targetOrbit, 0.0, 1.0). + SetState("Vertical Ascent"). wait until altitude > vericalAscent and asccent_prog > 0. - print "Start Gravity turn. Target Apoapsis: " + targetOrbit. + SetState("Gravity Turn"). local lock ease to EaseOutExp(asccent_prog, ascentProfile). - local lock tgtPitch to (1 - ease) * 90. + 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{ + if ASCENT_STATE <> "DONE" { preserve. } } wait until apoapsis >= targetOrbit. + lock throttle to 0. + unlock tgt_pitch. lock tgtPitch to 0. unlock steering. + SetState("Circularization"). + if circ = 1 { CircularizeBrute(targetOrbit, head). }else if circ = 2{ @@ -60,12 +72,9 @@ declare function Ascent{ }else if circ = 3 { lock steering to heading(head, 0, 270). CreateCircularizationNode(apoapsis). - // if periapsis < targetOrbit and eta:apoapsis < orbit:period / 2{ - // CreateCircularizationNode(apoapsis). - // } } - set isDone to true. + SetState("Done"). unlock steering. unlock throttle. @@ -73,8 +82,7 @@ declare function Ascent{ } local function Circularize{ - parameter tgt. - parameter head. + parameter tgt, head. lock throttle to 0. lock steering to heading(head, 0, 270). @@ -104,8 +112,7 @@ local function Circularize{ } local function CircularizeBrute{ - parameter tgt. - parameter head. + parameter tgt, head. lock throttle to 1. lock steering to heading(head, 0, 270). wait until periapsis >= tgt. @@ -116,13 +123,33 @@ local function CreateCircularizationNode{ parameter tgt. lock throttle to 0. + local c is terminal:width /2. + PrepareCircNodeHUD(). + local burnDvSI is " ---". + local burnDurationSI is " ---". + local burnDuration is 0. + when true then { + PrintRightAligned(2, 12, c - 4, burnDvSI). + 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)). + } + wait 0.01. + if ASCENT_STATE = "Circularization" { + preserve. + } + } + wait until altitude > 80000. local burnDv is CalculateCircularizationDV(tgt, orbit:semimajoraxis). + set burnDvSI to si_formatting(burnDv, "m/s"). local circNode is Node(time:seconds + eta:apoapsis, 0, 0, burnDv). add circNode. wait 0.01. lock steering to circNode:burnvector. - local burnDuration is CalculateMultiStageBurnDuration(burnDv). + set burnDuration to CalculateMultiStageBurnDuration(burnDv). + set burnDurationSI to time_formatting(burnDuration). wait until circNode:eta <= burnDuration /2. lock throttle to 1. wait until nextNode:deltav:mag <= 10. @@ -133,4 +160,145 @@ local function CreateCircularizationNode{ remove nextNode. wait 0.01. wait until throttle = 0. +} + +local function PrepareHUD{ + parameter targetOrbit, + vericalAscent, + ascentProfile, + circ, + inc. + + clearScreen. + DrawWindow(0, 0, terminal:width, terminal:height, " Air Tako OS "). + + print "Ascent: " + si_formatting(vericalAscent, "m") + " with a " + ascentProfile + " ascent profile." at (2, 1). + print "Orbit: " + si_formatting(targetOrbit, "m") + " at " + inc + "°" at (2, 2). + local circText is "None". + if circ = 1 { + set circText to "Brute Force". + }else if circ = 2{ + set circText to "Blind Calculated". + }else if circ = 3 { + set circText to "Manuever Node". + } + print "Circularization Method: " + circText at (2, 3). + //Orbit Separator + DrawHorizontalLineCapped(0, 4, terminal:width, "┉"). + PrintCentered(0, 5, terminal:width, "Orbit"). + PrepareOrbitHUD(). + //Guidance Separator + DrawHorizontalLineCapped(0, 10, terminal:width, "┉"). + PrintCentered(0, 11, terminal:width, "Guidance - " + ASCENT_STATE). + //Status Bar + DrawHorizontalLineCapped(0, terminal:height - 4, terminal:width, "┉"). + + PrepareGuidanceHUD(). +} + +local function PrepareOrbitHUD{ + local c is terminal:width /2. + print "Altitude:" at (2, 6). + print "Surface Alt:" at (c, 6). + //Ap + print "Ap:" at (2, 7). + print "ETA:" at (c, 7). + //Pe + print "Pe:" at (2, 8). + print "ETA:" at (c, 8). + //Speeds + print "Air Speed:" at (2, 9). + print "Orbit Speed:" at (c, 9). +} + +local function PrepareGuidanceHUD{ + local c is terminal:width /2. + if ASCENT_STATE = "Pre-Launch" { + print "Waiting for engine start..." at (2, 12). + }else if ASCENT_STATE = "Vertical Ascent" { + print "Vertical Ascent:" at (2, 12). + }else if ASCENT_STATE = "Gravity Turn" { + print "Target Pitch:" at (2, 12). + print "Current Pitch:" at (c, 12). + print "Deviation:" at (2, 13). + print "AoA:" at (c, 13). + }else if ASCENT_STATE = "Circularization" { + + }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). + } + } +} + +local function PrepareCircNodeHUD{ + local c is terminal:width /2. + + print "Delta V:" at (2, 12). + print "Duration:" at (c, 12). + print "Burn:" at (2, 13). + print "ETA:" at (c, 13). +} + + +local function RenderHUD{ + parameter veriticalAscSI. + parameter tgtPitch. + + local c is terminal:width /2. + //Orbit Section + //altitude + PrintRightAligned(2, 6, c - 4, si_formatting(altitude, "m")). + PrintRightAligned(c, 6, c - 2, si_formatting(alt:radar, "m")). + //Ap + PrintRightAligned(2, 7, c - 4, si_formatting(apoapsis, "m")). + if airspeed < constant:e { + PrintRightAligned(c, 7, c - 2, "Inf" ). + }else{ + PrintRightAligned(c, 7, c - 2, time_formatting(eta:apoapsis) ). + } + //Pe + PrintRightAligned(2, 8, c - 4, si_formatting(periapsis, "m")). + PrintRightAligned(c, 8, c - 2, time_formatting(eta:periapsis)). + //Speeds + PrintRightAligned(2, 9, c - 4, si_formatting(airspeed, "m/s")). + PrintRightAligned(c, 9, c - 2, si_formatting(ship:velocity:orbit:mag, "m/s")). + + if ASCENT_STATE = "Pre-Launch" { + }else if ASCENT_STATE = "Vertical Ascent" { + print si_formatting(altitude, "m") + " of " + veriticalAscSI at (2 + 16, 12). + }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) + "°"). + }else if ASCENT_STATE = "Circularization" { + + }else if ASCENT_STATE = "Done" { + + } + + + + RenderStatusBar(). +} + + +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). + PrepareGuidanceHUD(). +} + +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). } \ No newline at end of file diff --git a/library/lib_ascent.ksm b/library/lib_ascent.ksm new file mode 100644 index 0000000..1264f9c Binary files /dev/null and b/library/lib_ascent.ksm differ diff --git a/library/lib_gui.ks b/library/lib_gui.ks new file mode 100644 index 0000000..c176eaa --- /dev/null +++ b/library/lib_gui.ks @@ -0,0 +1,89 @@ +function DrawWindow{ + parameter x,y,w,h,title. + DrawBox(x, y, w, h). + PrintCentered(x,y, w, title). +} + +function DrawBox{ + parameter x,y,w,h. + + if h < 0 or y + h >= terminal:height { + set h to max(1,min(terminal:height - 2 - y,h)). + } + + DrawHorizontalLineCapped(x, y, w, "━", "┏", "┓"). + DrawHorizontalLineCapped(x, y+h, w, "━", "┗", "┛"). + set i to 0. + until i > h - 2 { + set i to i + 1. + print "┃" at (x, y + i). + print "┃" at (x + w, y + i). + } +} + +function DrawHorizontalLine{ + parameter x,y,w,lineChar is "━". + DrawHorizontalLineCapped(x,y,w,lineChar, lineChar, lineChar). +} + +function DrawHorizontalLineCapped{ + parameter x,y,w,lineChar is "━", capCharLeft is "┣", capCharRight is "┫". + + set i to 0. + local line is "". + until i > w - 1 { + set line to line + lineChar. + set i to i + 1. + } + print line at (x, y). + print capCharLeft at (x, y). + print capCharRight at (x + w -1, y). +} + +function DrawVerticalLineCapped{ + parameter x,y,h,lineChar is "┃", capCharTop is "┳", capCharBottom is "┻". + + if h < 0 or y + h >= terminal:height { + set h to max(1,min(terminal:height - 1 - y,h)). + } + + set i to 1. + until i > h - 2 { + print lineChar at (x, y+i). + set i to i + 1. + } + print capCharTop at (x, y). + print capCharBottom at (x, y + h - 1). +} + +function PrintCentered { + parameter x, y, + w, + text. + set l to text:length. + + print text at (x + (w/2) - (l/2), y). +} + +function PrintRightAligned { + parameter x, y, w, text. + set l to text:length. + + print text at (x + w - l, y). +} + +function ClearArea{ + parameter x, y, w, h, clearChar is " ". + + set j to 0. + local line is "". + until j > w - 1 { + set line to line + clearChar. + set j to j + 1. + } + set i to 0. + until i > h - 1 { + print line at (x,y + i). + set i to i + 1. + } +} \ No newline at end of file diff --git a/library/lib_gui.ksm b/library/lib_gui.ksm new file mode 100644 index 0000000..1dd007c Binary files /dev/null and b/library/lib_gui.ksm differ diff --git a/library/lib_gui_box.ks b/library/lib_gui_box.ks index 75f8fc2..4338963 100644 --- a/library/lib_gui_box.ks +++ b/library/lib_gui_box.ks @@ -5,64 +5,56 @@ function draw_custom_gui_box { parameter - x, y, w, h, - horizontal_char, - vertical_char, - corner_char. - -// Start Input Sanitization + x, y, w, h, + horizontal_char, + vertical_char, + corner_char. if x < 0 or x >= terminal:width { - set x to max(0,min(terminal:width - 1,x)). - HUDTEXT("Error: [draw_custom_gui_box] X value outside terminal.", 10, 2, 30, RED, FALSE). + set x to max(0,min(terminal:width - 1,x)). } if y < 0 or y >= (terminal:height - 1) { - set y to max(0,min(terminal:height - 2,y)). - HUDTEXT("Error: [draw_custom_gui_box] Y value outside terminal", 10, 2, 30, RED, FALSE). + set y to max(0,min(terminal:height - 2,y)). } if w < 1 or x + w > terminal:width { - set w to max(1,min(terminal:width - x,w)). - HUDTEXT("Error: [draw_custom_gui_box] W value outside terminal.", 10, 2, 30, RED, FALSE). + set w to max(1,min(terminal:width - x,w)). } if h < 1 or y + h >= terminal:height { - set h to max(1,min(terminal:height - 1 - y,h)). - HUDTEXT("Error: [draw_custom_gui_box] H value outside terminal.", 10, 2, 30, RED, FALSE). + set h to max(1,min(terminal:height - 1 - y,h)). } - // End Input Sanitization - local horizontal_str is "". local i is 1. until i > w { - if i = 1 or i = w { - set horizontal_str to horizontal_str + corner_char. - } else { - set horizontal_str to horizontal_str + horizontal_char. - } - set i to i + 1. + if i = 1 or i = w { + set horizontal_str to horizontal_str + corner_char. + } else { + set horizontal_str to horizontal_str + horizontal_char. + } + set i to i + 1. } print horizontal_str at(x, y). print horizontal_str at(x, y + h - 1). set i to 1. until i >= h - 1 { - print vertical_char at(x , y + i). - print vertical_char at(x + w - 1, y + i). - set i to i + 1. + print vertical_char at(x , y + i). + print vertical_char at(x + w - 1, y + i). + set i to i + 1. } } function draw_gui_box { parameter - x, y, w, h. + x, y, w, h. draw_custom_gui_box(x, y, w, h, "-", "|", "+"). } function draw_one_char_gui_box { parameter - x, y, w, h, - border_char. + x, y, w, h, + border_char. draw_custom_gui_box(x, y, w, h, border_char, border_char, border_char). -} +} \ No newline at end of file diff --git a/library/lib_gui_box.ksm b/library/lib_gui_box.ksm new file mode 100644 index 0000000..074b394 Binary files /dev/null and b/library/lib_gui_box.ksm differ diff --git a/library/lib_import.ks b/library/lib_import.ks index d8b9aaf..474ec65 100644 --- a/library/lib_import.ks +++ b/library/lib_import.ks @@ -1,6 +1,20 @@ declare function import { - parameter import_path. - copyPath("0:/" + import_path, "1:/" + import_path). - runOncePath(import_path). + parameter p, compileImport is true. + if status = "PRELAUNCH" { + if compileImport { + hudtext("Compiling " + p + " to ksm...", 5, 3, 21, yellow, false). + compile "0:/" + p + ".ks" to "0:/" + p + ".ksm". + SET ks TO archive:OPEN(p + ".ks"). + SET ksm TO archive:OPEN(p + ".ksm"). + if ks:size > ksm:size { + copyPath("0:/" + p + ".ksm", "1:/" + p). + } else{ + copyPath("0:/" + p + ".ks", "1:/" + p). + } + } else{ + copyPath("0:/" + p + ".ks", "1:/" + p). + } + } + runOncePath(p). } \ No newline at end of file diff --git a/library/lib_import.ksm b/library/lib_import.ksm new file mode 100644 index 0000000..4a988bb Binary files /dev/null and b/library/lib_import.ksm differ diff --git a/library/lib_math.ks b/library/lib_math.ks index bcf4b9e..d4ec044 100644 --- a/library/lib_math.ks +++ b/library/lib_math.ks @@ -1,22 +1,15 @@ declare function Lerp{ - parameter a. - parameter b. - parameter t. + parameter a, b, t. return a + (b - a) * t. } declare function Map{ - parameter value. - parameter a1. - parameter a2. - parameter b1. - parameter b2. + parameter value, a1, a2, b1, b2. return b1 + (b2 - b1) * ((value - a1) / (a2 - a1)). } declare function EaseOutExpo { - parameter x. - parameter p is 10. + parameter x, p is 10. if x = 1 { return 1. } else{ @@ -30,7 +23,6 @@ declare function EaseOutCirc{ } declare function EaseOutExp{ - parameter x. - parameter n is 2.0. + parameter x, n is 2.0. return x ^ (2.0 * n). } diff --git a/library/lib_math.ksm b/library/lib_math.ksm new file mode 100644 index 0000000..4f0c9c6 Binary files /dev/null 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 new file mode 100644 index 0000000..ed47600 Binary files /dev/null and b/library/lib_num_to_formatted_str.ksm differ diff --git a/library/lib_orbits.ks b/library/lib_orbits.ks index aeb2cc1..f4d17d5 100644 --- a/library/lib_orbits.ks +++ b/library/lib_orbits.ks @@ -1,6 +1,5 @@ declare function CalculateCircularizationDV{ - parameter ap is 0. - parameter sma is 0. + parameter ap is 0, sma is 0. local mu is body:mu. if ap = 0 { set ap to apoapsis. diff --git a/library/lib_orbits.ksm b/library/lib_orbits.ksm new file mode 100644 index 0000000..221a4db Binary files /dev/null and b/library/lib_orbits.ksm differ diff --git a/library/lib_staging.ks b/library/lib_staging.ks index 924d51b..daafe1e 100644 --- a/library/lib_staging.ks +++ b/library/lib_staging.ks @@ -1,5 +1,3 @@ - - declare function AutoStage{ if not EnginesInStageActive(ship:stagenum) { stage. @@ -7,7 +5,7 @@ declare function AutoStage{ } } -local function EnginesInStageActive{ +function EnginesInStageActive{ parameter targetStage. list engines in allEngines. @@ -21,12 +19,12 @@ local function EnginesInStageActive{ return true. } -local function IsFairingStage{ +function IsFairingStage{ parameter s. } -local function StateHasEngines{ +function StateHasEngines{ parameter s. } \ No newline at end of file diff --git a/library/lib_staging.ksm b/library/lib_staging.ksm new file mode 100644 index 0000000..75f5590 Binary files /dev/null and b/library/lib_staging.ksm differ diff --git a/library/lib_vessel_utils.ks b/library/lib_vessel_utils.ks index f73c490..f306083 100644 --- a/library/lib_vessel_utils.ks +++ b/library/lib_vessel_utils.ks @@ -4,14 +4,13 @@ declare function WaitForEngineStart{ } declare function GetDrag{ - parameter localGravity. - return ship:sensors:acc:mag + localGravity. + parameter lg. + return ship:sensors:acc:mag + lg. } declare function GetDragDir{ - parameter localGravity. - parameter dir. - return vDot(ship:sensors:acc, dir) + localGravity. + parameter lg, dir. + return vDot(ship:sensors:acc, dir) + lg. } declare function AnyEngineActive{ @@ -41,19 +40,18 @@ declare function GetIsp{ } declare function GetIspForStage{ - parameter engineStage. - parameter pressure is 0. + parameter eS, p is 0. LIST ENGINES IN egs. - local totalThrust is GetThrustOfStage(engineStage, pressure). + local totalThrust is GetThrustOfStage(eS, p). if totalThrust = 0{ return 0. } local sum is 0. local weights is 0. for eng in egs{ - if eng:stage = engineStage { - local w is eng:POSSIBLETHRUSTAT(pressure) / totalThrust. - local ispW is eng:ispat(pressure) * w. + if eng:stage = eS { + local w is eng:POSSIBLETHRUSTAT(p) / totalThrust. + local ispW is eng:ispat(p) * w. set sum to sum + ispW. set weights to weights + w. } @@ -73,70 +71,56 @@ declare function GetMaxMassFlow{ } declare function GetMaxMassFlowForStage{ - parameter engineStage. + parameter eS. LIST ENGINES IN egs. local sum is 0. for eng in egs{ - if eng:stage = engineStage { + if eng:stage = eS { set sum to sum + eng:maxmassflow. } } return sum. } - - - -declare function CalculateSuicideBurnDuration -{ +declare function CalculateSuicideBurnDuration{ parameter isp. return CalculateBurnDuration(verticalSpeed, isp, ship:mass, GetMaxMassFlow() * 1000). } -declare function CalculateBurnDuration -{ - parameter dv. - parameter burnIsp. - parameter initialMass. - parameter massFlow. +declare function CalculateBurnDuration{ + parameter dv, burnIsp, iM, mF. if burnIsp = 0 { return 0. } set dv to abs(dv). local exp is -dv / (burnIsp * constant:g0). - local massRatio is constant:e ^ (-exp). - local finalMass is initialMass / massRatio. - local fuelUsed is initialMass - finalMass. + local mR is constant:e ^ (-exp). + local fM is iM / mR. + local f is iM - fM. - if massFlow <= 0{ + if mF <= 0{ return 0. } - return fuelUsed / massFlow. + return f / mF. } - declare function CalculateSuicideBurnAltitude { - parameter vertSpeed. - parameter localGravity. - parameter tgtAltitude is 0.0. - parameter drag is 0.0. + parameter vS, lg, cAlt is 0.0, drag is 0.0. - local vertAcc is CalculateAverageDecceleration(localGravity, drag). - local burnAltitude is ((vertSpeed^2) / (2 * (vertAcc))). - return burnAltitude + tgtAltitude. + local vertAcc is CalculateAverageDecceleration(lg, drag). + local burnAltitude is ((vS^2) / (2 * (vertAcc))). + return burnAltitude + cAlt. } - - declare function CalculateAverageDecceleration{ - parameter localGravity. - parameter drag is 0. - local maxVertAcc is (ship:availablethrust / ship:mass) - localGravity. + parameter lg. + parameter d is 0. + local maxVertAcc is (ship:availablethrust / ship:mass) - lg. - return maxVertAcc + drag. + return maxVertAcc + d. } declare function GetLocalGravity{ @@ -149,20 +133,17 @@ declare function GetLocalGravity{ } declare function CalculateTimeToImpact{ - parameter vertSpeed. - parameter curAltitude. - parameter gravity. - parameter tgtAltitude is 0.0. + parameter vS, cAlt, cG, tAlt is 0.0. - if gravity <= 0 or curAltitude <= 0{ + if cG <= 0 or cAlt <= 0{ return 0.0. } - local vs is abs(vertSpeed). - local g is gravity. - local hRel is curAltitude - tgtAltitude. - local disc is ((vs^2) + (2 * g * hRel)). - return (vs + sqrt(disc)) / g. + set vS to abs(vS). + local g is cG. + local hRel is cAlt - tAlt. + local disc is ((vS^2) + (2 * g * hRel)). + return (vS + sqrt(disc)) / g. } function CalculateMultiStageBurnDuration{ @@ -170,54 +151,51 @@ function CalculateMultiStageBurnDuration{ if ship:STAGEDELTAV(ship:stagenum):current >= dv { return CalculateBurnDuration(dv, GetIsp(), ship:mass, GetMaxMassFlow()). }else{ - local burnTime is 0. + 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 burnTime. + 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. - print cdv. if cdv >= remDv { set sdv to remDv. }else{ set sdv to cdv. } - set burnTime to burnTime + CalculateBurnDuration(sdv, cisp, cmass, cflow). + set bT to bT + CalculateBurnDuration(sdv, cisp, cmass, cflow). set remDv to remDv - cdv. } - return burnTime. + return bT. } } - function GetThrustOfStage { - parameter st. - parameter pressure is 0. + parameter st, p is 0. - local totalThrust is 0. + local tTh is 0. LIST ENGINES IN egs. for eng in egs{ if eng:stage = st { - set totalThrust to totalThrust + eng:POSSIBLETHRUSTAT(pressure). + set tTh to tTh + eng:POSSIBLETHRUSTAT(p). } } - return totalThrust. + return tTh. } function GetMassOfStage { parameter st. - local total is 0. + local sum is 0. LIST PARTS IN allP. for p in allP { if p:stage <= st and p:DECOUPLEDIN < st { - set total to total + p:mass. + set sum to sum + p:mass. } } - return total. + return sum. } \ No newline at end of file diff --git a/library/lib_vessel_utils.ksm b/library/lib_vessel_utils.ksm new file mode 100644 index 0000000..e996b9d Binary files /dev/null and b/library/lib_vessel_utils.ksm differ diff --git a/tests.ks b/tests.ks index a971ce7..237cd33 100644 --- a/tests.ks +++ b/tests.ks @@ -1,26 +1,5 @@ -import("library/lib_vessel_utils"). +import("library/lib_ascent"). CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal"). -print "Waiting for Engine start". -WaitForEngineStart(). - - -function printStatge { - parameter s is ship:stagenum. - local curDv is ship:STAGEDELTAV(s):current. - local isp is GetIspForStage(s). - local smass is GetMassOfStage(s). - local flow is GetMaxMassFlowForStage(s). - local thrust is GetThrustOfStage(s). - - print "------ Stage: " + s + " ------". - print "Thrust: " + thrust + "kN Mass: " + round(smass, 3) + "t". - print "DV: " + round(curDv, 2) + "m/s ISP: " + round(isp, 2) + "s Flow: " + round(flow, 4) + "Mg/s". - print "Burn Duration: " + round(CalculateBurnDuration(curDv, isp, smass, flow), 2). -} - -// printStatge(ship:stagenum). -// printStatge(ship:stagenum - 1). - -print "Total Burn Time: " + CalculateMultiStageBurnDuration(ship:deltav:current). \ No newline at end of file +Ascent(95000, 1000, 0.7, 3). diff --git a/tests.ksm b/tests.ksm new file mode 100644 index 0000000..e81e6db Binary files /dev/null and b/tests.ksm differ