Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Trajectory program variables
- set turnStart to 500.
- set turnEnd to 70000.
- set turnExponent to 0.5.
- set finalAngle to 3.
- set targetInclination to 20.
- set targetApospsis to 200000.
- set targetPeriapsis to 200000.
- // End trajectory program variables
- // Steering controller PID values
- set pitchP to 0.04.
- set pitchD to 0.2.
- set yawP to 0.04.
- set yawD to 0.2.
- set rollD to 0.2.
- // End steering controller PID values
- clearscreen.
- if stage:number <> 1
- {
- print "Prestaging sequence not complete.".
- print "Vessel must be ready to activate last stage.".
- wait until False.
- }.
- print "3". wait 1.
- print "2". wait 1.
- rcs on. sas on. print "Vernor engines activated".
- print "1". wait 1.
- stage.
- lock throttle to 1. print "Liftoff!". wait 1.
- clearscreen.
- print "Vertical flight phase in progress" at (8,1).
- wait until alt:radar > turnStart.
- sas off.
- print "Launch trajectory program active " at (8,1).
- print "Altitude ====" at (1,3).
- print "Apoapsis ====" at (1,5). print "ETA =" at (25,5).
- print "Periapsis ===" at (1,6).
- print "O. Velocity =" at (1,8).
- print "Inclination =" at (1,9).
- print "Pitch Cmd ===" at (1,11).
- print "Heading Cmd =" at (1,12).
- until apoapsis > targetApospsis
- {
- if altitude <= turnEnd
- {
- set steerPitch to 90-(((altitude-turnStart)/(turnEnd-turnStart))^turnExponent*(90-finalAngle)).
- }.
- if altitude > turnEnd
- {
- set steerPitch to finalAngle.
- }.
- if verticalSpeed < 10
- {
- set steerPitch to steerPitch+min(-0.5*verticalSpeed,90).
- }.
- set steerHeading to 90. //+ 2*(ship:obt:inclination - targetInclination).
- set steerTo to heading(steerHeading, steerPitch) + R(0,0,steerHeading-180).
- run steerByRaw(steerTo:vector).
- print round(altitude,0) + " " at (15,3).
- print round(alt:apoapsis,0) + " " at (15,5). print round(eta:apoapsis,0) + " " at (31,5).
- print round(alt:periapsis,0) + " " at (15,6).
- print round(velocity:orbit:mag,2) + " " at (15,8).
- print round(ship:obt:inclination,2) + " " at (15,9).
- print round(steerPitch,1) + " " at (15,11).
- print round(steerHeading,1) + " " at (15,12).
- }.
- lock throttle to 0.
- clearscreen.
- print "Desired apoapsis reached " at (8,1).
- set ship:control:neutralize to True.
- lock throttle to 0.
- set oabStart to 0.
- set outOfAtmo to 0.
- set burnTime to 1.
- set mn to node(time:seconds+eta:apoapsis, 0, 0, 10000). add mn.
- print "Altitude ====" at (1,3).
- print "Apoapsis ====" at (1,5). print "ETA =" at (25,5).
- print "Periapsis ===" at (1,6). print "ETA =" at (25,6).
- print "S. Velocity =" at (1,8).
- print "O. Velocity =" at (1,9).
- until periapsis > targetPeriapsis
- {
- print round(altitude,0) + " " at (15,3).
- print round(alt:apoapsis,0) + " " at (15,5). print round(eta:apoapsis,0) + " " at (31,5).
- print round(alt:periapsis,0) + " " at (15,6). print round(eta:periapsis,0) + " " at (31,6).
- print round(velocity:surface:mag,2) + " " at (15,8).
- print round(velocity:orbit:mag,2) + " " at (15,9).
- if (altitude > ship:body:atm:height and outOfAtmo = 0)
- {
- print "Outside atmosphere, plotting OAB " at (8,1).
- lock burnTime to (abs(sqrt(ship:body:mu/(alt:apoapsis+ship:body:radius))-velocity:orbit:mag)/(maxthrust/mass)).
- set mn to node(time:seconds+eta:apoapsis, 0, 0, 10000). add mn.
- if targetPeriapsis-500 > apoapsis-500
- {
- set targetPeriapsis to apoapsis-500.
- }.
- set outOfAtmo to 1.
- }.
- if (oabStart = 0 and eta:apoapsis < burnTime/2)
- {
- lock throttle to 1. print "Orbital insertion burn begin" at (8,1).
- set oabStart to 1.
- }.
- if (apoapsis > targetApospsis*1.1 and periapsis > 70000)
- {
- print "Overshot apoapsis but in orbit " at (8,1).
- lock throttle to 0.
- wait 10.
- break.
- }.
- run steerByRaw(mn:burnVector).
- }.
- clearscreen. remove mn. lock throttle to 0.
- print "Desired orbit achieved".
- print "Apoapsis = "+apoapsis.
- print "Periapsis= "+periapsis. wait 2. print "".
- print "Launch code completed".
Advertisement
Add Comment
Please, Sign In to add comment