HUD overhaul.
This commit is contained in:
@@ -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) ).
|
||||
|
||||
|
||||
+6
-3
@@ -1,4 +1,7 @@
|
||||
set terminal:charheight to 20.
|
||||
|
||||
copyPath("0:/library/lib_import", "1:/library/lib_import").
|
||||
run "library/lib_import".
|
||||
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").
|
||||
+2
-3
@@ -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.
|
||||
|
||||
Binary file not shown.
@@ -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.
|
||||
|
||||
BIN
Binary file not shown.
@@ -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
@@ -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.
|
||||
@@ -134,3 +161,144 @@ local function CreateCircularizationNode{
|
||||
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).
|
||||
}
|
||||
Binary file not shown.
@@ -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.
@@ -10,30 +10,22 @@ function draw_custom_gui_box {
|
||||
vertical_char,
|
||||
corner_char.
|
||||
|
||||
// Start Input Sanitization
|
||||
|
||||
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).
|
||||
}
|
||||
|
||||
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).
|
||||
}
|
||||
|
||||
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).
|
||||
}
|
||||
|
||||
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).
|
||||
}
|
||||
|
||||
// End Input Sanitization
|
||||
|
||||
local horizontal_str is "".
|
||||
local i is 1.
|
||||
until i > w {
|
||||
|
||||
Binary file not shown.
+17
-3
@@ -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).
|
||||
}
|
||||
Binary file not shown.
+4
-12
@@ -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).
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -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.
|
||||
|
||||
Binary file not shown.
@@ -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.
|
||||
|
||||
}
|
||||
Binary file not shown.
+45
-67
@@ -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.
|
||||
}
|
||||
Binary file not shown.
@@ -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).
|
||||
Ascent(95000, 1000, 0.7, 3).
|
||||
|
||||
Reference in New Issue
Block a user