Improve ascend guidance.

This commit is contained in:
Casper V. Kristensen 2019-02-08 22:17:19 +01:00
parent 2e65161467
commit 396678e313
Signed by: caspervk
GPG key ID: 289CA03790535054
2 changed files with 65 additions and 32 deletions

View file

@ -15,21 +15,23 @@ function launch {
parameter pitchover_tilt is 20. // how many degrees to tilt at pitchover maneuver
parameter pitchover_altitude is 1000. // perform pitchover at this altitude
parameter pitchover_velocity is 100. // or this velocity
parameter auto_stage is true.
parameter auto_deploy_solar_panels is true.
parameter auto_deploy_fairings is true.
parameter auto_extend_antennas is true.
print "========= LAUNCHING =========".
print "================ ASCEND GUIDANCE =================".
print "Target orbital altitude: " + target_orbit_altitude + "m".
print "Target orbital inclination: " + target_orbit_inclination + "°".
print "Pitchover tilt: " + pitchover_tilt + "°".
print "Pitchover at: " + pitchover_altitude + "m or " + pitchover_velocity + " m/s".
print " ".
// 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 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 int(LATITUDE).
local target_orbit_inclination is max(target_orbit_inclination, launch_site_latitude).
// Calculate the launch azimuth; the compass heading we head for when launching to achieve orbit of desired inclination
@ -45,52 +47,71 @@ function launch {
print "Available orbital inclination: " + target_orbit_inclination + "°".
print "Launch azimuth: " + round(launch_azimuth, 3) + "°".
print "Launch southwards: " + southwards.
print "--- VERTICAL CLIMB ---".
print " ".
print "Auto-staging: " + auto_stage.
print "Auto-deploy solar panels: " + auto_deploy_solar_panels.
print "Auto-deploy fairings: " + auto_deploy_fairings.
print "Auto-extend antennas: " + auto_extend_antennas.
print " ".
// LAUNCH
SAS off.
RCS on.
set NAVMODE to "SURFACE".
lock STEERING to heading(launch_azimuth, 90). // roll to launch azimuth
lock THROTTLE to 1.0.
// LAUNCH
// Enable auto-staging
when should_stage() then {
when auto_stage and should_stage() then {
stage_when_ready().
wait 0.5.
return true. // preserve trigger
}
// Once a certain altitude (or velocity) is reached, a slight turn is made, called the pitchover maneuver
print "----------------- VERTICAL CLIMB -----------------".
print "Waiting for pitchover altitude or velocity".
wait until ALTITUDE > pitchover_altitude
or VELOCITY:surface:mag > pitchover_velocity.
print "--- PITCHOVER ---".
print "------------------- PITCHOVER --------------------".
// Once a certain altitude or velocity is reached, a slight turn is made, called the pitchover maneuver
lock STEERING to heading(launch_azimuth, 90-pitchover_tilt).
wait until actual_prograde_pitch() > pitchover_tilt. // wait until the prograde "catches up" to our tilted heading
print "Waiting for prograde vector to catch up".
wait until actual_prograde_pitch() > pitchover_tilt.
print "--- GRAVITY TURN ---".
print "------------------ GRAVITY TURN ------------------".
// TODO: the angle of the launch azimuth will not account for the fact that our compass will change as we move north/south.
lock STEERING to heading(launch_azimuth, 90-actual_prograde_pitch()). // Follow prograde pitch to get 0 deg angle of attack, but force compass heading at launch azimuth.
print "Waiting for apoapsis to match target altitude".
wait until APOAPSIS > target_orbit_altitude.
lock THROTTLE TO 0.
print "--- CIRCULARIZE ---".
print "Waiting for ship to leave the atmosphere..".
wait until SHIP:dynamicpressure = 0. // don't create maneuver node until we are out of the atmosphere - otherwise the apoapsis altitude and eta will change due to drag
print "------------------ CIRCULARIZE -------------------".
// Don't create maneuver node until we are out of the atmosphere; otherwise the apoapsis' altitude and eta will change due to drag
print "Waiting for ship to leave the atmosphere".
warp_for(atmosphere_exit_eta()). // we'll lose some velocity due to drag, so the warp will exit a few seconds before we actually exit the atmosphere
wait until SHIP:dynamicpressure = 0. // that's why we have this check as well
if auto_deploy_fairings {
deploy_fairings().
wait 3. // wait for fairings to clear the vessel
}
if auto_deploy_solar_panels {
print "Deploying solar panels".
PANELS on.
}
if auto_extend_antennas {
extend_antennas().
}
print "Deploying solar panels".
PANELS on.
// Create maneuver node that will circularize the orbit.
// Create maneuver node that will circularize the orbit. TODO: create circulize()-function in lib/maneuvers.ks instead
// NOTE: Potential errors in the inclination are not fixed, since we are most likely going to change our orbit, which will make the inclination change cheaper later on.
local node is NODE(TIME:SECONDS + ETA:APOAPSIS, 0, 0, 0).
@ -102,7 +123,7 @@ function launch {
execute_node().
print "========= LAUNCH SEQUENCE COMPLETE =========".
print "------------ LAUNCH SEQUENCE COMPLETE ------------".
unlock_control().
}
@ -126,4 +147,4 @@ function calculate_launch_azimuth {
}
launch(100_000, 0).
launch(100_000, 45).

View file

@ -1,8 +1,20 @@
@LAZYGLOBAL OFF.
function round_towards_zero {
function int {
//
// Truncate or round towards zero.
//
parameter n.
if n < 0 return ceiling(n).
return floor(n).
}
function atmosphere_exit_eta {
//
// Return the number of seconds until the vessel exists the atmosphere.
//
// the vdot gives us the magnitude of the orbital velocity vector in the UP direction because UP is a unit vector
return (BODY:atm:height - ALTITUDE) / vdot(velocity:orbit, UP:vector).
}