Guest User

Untitled

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