commit c3ab101f8b2710b068127d5592c3e452cd269a8a Author: annabunches Date: Sun Jul 18 04:07:00 2021 -0400 Initial commit. diff --git a/boot/rocket.ks b/boot/rocket.ks new file mode 100644 index 0000000..c38faa2 --- /dev/null +++ b/boot/rocket.ks @@ -0,0 +1,4 @@ +COPYPATH("0:/noop", ""). +COMPILE "0:/launch" to "1:/launch". + +SET core:bootfilename to "noop". diff --git a/dbgparts.ks b/dbgparts.ks new file mode 100644 index 0000000..1a61ccd --- /dev/null +++ b/dbgparts.ks @@ -0,0 +1,6 @@ +set outfile to "0:/parts.txt". +log "======== New run ========" to outfile. +for i in range(0,ship:parts:length) { + log "___Modules for ship:parts[" + i + "]____" to outfile. + log ship:parts[i]:allmodules to outfile. +} diff --git a/launch.ks b/launch.ks new file mode 100644 index 0000000..44f422a --- /dev/null +++ b/launch.ks @@ -0,0 +1,93 @@ +DECLARE FUNCTION throttle_to_twr { + declare parameter x is 1.5. + + local m is ship:mass. + local g is 9.81. + if has_grav_sensor = true { + set g to ship:sensors:grav:mag. + } + print "Locking throttle to: " + min((x*m*g)/ship:availablethrust, 1.0). + lock throttle to min((x*m*g)/ship:availablethrust, 1.0). +} + +DECLARE FUNCTION twr { + local m is ship:mass. + local g is 9.81. // fallback to this approximation that doesn't deal with + // altitude change. + if has_grav_sensor = true { + set g to ship:sensors:grav:mag. + } + local t is throttle * ship:availablethrust. + print "Mass: " + ship:mass. + print "Throttle: " + throttle. + print "Thrust (max): " + ship:availablethrust. + print "TWR = " + t/(m*g). + return t/(m*g). +} + +LOCAL has_grav_sensor is false. +DECLARE FUNCTION sensor_check { + list sensors in senselist. + for s in senselist { + if s:type = "grav" { + print "Gravometric sensor detected". + set has_grav_sensor to true. + return. + } + } + set has_grav_sensor to false. +} + +// countdown +sensor_check(). +LOCAL done is false. +PRINT "Initiating automated launch sequence". +FROM { local x is 5. } UNTIL x = 0 STEP { set x to x - 1. } DO { + PRINT "..." + x. + WAIT 1. +} + +// Logic for initial ascent. +SAS OFF. +LOCK throttle to 1.0. +LOCK steering to up. +STAGE. + +WHEN ship:altitude > 1000 THEN { + PRINT "Vectoring away from launchpad". + LOCK steering to HEADING(90, 88). + WHEN ship:altitude > 8000 THEN { + // begin "gravity" curve + PRINT "Beginning orbital insertion turn". + LOCK steering to HEADING(90,80). + WAIT 1. + LOCK steering to HEADING(90,70). + WAIT 1. + LOCK steering to HEADING(90,60). + WAIT 3. + LOCK steering to ship:prograde. + + WHEN ship:apoapsis > 70000 THEN { + LOCK throttle to 0.0. + // todo: automate orbital insertion. + PRINT "Initial ascent complete. Manually perform orbital insertion. Good luck, Kerman!". + SET done to true. + } + } +} + +// Control rate of ascent to reduce drag. +UNTIL ship:altitude > 32000 { + if twr() > 1.5 { + throttle_to_twr(1.5). + } + wait 0.001. +} +lock throttle to 1.0. + +// throttle_to_twr(1.5). +// WHEN ship:altitude > 32000 THEN { +// lock throttle to 1.0. +// } + +WAIT UNTIL done. diff --git a/noop.ks b/noop.ks new file mode 100644 index 0000000..e69de29