Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clearscreen.
- // 1. sets initial conditions
- set name to SHIP:name.
- set engines to ship:partstagged("engine").
- // 1.1. sets operational mode conditions to initial conditions.
- set trajectory to "Pre Launch".
- set maneuvre to "null".
- set mission_complete to false.
- // 1.2. sets functial variables to initial conditions.
- set thr to 0.
- set tick to 0.01.
- set taim to 0.
- set prevtaim to 0.
- set captabel to false.
- set counter to 1.
- set STAGE_COUNT to -1.
- for i in engines set STAGE_COUNT to STAGE_COUNT + 1.
- set display_stage to 1.
- set direction to heading(0,0).
- set throt to thr.
- lock steering to direction.
- lock throttle to throt.
- lock orbitlength to (max(eta:apoapsis,eta:periapsis) - min(eta:apoapsis,eta:periapsis))*2.
- set message1 to " ".
- set message2 to " ".
- set message3 to " ".
- // above reserved for future variables.
- // 1.2. sets navigation variables to initial conditions.
- set PITCH to 90.
- lock atmo_dir to heading(INCL,PITCH).
- // above reserved for future variables
- // 1.3. sets mission goals
- set TARGET_APO to 90000.
- set TARGET_PER to 90000.
- set INCL to 90.
- set TARGET_TRAJ to "Orbital".
- set TARGET_BODY to "Kerbin".
- set TARGET_SMA to (TARGET_APO + TARGET_PER)/2.
- lock SMA to (apoapsis + periapsis)/2.
- lock mission to ((TARGET_APO*0.02 > abs(TARGET_APO - apoapsis)) and (TARGET_PER*0.02 > abs(TARGET_PER - periapsis)) and (trajectory = TARGET_TRAJ)).
- lock secondary_mission to (TARGET_APO*0.05 > abs(TARGET_APO - apoapsis)) and (trajectory = TARGET_TRAJ).
- // 1.3.1 adjusts goals for error
- //set TARGET_PER to TARGET_PER*0.97.
- //set TARGET_APO to TARGET_APO*0.99337748.
- // 2. Prints display.
- function clearmessages
- {
- print " " at (3,30).
- print " " at (3,31).
- print " " at (3,32).
- }.
- function printmessages
- {
- parameter message1.
- parameter message2.
- parameter message3.
- set m1 to message1.
- set m2 to message2.
- set m3 to message3.
- print m1 at (3,30).
- print m2 at (3,31).
- print m3 at (3,32).
- }
- until counter = 50
- {
- print "=" at (counter,0).
- print "=" at (counter,34).
- print "-" at (counter,28).
- print "-" at (counter,6).
- set counter to counter + 1.
- }.
- set counter to 1.
- until counter = 33
- {
- print "|" at (0,counter).
- print "|" at (50,counter).
- set counter to counter +1.
- }.
- set counter to 1.
- until counter = 28
- {
- print "|" at (24,counter).
- set counter to counter +1.
- }.
- print " FLIGHT DATA " at (5,0).
- print " System messages: " at (5,28).
- print " TELEMETRY " at (8,3).
- print " PROJECTIONS " at (32,3).
- until mission_complete
- {
- // 2 Checks if mission complete - Input mission end parameters in condition below
- if mission
- {
- wait 5.
- toggle lights.
- set incl to incl + 180.
- set TARGET_TRAJ to "Decaying orbit".
- set TARGET_PER to 45000.
- set taim to taim + 5.
- if mission
- {
- //set mission_complete to true.
- set thr to 0.
- unlock steering.
- unlock direction.
- clearmessages.
- if mission <> secondary_mission
- {
- set message1 to "Primary mission complete".
- set mesasage2 to " ".
- set mission_complete to false.
- // set mission to secondary_mission.
- }.
- //if mission = secondary_mission
- // {
- // set message2 to "Mission accomplished".
- // }.
- }.
- }.
- // 3 Updates display with flight parameters.
- print ship:body at (6,8).
- if altitude < 1000 print " Altitude(km): 0" at (5,11).
- if altitude > 1000
- print " Altitude(km): " + (altitude - mod(altitude,1000))/1000 at (5,11).
- print " Speed(m/s): " + (ship:airspeed - mod(ship:airspeed,1) + " ") at (5,14).
- print " Throttle: " + ((throttle / 0.01) - mod(throttle / 0.01,1)) + "% " at (5,17).
- print " Mass (t): " + (ship:mass - mod(ship:mass,1)) at (5,20).
- print " Apoapsis(km):" + ((apoapsis - mod(apoapsis,1000))/1000 + " ") at (25,8).
- if periapsis < 0 print " Periapsis(km): 0" at (25,11).
- if periapsis > 0 print " Periapsis(km):" + (periapsis - mod(periapsis,1000))/1000 + " " at (25,11).
- print " Trajectory:" + trajectory + " " at (25,14).
- clearmessages.
- printmessages(message1,message2,message3).
- // 4.1 LAUNCH.
- if (trajectory = "Pre Launch") and (mission_complete = false)
- {
- set message1 to "Initialising flight parameters".
- set direction to heading(incl,90).
- set thr to 0.1.
- // 4.1 sets up flight log.
- set message2 to "Setting up flight log".
- set skipl0g to ship:name.
- set skipl0g to skipl0g + ".csv".
- switch to archive.
- //delete skipl0g.
- if captabel = false
- {
- log "Time,Altitude,Speed (x10),Throttle,Apoapsis,Periapsis" to skipl0g.
- set captabel to true.
- }.
- switch to 1.
- // 4.2 Launches vehicle.
- stage.
- set message3 to "Booster ignition".
- wait 3.
- set taim to taim + 3.
- }.
- // 5 Staging controls.
- if (STAGE_COUNT > -0.5) and (mission = false)
- if engines[STAGE_COUNT]:flameout
- {
- set message2 to ("Stage " + display_stage + " completed: discarding booster").
- wait 1.
- set taim to taim + 1.
- stage.
- wait 1.
- set taim to taim + 1.
- stage.
- set message1 to ("Stage " + (display_stage + 1) + " Commencing...").
- set display_stage to display_stage + 1.
- set STAGE_COUNT to STAGE_COUNT - 1.
- }.
- // 6 Checks flight mode
- if (ship:airspeed < 1) and (prevtaim < 5) set trajectory to "Pre Launch".
- if (ship:airspeed > 1) and (apoapsis < 70000) set trajectory to "Ballistic".
- if (apoapsis > 70000) and (apoapsis > 0) and (periapsis < 0) set trajectory to "Sub orbital".
- if (apoapsis > 70000) and (apoapsis > 0) and (periapsis < 70000) and (periapsis > 40000) set trajectory to "Decaying orbit".
- if (apoapsis > 70000) and (apoapsis > 0) and (periapsis > 70000) set trajectory to "Orbital".
- if (apoapsis < 0) set trajectory to "On Escape".
- // 7 Performs maneuvres to reach desired trajectory parameters.
- if (TARGET_TRAJ = "Ballistic") and (mission = false)
- {
- set pitch to (((90*TARGET_APO - 90*apoapsis)/TARGET_APO) - mod((90*TARGET_APO - 90*apoapsis)/TARGET_APO,1)).
- if apoapsis > TARGET_APO set pitch to ((eta:apoapsis * 360) * -1)/orbitlength.
- if pitch > 90 set pitch to 90.
- if eta:apoapsis > eta:periapsis set pitch to pitch* -1.
- set message3 to ("Adjusting pitch to:" + (pitch - mod(pitch,1)) + " degrees").
- }.
- if (TARGET_TRAJ = "Sub Orbital") and (mission = false)
- {
- set pitch to (((90*TARGET_APO - 90*apoapsis)/TARGET_APO) - mod((90*TARGET_APO - 90*apoapsis)/TARGET_APO,1)).
- if apoapsis > TARGET_APO set pitch to ((eta:apoapsis * 360) * -1)/orbitlength.
- if pitch > 90 set pitch to 90.
- if eta:apoapsis > eta:periapsis set pitch to pitch* -1.
- set message3 to ("Adjusting pitch to:" + (pitch - mod(pitch,1)) + " degrees").
- }.
- if (TARGET_TRAJ = "Orbital") and (mission = false)
- {
- set pitch to (((90*TARGET_APO - 90*apoapsis)/TARGET_APO) - mod((90*TARGET_APO - 90*apoapsis)/TARGET_APO,1)).
- if apoapsis > TARGET_APO set pitch to ((eta:apoapsis * 360) * -1)/orbitlength.
- if pitch > 90 set pitch to 90.
- if eta:apoapsis > eta:periapsis set pitch to pitch* -1.
- set message3 to ("Adjusting pitch to:" + (pitch - mod(pitch,1)) + " degrees").
- }.
- // Chutes control
- if (eta:periapsis < eta:apoapsis) and (trajectory = "Ballistic") and (ship:airspeed < 300) and (alt:radar < 1500) toggle chutes.
- // 8 Thrust control
- if mission = false
- {
- if (apoapsis < TARGET_APO*0.8) set thr to 1.
- if (apoapsis > TARGET_APO*0.8) set thr to (TARGET_APO*1.03 - Apoapsis) / (TARGET_APO*0.8).
- if (eta:apoapsis/orbitlength < 5/360) and (eta:apoapsis < eta:periapsis) and (trajectory = "Sub orbital") set thr to 1.
- if (eta:apoapsis/orbitlength < 5/360) and ((trajectory = "Decaying orbit") or (trajectory = "Orbital")) set thr to (TARGET_PER*1.03 - Periapsis) / (TARGET_PER*0.8).
- }.
- // 9 Resets controls and counters.
- if thr < 0.02 set thr to 0.
- set throt to thr.
- set direction to heading(incl,pitch).
- wait tick.
- set prevtaim to taim.
- set taim to taim + tick.
- }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement