diff --git a/boot/default.ks b/boot/default.ks index 9dce4f0..359141a 100755 --- a/boot/default.ks +++ b/boot/default.ks @@ -22,29 +22,34 @@ print "============= BOOT SEQUENCE COMPLETE =============". function update_scripts { + // // 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 local existing is LEXICON(). for item in CORE:volume:files:values { 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 { - local skip is false. // kOS doesn't support the 'continue' keyword... - - 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 - } + copy_file_if_necessary(item). } } + +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 +} diff --git a/launch.ks b/launch.ks index 7cba548..f1e3c16 100755 --- a/launch.ks +++ b/launch.ks @@ -28,7 +28,7 @@ function launch { // 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. - // 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 target_orbit_inclination is max(target_orbit_inclination, launch_site_latitude). diff --git a/lib/node.ks b/lib/node.ks index 1319028..7b6261d 100755 --- a/lib/node.ks +++ b/lib/node.ks @@ -35,23 +35,23 @@ function execute_node { wait until vang(SHIP:facing:vector, node:deltav) < 0.5. 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". - 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!". lock THROTTLE to 1.0. // Decrease throttle linearly when the burn duration is less than 1 second 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. 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. set THROTTLE to 0.0.