Improve readability.
This commit is contained in:
parent
23df3b4236
commit
4bcc2ccd3a
|
@ -22,29 +22,34 @@ print "============= BOOT SEQUENCE COMPLETE =============".
|
||||||
|
|
||||||
|
|
||||||
function update_scripts {
|
function update_scripts {
|
||||||
|
//
|
||||||
// Copy all .ks-files from the archive to the CPU's internal storage.
|
// Copy all .ks-files from the archive to the CPU's internal storage.
|
||||||
|
//
|
||||||
|
|
||||||
// Get lexicon of existing items (files/directories) and sizes on the internal storage
|
// Get lexicon of existing items (files/directories) and sizes on the internal storage
|
||||||
local existing is LEXICON().
|
local existing is LEXICON().
|
||||||
for item in CORE:volume:files:values {
|
for item in CORE:volume:files:values {
|
||||||
set existing[item:name] to item:size.
|
set existing[item:name] to item:size.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if items from the archive match those in the internal storage
|
|
||||||
for item in volume("ARCHIVE"):files:values {
|
for item in volume("ARCHIVE"):files:values {
|
||||||
local skip is false. // kOS doesn't support the 'continue' keyword...
|
copy_file_if_necessary(item).
|
||||||
|
|
||||||
if not skip and item:name[0] = "." set skip to true. // skip linux hidden dirs (e.g. .git)
|
|
||||||
if not skip and item:isfile
|
|
||||||
and item:extension <> "ks" set skip to true. // skip non-script items (e.g. README.md)
|
|
||||||
if not skip and existing:haskey(item:name)
|
|
||||||
and item:size = existing[item:name] set skip to true. // skip if local item is same size
|
|
||||||
|
|
||||||
if not skip {
|
|
||||||
print "Copying " + item:name + "..".
|
|
||||||
copypath(path(volume("ARCHIVE")):combine(item:name), CORE:volume).
|
|
||||||
|
|
||||||
if item:name = "boot" reboot. // reboot CPU if boot/ directory was updated
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function copy_file_if_necessary {
|
||||||
|
parameter file.
|
||||||
|
|
||||||
|
if item:name[0] = "." // skip linux hidden dirs (e.g. .git)
|
||||||
|
return.
|
||||||
|
if item:isfile and item:extension <> "ks" // skip non-script items (e.g. README.md)
|
||||||
|
return.
|
||||||
|
if existing:haskey(item:name) and item:size = existing[item:name] // skip if local item is same size
|
||||||
|
return.
|
||||||
|
|
||||||
|
print "Copying " + item:name.
|
||||||
|
copypath(path(volume("ARCHIVE")):combine(item:name), CORE:volume).
|
||||||
|
|
||||||
|
if item:name = "boot"
|
||||||
|
reboot. // reboot CPU if boot/ directory was updated
|
||||||
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ function launch {
|
||||||
// LAUNCH AZIMUTH
|
// LAUNCH AZIMUTH
|
||||||
|
|
||||||
// Since the "center" of an orbit must be at the center of gravity of the body, the latitude of the launch site establishes the minimum absolute orbital inclination.
|
// Since the "center" of an orbit must be at the center of gravity of the body, the latitude of the launch site establishes the minimum absolute orbital inclination.
|
||||||
// KSC is almost on the equator, so we're going to always round the latitude towards zero, and accept the inaccuracies it may introduce.
|
// KSC is almost on the equator, so we're going to always round the latitude towards zero to allow any inclination from KSC and accept the inaccuracies it may introduce.
|
||||||
local launch_site_latitude is round_towards_zero(LATITUDE).
|
local launch_site_latitude is round_towards_zero(LATITUDE).
|
||||||
local target_orbit_inclination is max(target_orbit_inclination, launch_site_latitude).
|
local target_orbit_inclination is max(target_orbit_inclination, launch_site_latitude).
|
||||||
|
|
||||||
|
|
10
lib/node.ks
10
lib/node.ks
|
@ -35,23 +35,23 @@ function execute_node {
|
||||||
wait until vang(SHIP:facing:vector, node:deltav) < 0.5.
|
wait until vang(SHIP:facing:vector, node:deltav) < 0.5.
|
||||||
|
|
||||||
print "Initializing warp".
|
print "Initializing warp".
|
||||||
warp_for(max(0, node:eta - (burn_duration/2) - 5)). // warp until 5s before node
|
warp_for(max(0, node:eta - (burn_duration/2) - 5)). // 5s before we need to start burn
|
||||||
|
|
||||||
print "Approaching".
|
print "Approaching".
|
||||||
wait until node:eta <= ceiling(burn_duration/2). // CEILING instead of ROUND, since we'd rather start the burn too soon to have time for perfecting the burn
|
wait until node:eta <= ceiling(burn_duration/2). // ceiling since we'd rather start the burn too soon to have time for perfecting it
|
||||||
|
|
||||||
print "Burn!".
|
print "Burn!".
|
||||||
lock THROTTLE to 1.0.
|
lock THROTTLE to 1.0.
|
||||||
|
|
||||||
// Decrease throttle linearly when the burn duration is less than 1 second
|
// Decrease throttle linearly when the burn duration is less than 1 second
|
||||||
wait until estimated_burn_duration(node) <= 1.
|
wait until estimated_burn_duration(node) <= 1.
|
||||||
lock THROTTLE to max(0.01, estimated_burn_duration(node)). // ensure we always finish by burning with at least 1% power
|
lock THROTTLE to max(0.01, estimated_burn_duration(node)). // ensure we always finish the burn by burning with at least 1% power at all times
|
||||||
|
|
||||||
// The burn vector will start to drift once we have very little left to burn. Therefore, take a "snapshot" of the burn vector as it is right now, and lock steering to it, instead of the dynamic vector
|
// The burn vector will start to drift once we have very little left to burn. Therefore, save the burn vector as it is right now, and lock steering to it, instead of the dynamic vector
|
||||||
local dv0 is node:deltav.
|
local dv0 is node:deltav.
|
||||||
lock STEERING to dv0.
|
lock STEERING to dv0.
|
||||||
|
|
||||||
// Stop the burn once the "snapshot" vector dv0 and current burn vector start facing opposite directions
|
// Stop the burn once the saved vector, dv0, and current burn vector start facing opposite directions
|
||||||
wait until vdot(dv0, node:deltav) < 0.
|
wait until vdot(dv0, node:deltav) < 0.
|
||||||
set THROTTLE to 0.0.
|
set THROTTLE to 0.0.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue