Better cohesion.

This commit is contained in:
Casper V. Kristensen 2019-02-08 23:18:34 +01:00
parent c99684d4dd
commit a38712c5a8
Signed by: caspervk
GPG key ID: 289CA03790535054
4 changed files with 44 additions and 16 deletions

View file

@ -6,6 +6,7 @@ run once "lib/rocket".
run once "lib/util".
run once "lib/vectors".
run once "lib/warp".
run once "maneuvers".
function launch {
@ -111,16 +112,8 @@ function launch {
extend_antennas().
}
// 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).
// Burn magnitude in the prograde direction is the difference between the required velocity to acheive circular orbit at apoapsis altitude and our velocity at apoapsis
local required_velocity is orbital_velocity_from_ap_pe(APOAPSIS, APOAPSIS, target_orbit_altitude).
set node:prograde to required_velocity - velocityat(SHIP, TIME:seconds + ETA:apoapsis):orbit:mag.
add node.
execute_node().
// 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.
circularize_at_apoapsis().
print "------------ LAUNCH SEQUENCE COMPLETE ------------".
@ -129,9 +122,12 @@ function launch {
function calculate_launch_azimuth {
//
// Calculate the launch azimuth; the compass heading we head for when launching to achieve orbit of desired inclination.
// Based on:
// http://www.orbiterwiki.org/wiki/Launch_Azimuth
// https://www.princeton.edu/~stengel/MAE342Lecture4.pdf
//
parameter target_orbit_inclination.
parameter target_orbit_altitude. // to compensate for the rotation of the body, we need to know the velocity of the target orbit, which is calculated from its altitude
parameter launch_site_latitude.
@ -139,7 +135,7 @@ function calculate_launch_azimuth {
local inertial_azimuth is arcsin(cos(target_orbit_inclination) / cos(launch_site_latitude)). // azimuth in inertial space, that is, disregarding the rotation of the body
local equatorial_rotational_velocity is (2 * CONSTANT:PI * BODY:radius) / BODY:rotationperiod.
local target_orbit_velocity is orbital_velocity_from_ap_pe(target_orbit_altitude, target_orbit_altitude, target_orbit_altitude).
local target_orbit_velocity is orbital_velocity_circular(target_orbit_altitude).
local launch_vector_x_component is target_orbit_velocity * sin(inertial_azimuth) - equatorial_rotational_velocity * cos(launch_site_latitude).
local launch_vector_y_component is target_orbit_velocity * cos(inertial_azimuth).

View file

@ -52,6 +52,11 @@ function orbital_velocity_from_ap_pe {
return orbital_velocity(altitude, semi_major_axis(ap, pe)).
}
function orbital_velocity_circular {
parameter altitude.
return orbital_velocity_from_ap_pe(altitude, altitude, altitude).
}
function orbital_eccentricity {
//

View file

@ -29,7 +29,7 @@ function execute_node {
print "=== EXECUTE MANEUVER NODE ===".
print "Estimated burn duration: " + ROUND(burn_duration, 1) + "s".
print "Aligning ship with burn vector..".
print "Aligning ship with burn vector".
SAS off.
lock STEERING to node:deltav.
wait until vang(SHIP:facing:vector, node:deltav) < 0.5.

View file

@ -21,4 +21,31 @@ function change_orbit {
print argument_of_periapsis.
}
change_orbit().
function circularize {
//
// Circularize orbit at the given target.
//
parameter target.
parameter eta. // eta to target
local node is NODE(TIME:SECONDS + eta, 0, 0, 0).
// Prograde burn magnitude is the difference between the required velocity to achieve circular orbit at target's altitude and our actual velocity at the target
local required_velocity is orbital_velocity_circular(target).
set node:prograde to required_velocity - velocityat(SHIP, TIME:seconds + eta):orbit:mag.
add node.
execute_node(node).
}
function circularize_at_apoapsis {
print "Circularizing at apoapsis".
return circularize(APOAPSIS, ETA:APOAPSIS).
}
function circularize_at_periapsis {
print "Circularizing at periapsis".
return circularize(PERIAPSIS, ETA:PERIAPSIS).
}
circularize_at_periapsis().