Created
February 22, 2018 07:37
-
-
Save HerrCraziDev/908519946a3ad07ebfc5243a21669d5e to your computer and use it in GitHub Desktop.
Function lib for the Falcon Heavy autopilot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//getLandingSite(String siteName) | |
// Return the GeoPosition of the site matching siteName, or the current vessel's position if not found | |
function getLandingSite | |
{ | |
parameter name is "auto". | |
if name = "auto" | |
{ | |
return ship:geoposition. | |
} | |
else if name = "LZ-2" | |
{ | |
return LATLNG(-0.15345044141426, -74.4820354877508). | |
} | |
else | |
{ | |
return VESSEL(name):geoposition. | |
} | |
} | |
//launch(Scalar targetOrbit [, Scalar targetHeading]) | |
// Launch to an orbit which apoapsis is targetOrbit and prograde direction is targetHeading | |
function fh_launch | |
{ | |
parameter targetOrbit is 80. | |
parameter targetHeading is 90000. | |
sas off. | |
//quick and dirty gravity turn | |
print "Performing gravity turn...". | |
lock steering to heading(targetHeading, 90 - ( (ship:orbit:apoapsis / targetOrbit)*90) ). | |
//when to stop for the boostback (making sure there is enough fuel to perform the boosback) | |
WAIT UNTIL ship:orbit:apoapsis >= targetOrbit or stage:resources[lqfResIndex]:amount < stage:resources[lqfResIndex]:capacity/3. | |
print "Staging side cores.". | |
set ship:control:pilotmainthrottle to 0. | |
STAGE. | |
WAIT 1. | |
set ship:control:pilotmainthrottle to 1. | |
skid:play( note(880, 0.04) ). | |
WAIT 0.02. | |
skid:play( note(880, 0.04) ). | |
} | |
//boostback(GeoPosition landingTarget) | |
// Do a boostback burn, attempting to bring the impact point as closest as possible from landingTarget | |
function fh_boostback | |
{ | |
parameter landingTarget. | |
print "Boostback phase started". | |
set ship:control:pilotmainthrottle to 0. | |
sas off. | |
rcs on. | |
lock throttle to 0. | |
lock burnVect to landingTarget:position - addons:tr:impactpos:position. | |
lock impactDistToTarget to burnVect:mag. | |
lock steering to burnVect. | |
print "Pointing the right direction". | |
from {local i is 3.} until (i = 0) step {set i to i-1.} do | |
{ | |
WAIT UNTIL VANG(ship:facing:vector, burnVect) < 5. | |
WAIT 0.5. | |
} | |
print "Performing boostback burn.". | |
lock throttle to min(impactDistToTarget/4000, 1). | |
UNTIL impactDistToTarget < 10 | |
{ | |
print "IMPCT-TRGT DIST. : "+round(impactDistToTarget, 3)+" " at (0,terminal:height-2). | |
WAIT 0.01. | |
} | |
unlock steering. | |
unlock throttle. | |
set throttle to 0. | |
set ship:control:pilotmainthrottle to 0. | |
rcs off. | |
sas on. | |
print "Boostback burn completed.". | |
} | |
//getResourceIndex(Strin resourceName) | |
// Get the index of the resource named resourceName in the resources list | |
function getResourceIndex | |
{ | |
local parameter resourceName. | |
set itResources to stage:resources:iterator. | |
UNTIL NOT itResources:next() | |
{ | |
if itResources:value:name = resourceName | |
{ | |
return itResources:index. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment