Advertisement
hubin162577

FalconLaunch

Oct 21st, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clearscreen.
  2. set pi to 3.1415926535897932384626433832795028841971693993751058209749445923.
  3. set mu to 3.986*(10^14).
  4. ag1 off.
  5.  
  6. function launchHeading {
  7. set azimuth to arcsin(cos(target:orbit:inclination)/cos(ship:latitude)).
  8. return azimuth.
  9. }
  10. function orbitHeading {
  11. set azimuth to arcsin(cos(ship:orbit:inclination)/cos(ship:latitude)).
  12. return azimuth.
  13. }
  14. function pitchAngle {
  15. set ang to 90-(vang(ship:velocity:surface,ship:up:vector)).
  16. return ang.
  17. } //for ascent
  18. function relativeInclination {
  19. set targpos to target:position-ship:body:position.
  20. set htarg to vcrs(targpos,target:velocity:orbit).
  21. set hship to -vcrs(ship:body:position,ship:velocity:orbit).
  22. set relinc to vang(htarg,hship).
  23. return relinc.
  24. }
  25. function distancefromPlane {
  26. set targpos to target:position-ship:body:position.
  27. set htarg to vcrs(targpos,target:velocity:orbit).
  28. set hship to vcrs(ship:body:position,ship:velocity:orbit).
  29. set relinc to vang(htarg,hship).
  30. set descendingNode to vcrs(htarg,hship).
  31. set ang to (pi/180)*vang(descendingNode,ship:body:position).
  32. set hypoteneuse to ang*ship:body:position:mag.
  33. set dist to sin(relinc)*hypoteneuse.
  34. return dist.
  35. }
  36. function pitchUp { //for space
  37. set r to ship:body:position:mag.
  38. set v to ship:velocity:orbit:mag.
  39. set ag to (mu/(r^2))-((v^2)/r)+alevel.
  40. set hypoteneuseAcc to ship:maxthrust/ship:mass.
  41. set theta to arcsin(ag/hypoteneuseAcc).
  42. return theta.
  43. }
  44.  
  45. set gturnAngle to 3.
  46. set gturnVelocity to 42.
  47. set doglegAcc to 2.
  48. set apheight to 220000.
  49. set periap to apheight-10000.
  50. set kpPitch to 1.
  51. set kiPitch to 0.1.
  52.  
  53. lock steering to heading(launchHeading(),90)+r(0,0,180).
  54. print "Liftoff!".
  55. lock throttle to 1.
  56. stage.
  57. set t0 to time:seconds.
  58.  
  59. wait until ship:verticalspeed > gturnVelocity.
  60.  
  61. lock steering to heading(launchHeading(),90-gturnAngle)+r(0,0,180).
  62. print "T+"+round(time:seconds-t0)+" Seconds. Beginning Roll Program".
  63.  
  64. wait until vang(ship:velocity:surface,ship:up:vector)>gturnAngle.
  65. print "T+"+round(time:seconds-t0)+" Seconds. Roll Program Complete".
  66.  
  67. lock steering to heading(launchHeading(),pitchAngle())+r(0,0,180).
  68.  
  69. //staging
  70. wait until (time:seconds-t0)>154.
  71. lock throttle to 0.
  72. print "T+"+round(time:seconds-t0)+" Seconds. MECO".
  73. wait until (time:seconds-t0)>158.
  74. print "T+"+round(time:seconds-t0)+" Seconds. First Stage Separation. RCS on".
  75.  
  76. stage.
  77. rcs on.
  78. lock throttle to 1.
  79. wait until (time:seconds-t0)>161.
  80. print "T+"+round(time:seconds-t0)+" Seconds. Second Stage Ignition".
  81. stage.
  82.  
  83.  
  84. set newPitch to pitchAngle().
  85. until ship:apoapsis > apheight {
  86. lock steering to heading(orbitHeading(),newPitch)+r(0,0,180).
  87. wait 0.1.
  88. }
  89.  
  90. set a to 0.
  91. until a > doglegAcc {
  92. lock steering to heading(orbitHeading(),0)+r(0,0,180).
  93. set v to (sin(relativeInclination())*ship:velocity:orbit:mag).
  94. set x to distancefromPlane().
  95. set a to (1/(2*x))*(v^2).
  96. wait 0.1.
  97. }
  98.  
  99.  
  100. print "T+"+round(time:seconds-t0)+" Seconds. Beginning Dogleg Maneuver".
  101. set upAngle to 0.
  102. set alevel to 0.
  103. until alevel > 1 and ship:verticalspeed < 0 {
  104. set relativeInc to relativeInclination().
  105. if relativeInc > 0.05 {
  106. set v to (sin(relativeInc)*ship:velocity:orbit:mag).
  107. set x to distancefromPlane().
  108. set a to ((1/(2*x))*(v^2)).
  109. set thrustacc to (ship:maxthrust/ship:mass)*cos(upAngle).
  110. set offsetAngle to arcsin(a/thrustacc).
  111. }. else {
  112. set offsetAngle to 0.
  113. }.
  114. set vlevel to ship:verticalspeed.
  115. set hdiff to ship:altitude-periap.
  116. set alevel to (1/(2*hdiff))*(vlevel^2).
  117.  
  118.  
  119.  
  120. lock steering to heading(orbitHeading()-offsetAngle,upAngle)+r(0,0,180).
  121. }
  122. print "T+"+round(time:seconds-t0)+" Seconds. Leveling off at 210 km".
  123. until ship:verticalspeed > -0.5 {
  124. set relativeInc to relativeInclination().
  125. if relativeInc > 0.05 {
  126. set v to (sin(relativeInc)*ship:velocity:orbit:mag).
  127. set x to distancefromPlane().
  128. set a to ((1/(2*x))*(v^2))+1.
  129. set thrustacc to (ship:maxthrust/ship:mass)*cos(upAngle).
  130. set offsetAngle to arcsin(a/thrustacc).
  131. }. else {
  132. set offsetAngle to 0.
  133. }.
  134.  
  135. set vlevel to ship:verticalspeed.
  136. set hdiff to ship:altitude-periap.
  137. set alevel to (1/(2*hdiff))*(vlevel^2).
  138.  
  139. set upAngle to pitchUp().
  140. lock steering to heading(orbitHeading()-offsetAngle,upAngle)+r(0,0,180).
  141. }
  142.  
  143. set alevel to 0.
  144. set vsInt to 0.
  145. until ship:periapsis > 0 {
  146. set relativeInc to relativeInclination().
  147. if relativeInc > 0.05{
  148. set v to (sin(relativeInc)*ship:velocity:orbit:mag).
  149. set x to distancefromPlane().
  150. set a to ((1/(2*x))*(v^2))+1.
  151. set thrustacc to (ship:maxthrust/ship:mass)*cos(upAngle).
  152. set offsetAngle to arcsin(a/thrustacc)..
  153. }. else {
  154. set offsetAngle to 0.
  155. }.
  156.  
  157. set vs1 to ship:verticalspeed.
  158. set t1 to time:seconds.
  159. wait 0.1.
  160. set vs2 to ship:verticalspeed.
  161. set t2 to time:seconds.
  162. set dt to t2-t1.
  163.  
  164. set vsInt to vsInt+(dt*(vs2+vs1)/2).
  165.  
  166. set anglediff to (-kpPitch*(ship:verticalspeed))+(-kiPitch*vsInt).
  167. set upAngle to pitchUp()+anglediff.
  168. lock steering to heading(orbitHeading()-offsetAngle,upAngle)+r(0,0,180).
  169. }
  170.  
  171. lock steering to prograde +r(0,0,180).
  172. ag2 on.
  173. wait until ship:apoapsis > 390000.
  174. lock throttle to 0.
  175. print "T+"+round(time:seconds-t0)+" Seconds. SECO".
  176. wait 10.
  177. stage.
  178. print "T+"+round(time:seconds-t0)+" Seconds. Spacecraft Separation".
  179. print "Remember to engage persistent rotation".
  180. set ship:control:fore to 1.
  181. lock steering to prograde +r(0,0,180).
  182.  
  183. wait until ship:apoapsis>400000.
  184.  
  185. set ship:control:neutralize to true.
  186. run rendezvous.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement