HUD overhaul.

This commit is contained in:
2026-05-03 04:14:03 -04:00
parent 1895386fdf
commit 73868e47db
27 changed files with 397 additions and 178 deletions
+3 -1
View File
@@ -8,7 +8,7 @@ if status = "PRELAUNCH" {
set profile to 0.7. set profile to 0.7.
set turn_start to 1000. set turn_start to 1000.
set target_orbit to 120000. set target_orbit to 100000.
when altitude > 80000 then { when altitude > 80000 then {
ag1 on. ag1 on.
@@ -16,6 +16,8 @@ if status = "PRELAUNCH" {
Ascent(target_orbit, turn_start, profile, 3). Ascent(target_orbit, turn_start, profile, 3).
wait 30.
SET V0 TO GETVOICE(0). SET V0 TO GETVOICE(0).
V0:PLAY( NOTE(400, 2.5) ). V0:PLAY( NOTE(400, 2.5) ).
BIN
View File
Binary file not shown.
+6 -3
View File
@@ -1,4 +1,7 @@
set terminal:charheight to 20. set terminal:charheight to 20.
if status = "PRELAUNCH"
copyPath("0:/library/lib_import", "1:/library/lib_import"). {
run "library/lib_import". 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").
+2 -3
View File
@@ -10,20 +10,19 @@ if status = "PRELAUNCH" {
print "Verical Ascent: ". print "Verical Ascent: ".
set turn_start to terminal_input_number(16, 1, 6, 1000). set turn_start to terminal_input_number(16, 1, 6, 1000).
print "Target Orbit: ". 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: ". print "Inclination: ".
set inclination to terminal_input_number(13, 3, 8, 0). set inclination to terminal_input_number(13, 3, 8, 0).
print "Circularization: ". print "Circularization: ".
set circ to terminal_input_number(17, 4, 8, 3). set circ to terminal_input_number(17, 4, 8, 3).
print "Waiting for Engine Start...".
WaitForEngineStart().
clearScreen. clearScreen.
sas off. sas off.
Ascent(target_orbit:toscalar(0), turn_start:toscalar(0), profile:toscalar(0), circ:toscalar(0), inclination:toscalar(0)). 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"). CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").
sas on. sas on.
SHUTDOWN. SHUTDOWN.
BIN
View File
Binary file not shown.
+3 -1
View File
@@ -7,7 +7,7 @@ if status = "PRELAUNCH" {
set profile to 0.7. set profile to 0.7.
set turn_start to 1000. set turn_start to 1000.
set target_orbit to 100000. set target_orbit to 960000.
when altitude > 80000 then { when altitude > 80000 then {
ag1 on. ag1 on.
@@ -15,6 +15,8 @@ if status = "PRELAUNCH" {
Ascent(target_orbit, turn_start, profile, 3). Ascent(target_orbit, turn_start, profile, 3).
wait 30.
print "Orbit Achieved, Releasing Controls". print "Orbit Achieved, Releasing Controls".
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal"). CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").
SHUTDOWN. SHUTDOWN.
BIN
View File
Binary file not shown.
+4
View File
@@ -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".
+197 -29
View File
@@ -2,57 +2,69 @@ import("library/lib_staging").
import("library/lib_math"). import("library/lib_math").
import("library/lib_vessel_utils"). import("library/lib_vessel_utils").
import("library/lib_orbits"). import("library/lib_orbits").
import("library/lib_num_to_formatted_str").
import("library/lib_gui").
declare ASCENT_STATE is "Pre-Launch".
declare function Ascent{ declare function Ascent{
parameter targetOrbit is 100000. parameter targetOrbit is 100000,
parameter vericalAscent is 1000. vericalAscent is 1000,
parameter ascentProfile is 1.2. ascentProfile is 1.2,
parameter circ is 1. circ is 1,
parameter inc is 0. inc is 0.
print "Params (" + targetOrbit + ", " + vericalAscent + ", " + ascentProfile + ", " + circ + ", " + inc + ")". // local tgtOrbitSI is si_formatting(targetOrbit, "m").
print "Vertical Climb to " + vericalAscent. local vericalAscentSI is si_formatting(vericalAscent, "m").
set tgtPitch to 90. set tgtPitch to 90.
set isDone to false. local head to 90 + inc.
lock throttle to 1. 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). 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, 0, targetOrbit, 0.0, 1.0).
SetState("Vertical Ascent").
wait until altitude > vericalAscent and asccent_prog > 0. 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 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 //Auto Staging
when periapsis < targetOrbit then{ when periapsis < targetOrbit then{
AutoStage(). AutoStage().
wait 0.01. wait 0.01.
if not isDone{ if ASCENT_STATE <> "DONE" {
preserve. preserve.
} }
} }
wait until apoapsis >= targetOrbit. wait until apoapsis >= targetOrbit.
lock throttle to 0.
unlock tgt_pitch. unlock tgt_pitch.
lock tgtPitch to 0. lock tgtPitch to 0.
unlock steering. unlock steering.
SetState("Circularization").
if circ = 1 { if circ = 1 {
CircularizeBrute(targetOrbit, head). CircularizeBrute(targetOrbit, head).
}else if circ = 2{ }else if circ = 2{
@@ -60,12 +72,9 @@ declare function Ascent{
}else if circ = 3 { }else if circ = 3 {
lock steering to heading(head, 0, 270). lock steering to heading(head, 0, 270).
CreateCircularizationNode(apoapsis). CreateCircularizationNode(apoapsis).
// if periapsis < targetOrbit and eta:apoapsis < orbit:period / 2{
// CreateCircularizationNode(apoapsis).
// }
} }
set isDone to true. SetState("Done").
unlock steering. unlock steering.
unlock throttle. unlock throttle.
@@ -73,8 +82,7 @@ declare function Ascent{
} }
local function Circularize{ local function Circularize{
parameter tgt. parameter tgt, head.
parameter head.
lock throttle to 0. lock throttle to 0.
lock steering to heading(head, 0, 270). lock steering to heading(head, 0, 270).
@@ -104,8 +112,7 @@ local function Circularize{
} }
local function CircularizeBrute{ local function CircularizeBrute{
parameter tgt. parameter tgt, head.
parameter head.
lock throttle to 1. lock throttle to 1.
lock steering to heading(head, 0, 270). lock steering to heading(head, 0, 270).
wait until periapsis >= tgt. wait until periapsis >= tgt.
@@ -116,13 +123,33 @@ local function CreateCircularizationNode{
parameter tgt. parameter tgt.
lock throttle to 0. 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. wait until altitude > 80000.
local burnDv is CalculateCircularizationDV(tgt, orbit:semimajoraxis). 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). local circNode is Node(time:seconds + eta:apoapsis, 0, 0, burnDv).
add circNode. add circNode.
wait 0.01. wait 0.01.
lock steering to circNode:burnvector. 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. wait until circNode:eta <= burnDuration /2.
lock throttle to 1. lock throttle to 1.
wait until nextNode:deltav:mag <= 10. wait until nextNode:deltav:mag <= 10.
@@ -133,4 +160,145 @@ local function CreateCircularizationNode{
remove nextNode. remove nextNode.
wait 0.01. wait 0.01.
wait until throttle = 0. 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).
} }
Binary file not shown.
+89
View File
@@ -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.
}
}
Binary file not shown.
+21 -29
View File
@@ -5,64 +5,56 @@
function draw_custom_gui_box { function draw_custom_gui_box {
parameter parameter
x, y, w, h, x, y, w, h,
horizontal_char, horizontal_char,
vertical_char, vertical_char,
corner_char. corner_char.
// Start Input Sanitization
if x < 0 or x >= terminal:width { if x < 0 or x >= terminal:width {
set x to max(0,min(terminal:width - 1,x)). 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).
} }
if y < 0 or y >= (terminal:height - 1) { if y < 0 or y >= (terminal:height - 1) {
set y to max(0,min(terminal:height - 2,y)). 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).
} }
if w < 1 or x + w > terminal:width { if w < 1 or x + w > terminal:width {
set w to max(1,min(terminal:width - x,w)). 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).
} }
if h < 1 or y + h >= terminal:height { if h < 1 or y + h >= terminal:height {
set h to max(1,min(terminal:height - 1 - y,h)). 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).
} }
// End Input Sanitization
local horizontal_str is "". local horizontal_str is "".
local i is 1. local i is 1.
until i > w { until i > w {
if i = 1 or i = w { if i = 1 or i = w {
set horizontal_str to horizontal_str + corner_char. set horizontal_str to horizontal_str + corner_char.
} else { } else {
set horizontal_str to horizontal_str + horizontal_char. set horizontal_str to horizontal_str + horizontal_char.
} }
set i to i + 1. set i to i + 1.
} }
print horizontal_str at(x, y). print horizontal_str at(x, y).
print horizontal_str at(x, y + h - 1). print horizontal_str at(x, y + h - 1).
set i to 1. set i to 1.
until i >= h - 1 { until i >= h - 1 {
print vertical_char at(x , y + i). print vertical_char at(x , y + i).
print vertical_char at(x + w - 1, y + i). print vertical_char at(x + w - 1, y + i).
set i to i + 1. set i to i + 1.
} }
} }
function draw_gui_box { function draw_gui_box {
parameter parameter
x, y, w, h. x, y, w, h.
draw_custom_gui_box(x, y, w, h, "-", "|", "+"). draw_custom_gui_box(x, y, w, h, "-", "|", "+").
} }
function draw_one_char_gui_box { function draw_one_char_gui_box {
parameter parameter
x, y, w, h, x, y, w, h,
border_char. border_char.
draw_custom_gui_box(x, y, w, h, border_char, border_char, border_char). draw_custom_gui_box(x, y, w, h, border_char, border_char, border_char).
} }
Binary file not shown.
+17 -3
View File
@@ -1,6 +1,20 @@
declare function import { declare function import {
parameter import_path. parameter p, compileImport is true.
copyPath("0:/" + import_path, "1:/" + import_path).
runOncePath(import_path).
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).
} }
Binary file not shown.
+4 -12
View File
@@ -1,22 +1,15 @@
declare function Lerp{ declare function Lerp{
parameter a. parameter a, b, t.
parameter b.
parameter t.
return a + (b - a) * t. return a + (b - a) * t.
} }
declare function Map{ declare function Map{
parameter value. parameter value, a1, a2, b1, b2.
parameter a1.
parameter a2.
parameter b1.
parameter b2.
return b1 + (b2 - b1) * ((value - a1) / (a2 - a1)). return b1 + (b2 - b1) * ((value - a1) / (a2 - a1)).
} }
declare function EaseOutExpo { declare function EaseOutExpo {
parameter x. parameter x, p is 10.
parameter p is 10.
if x = 1 { if x = 1 {
return 1. return 1.
} else{ } else{
@@ -30,7 +23,6 @@ declare function EaseOutCirc{
} }
declare function EaseOutExp{ declare function EaseOutExp{
parameter x. parameter x, n is 2.0.
parameter n is 2.0.
return x ^ (2.0 * n). return x ^ (2.0 * n).
} }
Binary file not shown.
Binary file not shown.
+1 -2
View File
@@ -1,6 +1,5 @@
declare function CalculateCircularizationDV{ declare function CalculateCircularizationDV{
parameter ap is 0. parameter ap is 0, sma is 0.
parameter sma is 0.
local mu is body:mu. local mu is body:mu.
if ap = 0 { if ap = 0 {
set ap to apoapsis. set ap to apoapsis.
Binary file not shown.
+3 -5
View File
@@ -1,5 +1,3 @@
declare function AutoStage{ declare function AutoStage{
if not EnginesInStageActive(ship:stagenum) { if not EnginesInStageActive(ship:stagenum) {
stage. stage.
@@ -7,7 +5,7 @@ declare function AutoStage{
} }
} }
local function EnginesInStageActive{ function EnginesInStageActive{
parameter targetStage. parameter targetStage.
list engines in allEngines. list engines in allEngines.
@@ -21,12 +19,12 @@ local function EnginesInStageActive{
return true. return true.
} }
local function IsFairingStage{ function IsFairingStage{
parameter s. parameter s.
} }
local function StateHasEngines{ function StateHasEngines{
parameter s. parameter s.
} }
Binary file not shown.
+45 -67
View File
@@ -4,14 +4,13 @@ declare function WaitForEngineStart{
} }
declare function GetDrag{ declare function GetDrag{
parameter localGravity. parameter lg.
return ship:sensors:acc:mag + localGravity. return ship:sensors:acc:mag + lg.
} }
declare function GetDragDir{ declare function GetDragDir{
parameter localGravity. parameter lg, dir.
parameter dir. return vDot(ship:sensors:acc, dir) + lg.
return vDot(ship:sensors:acc, dir) + localGravity.
} }
declare function AnyEngineActive{ declare function AnyEngineActive{
@@ -41,19 +40,18 @@ declare function GetIsp{
} }
declare function GetIspForStage{ declare function GetIspForStage{
parameter engineStage. parameter eS, p is 0.
parameter pressure is 0.
LIST ENGINES IN egs. LIST ENGINES IN egs.
local totalThrust is GetThrustOfStage(engineStage, pressure). local totalThrust is GetThrustOfStage(eS, p).
if totalThrust = 0{ if totalThrust = 0{
return 0. return 0.
} }
local sum is 0. local sum is 0.
local weights is 0. local weights is 0.
for eng in egs{ for eng in egs{
if eng:stage = engineStage { if eng:stage = eS {
local w is eng:POSSIBLETHRUSTAT(pressure) / totalThrust. local w is eng:POSSIBLETHRUSTAT(p) / totalThrust.
local ispW is eng:ispat(pressure) * w. local ispW is eng:ispat(p) * w.
set sum to sum + ispW. set sum to sum + ispW.
set weights to weights + w. set weights to weights + w.
} }
@@ -73,70 +71,56 @@ declare function GetMaxMassFlow{
} }
declare function GetMaxMassFlowForStage{ declare function GetMaxMassFlowForStage{
parameter engineStage. parameter eS.
LIST ENGINES IN egs. LIST ENGINES IN egs.
local sum is 0. local sum is 0.
for eng in egs{ for eng in egs{
if eng:stage = engineStage { if eng:stage = eS {
set sum to sum + eng:maxmassflow. set sum to sum + eng:maxmassflow.
} }
} }
return sum. return sum.
} }
declare function CalculateSuicideBurnDuration{
declare function CalculateSuicideBurnDuration
{
parameter isp. parameter isp.
return CalculateBurnDuration(verticalSpeed, isp, ship:mass, GetMaxMassFlow() * 1000). return CalculateBurnDuration(verticalSpeed, isp, ship:mass, GetMaxMassFlow() * 1000).
} }
declare function CalculateBurnDuration declare function CalculateBurnDuration{
{ parameter dv, burnIsp, iM, mF.
parameter dv.
parameter burnIsp.
parameter initialMass.
parameter massFlow.
if burnIsp = 0 { if burnIsp = 0 {
return 0. return 0.
} }
set dv to abs(dv). set dv to abs(dv).
local exp is -dv / (burnIsp * constant:g0). local exp is -dv / (burnIsp * constant:g0).
local massRatio is constant:e ^ (-exp). local mR is constant:e ^ (-exp).
local finalMass is initialMass / massRatio. local fM is iM / mR.
local fuelUsed is initialMass - finalMass. local f is iM - fM.
if massFlow <= 0{ if mF <= 0{
return 0. return 0.
} }
return fuelUsed / massFlow. return f / mF.
} }
declare function CalculateSuicideBurnAltitude declare function CalculateSuicideBurnAltitude
{ {
parameter vertSpeed. parameter vS, lg, cAlt is 0.0, drag is 0.0.
parameter localGravity.
parameter tgtAltitude is 0.0.
parameter drag is 0.0.
local vertAcc is CalculateAverageDecceleration(localGravity, drag). local vertAcc is CalculateAverageDecceleration(lg, drag).
local burnAltitude is ((vertSpeed^2) / (2 * (vertAcc))). local burnAltitude is ((vS^2) / (2 * (vertAcc))).
return burnAltitude + tgtAltitude. return burnAltitude + cAlt.
} }
declare function CalculateAverageDecceleration{ declare function CalculateAverageDecceleration{
parameter localGravity. parameter lg.
parameter drag is 0. parameter d is 0.
local maxVertAcc is (ship:availablethrust / ship:mass) - localGravity. local maxVertAcc is (ship:availablethrust / ship:mass) - lg.
return maxVertAcc + drag. return maxVertAcc + d.
} }
declare function GetLocalGravity{ declare function GetLocalGravity{
@@ -149,20 +133,17 @@ declare function GetLocalGravity{
} }
declare function CalculateTimeToImpact{ declare function CalculateTimeToImpact{
parameter vertSpeed. parameter vS, cAlt, cG, tAlt is 0.0.
parameter curAltitude.
parameter gravity.
parameter tgtAltitude is 0.0.
if gravity <= 0 or curAltitude <= 0{ if cG <= 0 or cAlt <= 0{
return 0.0. return 0.0.
} }
local vs is abs(vertSpeed). set vS to abs(vS).
local g is gravity. local g is cG.
local hRel is curAltitude - tgtAltitude. local hRel is cAlt - tAlt.
local disc is ((vs^2) + (2 * g * hRel)). local disc is ((vS^2) + (2 * g * hRel)).
return (vs + sqrt(disc)) / g. return (vS + sqrt(disc)) / g.
} }
function CalculateMultiStageBurnDuration{ function CalculateMultiStageBurnDuration{
@@ -170,54 +151,51 @@ function CalculateMultiStageBurnDuration{
if ship:STAGEDELTAV(ship:stagenum):current >= dv { if ship:STAGEDELTAV(ship:stagenum):current >= dv {
return CalculateBurnDuration(dv, GetIsp(), ship:mass, GetMaxMassFlow()). return CalculateBurnDuration(dv, GetIsp(), ship:mass, GetMaxMassFlow()).
}else{ }else{
local burnTime is 0. local bT is 0.
local remDv is dv. local remDv is dv.
from {local s is ship:stagenum. } until s = -1 step { set s to s-1.} do { from {local s is ship:stagenum. } until s = -1 step { set s to s-1.} do {
if remDv <= 0 { if remDv <= 0 {
return burnTime. return bT.
} }
local cdv is ship:stagedeltav(s):current. local cdv is ship:stagedeltav(s):current.
local cmass is GetMassOfStage(s). local cmass is GetMassOfStage(s).
local cflow is GetMaxMassFlowForStage(s). local cflow is GetMaxMassFlowForStage(s).
local cisp is GetIspForStage(s). local cisp is GetIspForStage(s).
local sdv is 0. local sdv is 0.
print cdv.
if cdv >= remDv { if cdv >= remDv {
set sdv to remDv. set sdv to remDv.
}else{ }else{
set sdv to cdv. 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. set remDv to remDv - cdv.
} }
return burnTime. return bT.
} }
} }
function GetThrustOfStage { function GetThrustOfStage {
parameter st. parameter st, p is 0.
parameter pressure is 0.
local totalThrust is 0. local tTh is 0.
LIST ENGINES IN egs. LIST ENGINES IN egs.
for eng in egs{ for eng in egs{
if eng:stage = st { if eng:stage = st {
set totalThrust to totalThrust + eng:POSSIBLETHRUSTAT(pressure). set tTh to tTh + eng:POSSIBLETHRUSTAT(p).
} }
} }
return totalThrust. return tTh.
} }
function GetMassOfStage { function GetMassOfStage {
parameter st. parameter st.
local total is 0. local sum is 0.
LIST PARTS IN allP. LIST PARTS IN allP.
for p in allP { for p in allP {
if p:stage <= st and p:DECOUPLEDIN < st { if p:stage <= st and p:DECOUPLEDIN < st {
set total to total + p:mass. set sum to sum + p:mass.
} }
} }
return total. return sum.
} }
Binary file not shown.
+2 -23
View File
@@ -1,26 +1,5 @@
import("library/lib_vessel_utils"). import("library/lib_ascent").
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal"). CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
print "Waiting for Engine start". Ascent(95000, 1000, 0.7, 3).
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).
BIN
View File
Binary file not shown.