// This script will launch a rocket into a circular orbit around Kerbin // It assumes the rocket has at least two stages and a fairing // It also assumes the rocket has the following mods installed: // KRPC, KOS, KOS-StockCamera, KOS-Scansat, KOS-EVA, KOS-Career, QuickStart // Set the desired apoapsis and inclination of the orbit set target_apo to 200000. // in meters set target_inc to 0. // in degrees // Set the launch time (optional) set launch_time to "10:00:00". // in 00:00:05 format // Set the maximum thrust-to-weight ratio (optional) set max_twr to 1.5. // Initialize some variables set stage_number to stage:number. set stage_liquidfuel to stage:liquidfuel. set throttle to 1. set steering to 90. // Wait for the launch time (optional) if launch_time <> "" { print "Waiting for launch time: " + launch_time. wait until time:seconds = time:seconds(launch_time). } // Activate the first stage and lock the steering to east print "Liftoff!". stage. lock steering to heading(steering, 90). // Main ascent loop until apoapsis > target_apo or stage_number = 0 { // Throttle down if twr is too high if ship:maxthrust / ship:mass > max_twr { set throttle to max_twr * ship:mass / ship:maxthrust. } // Throttle up if twr is too low if ship:maxthrust / ship:mass < max_twr * 0.9 { set throttle to 1. } // Stage when out of liquid fuel if stage_liquidfuel = 0 { print "Staging.". stage. set stage_number to stage:number. set stage_liquidfuel to stage:liquidfuel. } // Jettison fairing when above 70 km if altitude > 70000 and ship:fairing { print "Jettisoning fairing.". ship:fairing:jettison(). } // Adjust steering based on altitude and velocity if altitude < 10000 { // Stay vertical until 10 km set steering to 90. } else if altitude < 40000 { // Gradually pitch down until 40 km set steering to 90 - (altitude - 10000) / 1000. } else { // Follow prograde until apoapsis set steering to velocity:orbit. } // Lock steering to the desired direction lock steering to heading(steering, 90 - target_inc * sin(longitude)). } // Cut off engines and coast to apoapsis print "Coasting to apoapsis.". set throttle to 0. // Circularize at apoapsis print "Circularizing.". lock steering to prograde. wait until eta:apoapsis < 30. set throttle to 1. wait until periapsis > target_apo - 1000. set throttle to 0. // Print orbital parameters and end the script print "Orbit achieved.". print "Apoapsis: " + round(apoapsis) + " m.". print "Periapsis: " + round(periapsis) + " m.". print "Inclination: " + round(inclination) + " deg.". print "End of script.".