Guest User

MAV_ascent.ks

a guest
Apr 7th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. // Trajectory program variables
  2. set turnStart to 500.
  3. set turnEnd to 70000.
  4. set turnExponent to 0.5.
  5. set finalAngle to 3.
  6. set targetInclination to 20.
  7. set targetApospsis to 200000.
  8. set targetPeriapsis to 200000.
  9. // End trajectory program variables
  10. // Steering controller PID values
  11. set pitchP to 0.04.
  12. set pitchD to 0.2.
  13. set yawP to 0.04.
  14. set yawD to 0.2.
  15. set rollD to 0.2.
  16. // End steering controller PID values
  17. clearscreen.
  18. if stage:number <> 1
  19. {
  20. print "Prestaging sequence not complete.".
  21. print "Vessel must be ready to activate last stage.".
  22. wait until False.
  23. }.
  24. print "3". wait 1.
  25. print "2". wait 1.
  26. rcs on. sas on. print "Vernor engines activated".
  27. print "1". wait 1.
  28. stage.
  29. lock throttle to 1. print "Liftoff!". wait 1.
  30. clearscreen.
  31. print "Vertical flight phase in progress" at (8,1).
  32. wait until alt:radar > turnStart.
  33. sas off.
  34. print "Launch trajectory program active " at (8,1).
  35. print "Altitude ====" at (1,3).
  36. print "Apoapsis ====" at (1,5). print "ETA =" at (25,5).
  37. print "Periapsis ===" at (1,6).
  38. print "O. Velocity =" at (1,8).
  39. print "Inclination =" at (1,9).
  40. print "Pitch Cmd ===" at (1,11).
  41. print "Heading Cmd =" at (1,12).
  42. until apoapsis > targetApospsis
  43. {
  44. if altitude <= turnEnd
  45. {
  46. set steerPitch to 90-(((altitude-turnStart)/(turnEnd-turnStart))^turnExponent*(90-finalAngle)).
  47. }.
  48. if altitude > turnEnd
  49. {
  50. set steerPitch to finalAngle.
  51. }.
  52. if verticalSpeed < 10
  53. {
  54. set steerPitch to steerPitch+min(-0.5*verticalSpeed,90).
  55. }.
  56. set steerHeading to 90. //+ 2*(ship:obt:inclination - targetInclination).
  57. set steerTo to heading(steerHeading, steerPitch) + R(0,0,steerHeading-180).
  58. run steerByRaw(steerTo:vector).
  59. print round(altitude,0) + " " at (15,3).
  60. print round(alt:apoapsis,0) + " " at (15,5). print round(eta:apoapsis,0) + " " at (31,5).
  61. print round(alt:periapsis,0) + " " at (15,6).
  62. print round(velocity:orbit:mag,2) + " " at (15,8).
  63. print round(ship:obt:inclination,2) + " " at (15,9).
  64. print round(steerPitch,1) + " " at (15,11).
  65. print round(steerHeading,1) + " " at (15,12).
  66. }.
  67. lock throttle to 0.
  68. clearscreen.
  69. print "Desired apoapsis reached " at (8,1).
  70. set ship:control:neutralize to True.
  71. lock throttle to 0.
  72. set oabStart to 0.
  73. set outOfAtmo to 0.
  74. set burnTime to 1.
  75. set mn to node(time:seconds+eta:apoapsis, 0, 0, 10000). add mn.
  76. print "Altitude ====" at (1,3).
  77. print "Apoapsis ====" at (1,5). print "ETA =" at (25,5).
  78. print "Periapsis ===" at (1,6). print "ETA =" at (25,6).
  79. print "S. Velocity =" at (1,8).
  80. print "O. Velocity =" at (1,9).
  81. until periapsis > targetPeriapsis
  82. {
  83. print round(altitude,0) + " " at (15,3).
  84. print round(alt:apoapsis,0) + " " at (15,5). print round(eta:apoapsis,0) + " " at (31,5).
  85. print round(alt:periapsis,0) + " " at (15,6). print round(eta:periapsis,0) + " " at (31,6).
  86. print round(velocity:surface:mag,2) + " " at (15,8).
  87. print round(velocity:orbit:mag,2) + " " at (15,9).
  88. if (altitude > ship:body:atm:height and outOfAtmo = 0)
  89. {
  90. print "Outside atmosphere, plotting OAB " at (8,1).
  91. lock burnTime to (abs(sqrt(ship:body:mu/(alt:apoapsis+ship:body:radius))-velocity:orbit:mag)/(maxthrust/mass)).
  92. set mn to node(time:seconds+eta:apoapsis, 0, 0, 10000). add mn.
  93. if targetPeriapsis-500 > apoapsis-500
  94. {
  95. set targetPeriapsis to apoapsis-500.
  96. }.
  97. set outOfAtmo to 1.
  98. }.
  99. if (oabStart = 0 and eta:apoapsis < burnTime/2)
  100. {
  101. lock throttle to 1. print "Orbital insertion burn begin" at (8,1).
  102. set oabStart to 1.
  103. }.
  104. if (apoapsis > targetApospsis*1.1 and periapsis > 70000)
  105. {
  106. print "Overshot apoapsis but in orbit " at (8,1).
  107. lock throttle to 0.
  108. wait 10.
  109. break.
  110. }.
  111. run steerByRaw(mn:burnVector).
  112. }.
  113. clearscreen. remove mn. lock throttle to 0.
  114. print "Desired orbit achieved".
  115. print "Apoapsis = "+apoapsis.
  116. print "Periapsis= "+periapsis. wait 2. print "".
  117. print "Launch code completed".
Advertisement
Add Comment
Please, Sign In to add comment