Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //launch.ks
- //code by "Seth Persigehl" used as reference
- //This program launches the LKOS from the KSC and flies it into low Kerbin orbit
- clearscreen.
- //Set the ship to a known configuration
- SAS off.
- RCS off.
- lights off.
- lock throttle to 0.
- gear off.
- //Init variables
- declare GLOBAL targetApoapsis to 100000.
- declare GLOBAL targetPeriapsis to 100000.
- declare GLOBAL targetInclination to 90.
- declare GLOBAL currentInclination to 0.
- declare GLOBAL targetAzimuth to 90.
- declare GLOBAL targetPitch to 90.
- declare GLOBAL stages to 0.
- RUN launch_util.ks.
- LOCAL azimuthData to initAzimuth(targetApoapsis, targetPeriapsis, targetInclination).
- set runmode to 2. //Safety in case rocket is mid-flight
- if ALT:RADAR < 50 //Waiting for takeoff
- {
- set runmode to 1.
- }
- until runmode = 0 //Run until we end the program
- {
- lock currentInclination to SHIP:OBT:INCLINATION.
- lock targetAzimuth to getAzimuth(azimuthData).
- if runmode = 1 //Ship is on the launchpad
- {
- lights on.
- print "Launch sequence start" + " " at (5,1).
- print "T - 30 seconds" at (5,2).
- wait 10.
- SAS on.
- lock steering to UP. //Point the rocket straight up
- print "Internal guidance online" + " " at (5,1).
- print "T - 20 seconds" at (5,2).
- wait 10.
- print "All systems at go" + " " at (5,1).
- print "T - 10 seconds" at (5,2).
- wait 1.
- print "T - 09 seconds" at (5,2).
- wait 1.
- stage. //Activate Engines
- print "Ignition sequence start" + " " at (5,1).
- print "T - 08 seconds" at (5,2).
- wait 1.
- print "T - 07 seconds" at (5,2).
- wait 1.
- print "T - 06 seconds" at (5,2).
- wait 1.
- print "T - 05 seconds" at (5,2).
- wait 1.
- print "T - 04 seconds" at (5,2).
- wait 1.
- print "T - 03 seconds" at (5,2).
- wait 1.
- set TVAL to (1.0). //Throttle up to 100%
- lock throttle to TVAL.
- print "All engines running" + " " at (5,1).
- print "T - 02 seconds" at (5,2).
- wait 1.
- print "T - 01 seconds" at (5,2).
- wait 1.
- stage. //Release launch clamps
- set stages to (stages + 1).
- print "Liftoff!" + " " at (5,1).
- print "T - 00 seconds" at (5,2).
- set runmode to 2. //Go to the next runmode
- }
- else if runmode = 2 // Fly UP to 10,000m
- {
- set targetPitch to 90.
- lock steering to heading (targetAzimuth + 0,targetPitch). //Straight up.
- set TVAL to (1.0).
- if SURFACESPEED > 100 //Once altitude is higher than 10km, go to Gravity Turn mode
- {
- print "Performing Gravity turn" + " " at (5,1).
- set runmode to 3.
- }
- }
- else if runmode = 3 //Gravity turn
- {
- if ALT:RADAR < 15000 //Pitch between 90 and 45 degrees
- {
- set targetPitch to (45 * (2 - (ALT:RADAR / 15000))).
- }
- else //Pitch between 45 and 5 degrees
- {
- set targetPitch to (5 + 40 * (1 - (ALT:RADAR-15000) / 45000)).
- }
- lock steering to heading ( targetAzimuth + 0, targetPitch). //Heading 90' (East), then target pitch
- set TVAL to (1.0).
- if (stages = 1) and (SURFACESPEED > 250)
- {
- print "throttle down for max Q" + " " at (5,1).
- set TVAL to (0.667).
- }
- else if stages = 2
- {
- print "throttle up" + " " at (5,1).
- }
- if SHIP:APOAPSIS > targetApoapsis
- {
- print "main engine cut off" + " " at (5,1).
- set runmode to 4.
- }
- }
- else if runmode = 4 //Coast to Ap
- {
- set targetPitch to 3.
- lock steering to heading ( targetAzimuth + 0, targetPitch). //Stay pointing 3 degrees above horizon
- set TVAL to (0.0). //Engines off.
- if (SHIP:ALTITUDE > 70000) and (ETA:APOAPSIS > 60) and (VERTICALSPEED > 0) {
- if WARP = 0 // If we are not time warping
- {
- wait 1. //Wait to make sure the ship is stable
- print "deploying solar panels" + " " at (5,1).
- panels on. //Deploy solar panels
- wait 5.
- print "coasting to apoapsis" + " " at (5,1).
- SET WARP TO 3. //Be really careful about warping
- }
- }.
- else if ETA:APOAPSIS < 60
- {
- SET WARP to 0.
- set runmode to 5.
- }
- }
- else if runmode = 5 //Burn to raise Periapsis
- {
- set targetPitch to 0.
- lock steering to heading ( targetAzimuth + 0, targetPitch).
- if ETA:APOAPSIS < 5 or VERTICALSPEED < 0 //If we're less 5 seconds from Ap or loosing altitude
- {
- print "performing circularization burn" + " " at (5,1).
- if (SHIP:PERIAPSIS < targetPeriapsis * 0.8) //full throttle
- {
- set TVAL to (1.0).
- }
- else //decrease throttle near circularization
- {
- set TVAL to (1.0) - min(0.8, ((SHIP:PERIAPSIS - targetPeriapsis * 0.8) / (targetPeriapsis - targetPeriapsis * 0.8))).
- }
- }
- if (SHIP:PERIAPSIS > targetPeriapsis) or (SHIP:PERIAPSIS > targetApoapsis * 0.995) //If the periapsis is high enough or getting close to the apoapsis
- {
- set TVAL to (0.0).
- set runmode to 10.
- }
- }
- else if runmode = 10 //Final touches
- {
- set TVAL to (0.0). //Shutdown engine.
- lights on.
- unlock steering.
- print "ascent completed" + " " at (5,1).
- set runmode to 0.
- }
- //Housekeeping
- // Check for flameout of any of the existing engines:
- set stg_numF to 0.
- list engines in stg_eList.
- for stg_eng in stg_eList
- {
- if stg_eng:flameout
- {
- set stg_numF to stg_numF + 1.
- }.
- }.
- if stg_numF > 0 //If any engines flamed out: stage
- {
- lock throttle to 0.
- wait 2.
- stage.
- set stages to (stages + 1).
- wait 2.
- lock throttle to TVAL.
- }
- set finalTVAL to TVAL.
- lock throttle to finalTVAL. //Write our planned throttle to the physical throttle
- //Print data to screen.
- print "T + " + round(MISSIONTIME) at (5,2).
- print "RUNMODE: " + runmode + " " at (5,4).
- print "STAGE: " + stages + " " at (5,5).
- print "ALTITUDE: " + round(SHIP:ALTITUDE) + " " at (5,6).
- print "ETA to AP: " + round(ETA:APOAPSIS) + " " at (5,7).
- print "APOAPSIS: " + "current: " + round(SHIP:APOAPSIS) + " target: " + round(targetApoapsis) + " " at (5,15).
- print "PERIAPSIS: " + "current: " + round(SHIP:PERIAPSIS) + " target: " + round(targetPeriapsis) + " " at (5,16).
- print "INCLINATION: " + "current: " + round(currentInclination) + " target: " + round(targetInclination) + " " at (5,17).
- print "STEERING: " + "azimuth: " + round(targetAzimuth) + " pitch : " + round(targetPitch) + " " at (5,18).
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement