Improve ascend guidance.
This commit is contained in:
parent
2e65161467
commit
396678e313
67
launch.ks
67
launch.ks
|
@ -16,20 +16,22 @@ function launch {
|
||||||
parameter pitchover_altitude is 1000. // perform pitchover at this altitude
|
parameter pitchover_altitude is 1000. // perform pitchover at this altitude
|
||||||
parameter pitchover_velocity is 100. // or this velocity
|
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 altitude: " + target_orbit_altitude + "m".
|
||||||
print "Target orbital inclination: " + target_orbit_inclination + "°".
|
print "Target orbital inclination: " + target_orbit_inclination + "°".
|
||||||
print "Pitchover tilt: " + pitchover_tilt + "°".
|
print "Pitchover tilt: " + pitchover_tilt + "°".
|
||||||
print "Pitchover at: " + pitchover_altitude + "m or " + pitchover_velocity + " m/s".
|
print "Pitchover at: " + pitchover_altitude + "m or " + pitchover_velocity + " m/s".
|
||||||
print " ".
|
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.
|
// 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.
|
// 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).
|
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
|
// 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 "Available orbital inclination: " + target_orbit_inclination + "°".
|
||||||
print "Launch azimuth: " + round(launch_azimuth, 3) + "°".
|
print "Launch azimuth: " + round(launch_azimuth, 3) + "°".
|
||||||
print "Launch southwards: " + southwards.
|
print "Launch southwards: " + southwards.
|
||||||
|
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 " ".
|
||||||
|
|
||||||
|
|
||||||
print "--- VERTICAL CLIMB ---".
|
// LAUNCH
|
||||||
|
|
||||||
SAS off.
|
SAS off.
|
||||||
RCS on.
|
RCS on.
|
||||||
set NAVMODE to "SURFACE".
|
set NAVMODE to "SURFACE".
|
||||||
lock STEERING to heading(launch_azimuth, 90). // roll to launch azimuth
|
lock STEERING to heading(launch_azimuth, 90). // roll to launch azimuth
|
||||||
lock THROTTLE to 1.0.
|
lock THROTTLE to 1.0.
|
||||||
|
|
||||||
|
when auto_stage and should_stage() then {
|
||||||
// LAUNCH
|
|
||||||
|
|
||||||
// Enable auto-staging
|
|
||||||
when should_stage() then {
|
|
||||||
stage_when_ready().
|
stage_when_ready().
|
||||||
wait 0.5.
|
wait 0.5.
|
||||||
return true. // preserve trigger
|
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
|
wait until ALTITUDE > pitchover_altitude
|
||||||
or VELOCITY:surface:mag > pitchover_velocity.
|
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).
|
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.
|
// 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.
|
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.
|
wait until APOAPSIS > target_orbit_altitude.
|
||||||
lock THROTTLE TO 0.
|
lock THROTTLE TO 0.
|
||||||
|
|
||||||
|
|
||||||
print "--- CIRCULARIZE ---".
|
print "------------------ CIRCULARIZE -------------------".
|
||||||
print "Waiting for ship to leave the atmosphere..".
|
// Don't create maneuver node until we are out of the atmosphere; otherwise the apoapsis' altitude and eta will change due to drag
|
||||||
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 "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
|
||||||
|
|
||||||
print "Deploying solar panels".
|
if auto_deploy_fairings {
|
||||||
PANELS on.
|
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().
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
// 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).
|
local node is NODE(TIME:SECONDS + ETA:APOAPSIS, 0, 0, 0).
|
||||||
|
|
||||||
|
@ -102,7 +123,7 @@ function launch {
|
||||||
execute_node().
|
execute_node().
|
||||||
|
|
||||||
|
|
||||||
print "========= LAUNCH SEQUENCE COMPLETE =========".
|
print "------------ LAUNCH SEQUENCE COMPLETE ------------".
|
||||||
unlock_control().
|
unlock_control().
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,4 +147,4 @@ function calculate_launch_azimuth {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
launch(100_000, 0).
|
launch(100_000, 45).
|
||||||
|
|
14
lib/util.ks
14
lib/util.ks
|
@ -1,8 +1,20 @@
|
||||||
@LAZYGLOBAL OFF.
|
@LAZYGLOBAL OFF.
|
||||||
|
|
||||||
function round_towards_zero {
|
function int {
|
||||||
|
//
|
||||||
|
// Truncate or round towards zero.
|
||||||
|
//
|
||||||
parameter n.
|
parameter n.
|
||||||
|
|
||||||
if n < 0 return ceiling(n).
|
if n < 0 return ceiling(n).
|
||||||
return floor(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).
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue