Skip to content

Instantly share code, notes, and snippets.

@HerrCraziDev
Created January 6, 2018 17:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save HerrCraziDev/468a832395a427a3283a6b1b2b54a469 to your computer and use it in GitHub Desktop.
Save HerrCraziDev/468a832395a427a3283a6b1b2b54a469 to your computer and use it in GitHub Desktop.
Script for performing an hoverslam (aka. suicide burn) in KSP, like SpaceX's rockets. Uses the mod kOS. Start the script on the launchpad, and launch the rocket normally. It will automatically handle the descent and landing for you.
parameter defaultRadarOffset is 7, gearDeployTime is 6.
clearscreen.
print "*****************************".
print "* FAITO Aerospace *".
print "* XASR-3.1 Autolander Pilot *".
print "* © Empire of Fegeland, 2055*".
print "*****************************".
if defaultRadarOffset <> 7
{
set radarOffset to defaultRadarOffset.
}
if abs(ship:verticalspeed) < 1
{
set radarOffset to alt:radar. // The value of alt:radar when landed (on gear)
} else if radarOffset = 0 {
set radarOffset to defaultRadarOffset.
print "Warning : pilot engaged while in flight, radar offset will be set to 7 (XASR-3).".
}
//Distance from impact point, else vessel's altitude
if addons:tr:available and addons:tr:hasimpact
{
lock impactDist to addons:tr:impactpos:distance.
} else {
lock impactDist to alt:radar - radarOffset.
print "Warning : impact position not available. You should (re)install Trajectories, or maybe takeoff.".
}
lock g to constant:g * body:mass / body:radius^2. // Gravity (m/s^2)
lock shipVel to ship:velocity:surface:mag. // Vessel's total velocity
lock maxDecel to (ship:availablethrust / ship:mass) - g. // Maximum deceleration possible (m/s^2)
lock stopDist to ship:velocity:surface:sqrmagnitude / (2 * maxDecel). // The distance the burn will require
lock idealThrottle to stopDist / impactDist. // Throttle required for perfect hoverslam
lock impactTime to impactDist / abs(shipVel). // Time until impact, used for landing gear
print "Radar offset : " at (0, terminal:width).
print radarOffset at (16, terminal:width).
when ship:verticalspeed < -1 then
{
print "Preparing for autolanding...".
rcs on.
sas off.
brakes on.
lock steering to srfretrograde.
when impactTime < gearDeployTime then
{
gear on.
}
when impactDist < stopDist then
{
print "Performing autolanding".
print idealThrottle.
print shipVel.
print stopDist.
lock throttle to idealThrottle.
when ship:groundspeed < 1 and ship:verticalspeed < 5 then
{
lock steering to Up.
print "Vessel verticalized.".
}
when impactTime < 2 then
{
lock impactDist to alt:radar - radarOffset.
print "Precision approach phase. Impact in 2s.".
}
when ship:status = "LANDED" then
{
print "Autolanding completed".
set ship:control:pilotmainthrottle to 0.
unlock steering.
rcs off.
sas on.
}
}
}
UNTIL ship:status = "LANDED"
{
print "SRF VEL : " + round(shipVel, 4) + " m/s " at (0, terminal:height - 11).
print "HOR VEL : " + round(ship:groundspeed, 4) + " m/s " at (0, terminal:height - 10).
print "VERT VEL : " + round(ship:verticalspeed, 4) + " m/s " at (0, terminal:height - 9).
print "DESC RATE: " + round( abs(ship:verticalspeed/ship:groundspeed), 2) + " " at (0, terminal:height - 8).
print "IMPACT : T+" + round(impactTime, 3) + " s " at (0, terminal:height - 6).
print "IMPACT DIST : " + round(impactDist, 2) + " m " at (0, terminal:height - 5).
print "MAX DECEL : " + round(maxDecel, 5) + " m/s² " at (0, terminal:height - 4).
print "S. BURN DIST : " + round(stopDist, 2) + " m " at (0, terminal:height - 3).
print "THROTTLE : " + round(idealThrottle*100,2) + " % " at (0, terminal:height - 1).
WAIT 0.01.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment