Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Basic Launch Script for KSP Rockets with or without Booster.
- // by Niwo
- // Version 0.3
- // Declaration
- set tVal to 0. // Throttle Value
- set aborted to 0.
- set liftoff to 0.
- set f to 0. // Failure Counter
- set s to 0. // Stage Counter Variable
- set targetPeriapsis to 95000.
- set targetApoapsis to 100000.
- set boosters to 0.
- // SET Stage1 TO SHIP:PARTSDUBBED("Stage1")[0]. // TODO
- // Booster check.
- if ship:solidfuel > 0 {
- set boosters to 1. // are there any boosters?
- }.
- if ALT:RADAR < 50 {
- // Phase 1
- // Prestart Checks
- // TODO: Make it smarter with while i++ and at (x,x). stuff
- clearscreen.
- Print "Initiating Prelaunch Configuration".
- print "#____".
- wait 0.5.
- // Setting up SAS
- clearscreen.
- Print "Initiating Prelaunch Configuration".
- print "##___".
- PRINT "SETTING UP SAS".
- sas on.
- wait 0.5.
- clearscreen.
- Print "Initiating Prelaunch Configuration".
- print "###__".
- PRINT "SETTING UP SAS".
- PRINT "SETTING SAS TO STABILITYASSIST".
- SET SASMODE TO "STABILITYASSIST".
- wait 0.5.
- // Setting up Throttle
- clearscreen.
- Print "Initiating Prelaunch Configuration".
- print "####_".
- PRINT "SETTING UP SAS".
- PRINT "SETTING SAS TO STABILITYASSIST".
- PRINT "Setting Full Throttle".
- set tVal to 1.
- lock throttle to tVal.
- wait 0.5.
- // Setting Steering to up 0°
- clearscreen.
- Print "Initiating Prelaunch Configuration".
- print "#####".
- PRINT "SETTING UP SAS".
- PRINT "SETTING SAS TO STABILITYASSIST".
- PRINT "Setting Full Throttle".
- Print "Setting Steering to up".
- lock steering to up + R(0,0,180). wait 1.
- // Phase 2
- // LAUNCH!!!
- // If you want a Countdown.
- FROM {local countdown is 5.} UNTIL countdown = 0 STEP {SET countdown to countdown - 1.} DO {
- PRINT "Countdown: " + countdown at (1,7).
- print " ".
- WAIT 1.
- }
- PRINT "Ignition!".
- stage.
- wait 2.
- until ALT:RADAR < 10 {
- if verticalspeed > 10 + aborted = 0 + liftoff = 0 {
- PRINT " ".
- PRINT "LIFTOFF!".
- set liftoff to 1.
- break.
- }.
- else if liftoff = 0 {
- set aborted to 1.
- lock throttle to 0.
- set tVal to 0.
- sas off.
- until f = 5 {
- clearscreen.
- print "FAILURE! Abort Start immediatly !!!".
- wait 0.5.
- clearscreen.
- print " ".
- wait 0.5.
- set f to (f + 1).
- }.
- clearscreen.
- print "Start aborted.".
- print "Launch Program Terminated.".
- break.
- }.
- }.
- if liftoff = 1 {
- // Permanent Checking
- // Seperating Boosters
- when stage:solidfuel < 0.01 and boosters = 1 then {
- stage.
- print " ".
- print "Boosters separated.".
- }.
- // Seperating Stage (Seperator and next Stage Engine must be in the same stage section!!!)
- when stage:liquidfuel < 0.1 OR SHIP:MAXTHRUST < 0.1 and tVal > 0.1 and s < 4 then { // Fallback function: if stage:liquidfuel refers to the whole ship, or ship:maxthrust and ... initiates staging.
- // when stage:liquidfuel < 0.1 then {
- stage.
- set s to MAX(4, s + 1 ).
- print " ".
- print "Stage " + s + " separated.". // add num counter.
- preserve.
- }.
- // Phase 3
- // Climb
- wait until altitude > 2000.
- Print "2000m ASL. Turn HDG 270 Degrees.".
- lock steering to up + R(0,0,270).
- // Phase 4
- // Roll Program
- wait until altitude > 10000.
- Print "10000m ASL. " .
- PRINT "Commencing Roll Program".
- set roll to 1.
- until altitude > 31000 {
- if roll = 1 {
- set targetPitch to MAX(30, 90 * (1 - ALT:RADAR / 31000)). //Pitch over gradually until levelling out to 30 degrees at 31km
- lock steering to heading ( 90, targetPitch). //Heading 90' (East), then target pitch
- print "Target Pitch: " + round(targetPitch) + " Degrees." at (1,40).
- if targetPitch < 31 {
- // lock steering to heading ( 90, 30). //Heading 90' (East), then target pitch 30°, fallback
- set roll to 0.
- print "Roll complete.".
- print " " at (1,40).
- }.
- }.
- }.
- // Phase 5
- // Orbit
- wait until altitude > 32000.
- print "Waiting for Apoapsis to be 100000 km (ASL).".
- wait until ALT:APOAPSIS > targetApoapsis.
- set tVal to 0.
- PRINT "Switching SAS off, to save energy.".
- sas off.
- // lock throttle to 0. // pretty obsolete.
- if ETA:APOAPSIS < 59 {
- print "ETA to AP: " + round(ETA:APOAPSIS) + " s " at (5,8).
- }.
- else {
- print "ETA to AP: " + round(ETA:APOAPSIS / 60) + " min " at (5,8).
- }.
- // lock steering to prograde.
- print "Waiting for circularization burn.".
- wait until eta:apoapsis < 30.
- SET WARP TO 0.
- wait 5.
- PRINT "SETTING SAS TO ON AND PROGRADE".
- sas on.
- wait 0.5.
- SET SASMODE TO "PROGRADE".
- wait 4.
- set tVal to 0.7.
- lock throttle to tVal. // repeated for saftey. Test if its obsolete.
- until ALT:PERIAPSIS > targetPeriapsis {
- if ETA:APOAPSIS < 5 or VERTICALSPEED < 0 { //If we're less 5 seconds from Ap or loosing altitude
- if vBurn = 0 {
- print "Burn.".
- set vBurn to 1.
- }.
- set tVal to 1.
- }
- if (SHIP:PERIAPSIS > targetPeriapsis) or (SHIP:PERIAPSIS > targetApoapsis * 0.95) {
- //If the periapsis is high enough or getting close to the apoapsis
- set tVal to 0.
- }
- }
- wait until ALT:PERIAPSIS > targetPeriapsis.
- set tVal to 0.
- lock throttle to 0.
- wait 2.
- PRINT "Switching SAS off, to save energy.".
- sas off.
- wait 1.
- until f = 10 {
- clearscreen.
- print "Orbit Reached.".
- print "KILL ENGINES!!!".
- wait 0.5.
- clearscreen.
- print "Orbit Reached.".
- print " ".
- wait 0.5.
- set f to (f + 1).
- }.
- }.
- }. else {
- Print "You are not ready to launch or not on the Launchpad.".
- Print "Your Status is: " + Status.
- WAIT UNTIL FALSE.
- }.
- //end program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement