Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This program launches a ship from the KSC and flies it into equatorial orbit at 100km
- //Set the ship to a known configuration
- // SET SASMODE TO "STABILITYASSIST".
- // declare parameter targetAltitude.
- SAS on.
- RCS off.
- lights off.
- lock throttle to 0. //Throttle is a decimal from 0.0 to 1.0
- gear off.
- clearscreen.
- set mth to SHIP:MAXTHRUST.
- set targetAltitude to 100000. // Convert Target altitude in meter for a circular orbit
- set runmode to 2. //Safety in case we start mid-flight
- if ALT:RADAR < 50 { //Guess if we are waiting for take off
- set runmode to 1.
- print "Launchpad. Check.".
- }
- until runmode = 0 {
- if runmode = 1 { // Ship on launchpad
- lock steering to heading (90,90). //Point the rocket straight up
- set TVAL to 1. //Throttle up to 100%
- stage.
- wait 1.
- stage.
- set mth to SHIP:MAXTHRUST.
- set runmode to 2. //Go to the next runmode
- print "Ignition !".
- }
- else if runmode = 2 { // Fly up to 12k
- lock steering to heading (90,90). //Straight up.
- if SHIP:ALTITUDE < 800 {
- set TVAL to 1.
- }
- if SHIP:ALTITUDE > 800 {
- SET cTWR to SHIP:MAXTHRUST / (SHIP:MASS * SHIP:SENSORS:GRAV:MAG).
- if cTWR > 1.5 {
- SET TVAL to 1.5*(SHIP:MASS * SHIP:SENSORS:GRAV:MAG)/SHIP:MAXTHRUST.
- }
- if cTWR < 1.5 {
- SET TVAL to 1.
- }
- }
- if SHIP:ALTITUDE > 12000 {
- set runmode to 3.
- print "Initiate gravity turn...".
- }
- }
- else if runmode = 3 { // Gravity turn and burd until AP is 90k
- set targetPitch to max( 3, 90 * (1 - (SHIP:ALTITUDE-12000) / (50000-12000) )).
- //Pitch over gradually until levelling out to 1 degrees at 50km
- lock steering to heading ( 90, targetPitch). //Heading 90' (East), then target pitch
- if SHIP:ALTITUDE < 45000 {
- SET cTWR to SHIP:MAXTHRUST / (SHIP:MASS * SHIP:SENSORS:GRAV:MAG).
- if cTWR > 1.5 {
- SET TVAL to 1.5*(SHIP:MASS * SHIP:SENSORS:GRAV:MAG)/SHIP:MAXTHRUST.
- }
- if cTWR < 1.5 {
- SET TVAL to 1.
- }
- }
- else {
- set TVAL to 1.
- }
- if SHIP:APOAPSIS > 100000 {
- set runmode to 4.
- print "Stabilize...".
- }
- }
- else if runmode = 4 { // Warp just after AP
- lock steering to heading ( 90, 0). //Stay pointing 1 degrees above horizon
- set TVAL to 0.
- if (ETA:APOAPSIS > 60) and (VERTICALSPEED > 0) {
- if WARP = 0 AND SHIP:ALTITUDE > 70000 { // If we are not time warping
- wait 1. //Wait to make sure the ship is stable
- SET WARP TO 3. //Be really careful about warping
- }
- }.
- else if ETA:APOAPSIS < 20 {
- SET WARP to 0.
- set runmode to 5.
- print "Circulize...".
- }
- }
- else if runmode = 5 { // Burn until AP/PER is targetAltitude
- set TVAL to 1.
- if (SHIP:PERIAPSIS > targetAltitude*0.90) {
- set TVAL to 0.5.
- }
- if (SHIP:PERIAPSIS > targetAltitude-500) {
- set TVAL to 0.
- set runmode to 10.
- print "Circulized.".
- }
- }
- else if runmode =10 {
- set TVAL to 0.
- unlock steering.
- print "Launch sucessfull.".
- print "Orbit is " + SHIP:PERIAPSIS/1000 + "km / " + SHIP:APOAPSIS/1000 + "km.".
- set runmode to 0.
- }
- lock throttle to TVAL. //Write our planned throttle to the physical throttle
- // Staging
- if mth>SHIP:MAXTHRUST or SHIP:MAXTHRUST=0 {
- stage.
- wait 0.1.
- set mth to SHIP:MAXTHRUST.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement