This commit is contained in:
Valentin Verdier 2021-12-29 01:07:57 +01:00
commit 337a85cc77
4 changed files with 152 additions and 0 deletions

22
boot/automate_01.ks Normal file
View File

@ -0,0 +1,22 @@
wait until ship:unpacked.
clearscreen.
print "##### AUTOMATE_01 Bootloader #####".
print "".
copypath("0:/lib.ks", "1:/lib.ks").
run "lib.ks".
include("libmaneuver.ks").
global g_direction is 90.
global g_throttle is 1.
global g_apoapsis is 80000.
global g_gt_angle is 10.
global g_gt_velocity is 60.
man_launch(g_direction, g_throttle).
man_gravity_turn(g_direction, g_gt_angle, g_gt_velocity, g_apoapsis).
release().
man_node_circularize("apo").
man_node_exec().
release().

17
lib.ks Normal file
View File

@ -0,0 +1,17 @@
global function include {
parameter srcpath.
print "Loading " + srcpath + "...".
copypath("0:/" + srcpath, "1:/" + srcpath).
runpath("1:/" + srcpath).
}
global function pause {
parameter msg.
print msg.
wait until terminal:input:getchar() = terminal:input:enter.
}
global function release {
unlock steering.
unlock throttle.
}

104
libmaneuver.ks Normal file
View File

@ -0,0 +1,104 @@
global function man_get_dv {
parameter p_periapsis, p_apoapsis, p_altitude.
local radius is ship:body:radius.
local rs is radius + p_altitude.
local rp is radius + p_periapsis.
local ra is radius + p_apoapsis.
local a is (ra + rp) / 2.
return sqrt(ship:body:mu * (2/rs - 1/a)).
}
global function man_get_dv_hohmann {
parameter p_altitude, p_target.
local vi is man_get_dv(ship:orbit:periapsis, ship:orbit:apoapsis, p_altitude).
local vf is 0.
if p_altitude < p_target {
set vf to man_get_dv(p_altitude, p_target, p_altitude).
} else {
set vf to man_get_dv(p_target, p_altitude, p_altitude).
}
return vf - vi.
}
global function man_node_circularize {
parameter p_pos.
local dv is 0.
local tn is 0.
if p_pos = "apo" {
set dv to man_get_dv_hohmann(ship:orbit:apoapsis, ship:orbit:apoapsis).
set tn to time:seconds + ship:orbit:eta:apoapsis.
} else {
set dv to man_get_dv_hohmann(ship:orbit:periapsis, ship:orbit:periapsis).
set tn to time:seconds + ship:orbit:eta:periapsis.
}
add node(tn, 0, 0, dv).
}
global function man_node_exec {
local nd is nextNode.
lock steering to nd:burnvector.
lock accel to ship:maxthrust / ship:mass.
lock dur to nd:deltav:mag / accel.
wait until nd:eta <= (dur / 2).
lock throttle to 1.
wait until dur < 0.5.
lock steering to ship:facing.
lock throttle to 0.25.
local dv is nd:deltav:mag.
until nd:deltav:mag > dv {
set dv to nd:deltav:mag.
}
lock throttle to 0.
unlock dur.
unlock accel.
remove nd.
}
global function man_launch {
parameter p_direction, p_throttle.
print "=> man_launch".
lock throttle to p_throttle.
lock steering to ship:facing.
stage.
wait 2.
stage.
wait until ship:altitude >= 150.
print " - Alignment...".
lock steering to heading(p_direction, 90).
}
global function man_gravity_turn {
parameter p_direction, p_angle, p_velocity, p_apoapsis.
print "=> man_gravity_turn".
wait until ship:velocity:surface:mag >= p_velocity.
print " - Rotation...".
local gt_start is heading(p_direction, 90 - p_angle).
lock steering to gt_start.
wait until vang(ship:facing:vector, gt_start:vector) < 1.
wait until vang(ship:srfprograde:vector, ship:facing:vector) < 1.
print " - Follow prograde...".
lock steering to heading(p_direction, 90 - vang(ship:up:vector, ship:srfprograde:vector)).
wait until ship:orbit:apoapsis >= 0.95 * p_apoapsis.
lock throttle to 0.3.
wait until ship:orbit:apoapsis >= p_apoapsis.
print " - Apoapsis OK".
lock throttle to 0.
wait 1.
stage.
wait 1.
stage.
}

9
libutils.ks Normal file
View File

@ -0,0 +1,9 @@
global function util_drop_solid_boosters {
parameter p_throttle.
when stage:resourcesLex["SolidFuel"]:amount = 0 then {
wait 0.5.
stage.
wait 0.5.
lock throttle to p_throttle.
}
}