Advertisement
Guest User

Adaptive Launch Script for kOS

a guest
Jun 1st, 2016
1,577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Adaptive Launch Script for Kerbal Operating System
  2. //By /u/supreme_blorgon
  3. //
  4. //To run, type into terminal " run als(<target orbit height>). ",
  5. //replace everything between and including <> with your desired
  6. //orbit height in METERS (e.g.: 150000). This script will automatically
  7. //determine the throttle control based on the number you pass into the program.
  8. //
  9. //Once the spacecraft is out of the atmosphere, the script
  10. //will automatically trigger action group 1. I've set all my
  11. //rockets up to either deploy their fairings or jettison
  12. //their escape towers on AG1. You will need to change that line if you
  13. //don't want to use it.
  14. //
  15. //Please give credit when using or modifying!
  16. //
  17. //kOS was originally created by Nivekk. It is under active development by
  18. //the kOS Team and is licensed under terms of GNU General Public License
  19. //Version 3, 29 June 2007, Copyright © 2007 Free Software Foundation, Inc.
  20. //
  21. parameter orbitheight.
  22. when stage:solidfuel < 0.1 then {
  23.     stage.
  24. }
  25. when stage:liquidfuel < 0.1 then {
  26.     stage.
  27.     return true.
  28. }
  29. set gain to 1/-(orbitHeight+1)^2.
  30. lock steering to r(0,0,0)*up.
  31. lock throttle to 1.
  32. stage.
  33. set twr to ship:maxthrustat(ship:sensors:pres / 100) / ship:mass * ship:sensors:grav:mag.
  34. set tgain to 0.1 - (0.1005 / twr).
  35. wait until ship:altitude > 147.
  36. until ship:altitude >= 53000 {
  37.     set salt to ship:altitude.
  38.     set tta to eta:apoapsis.
  39.     set pitch to -sqrt(0.170283 * salt) + 5.
  40.     set teta to (-1 * pitch) + tgain * (pitch + 90).
  41.     if pitch < -90 {
  42.         set pitch to -90.
  43.     }
  44.     lock steering to r(0,pitch,0)*up.
  45.     set tmoid to -1/(1+5^(teta - tta))+1.
  46.     lock throttle to tmoid.
  47.     if ship:apoapsis > orbitHeight - (orbitHeight*0.1) {
  48.         lock throttle to 0.
  49.         break.
  50.     }
  51. }
  52. lock steering to r(0,-90,0)*up.
  53. until ship:apoapsis > orbitHeight - (orbitHeight*0.1) {
  54.     lock throttle to 0.25.
  55. }
  56. lock throttle to 0.
  57. wait until ship:altitude >= 70000.
  58. toggle AG1.
  59. rcs on.
  60. until ship:apoapsis >= orbitHeight {
  61.     set apo to ship:apoapsis.
  62.     set pthrot to gain*apo^2+1.
  63.     if pthrot < 0   {
  64.             lock throttle to 0.
  65.         }
  66.     if pthrot < 0.005   {
  67.             lock throttle to 0.005.
  68.         }
  69.     else {
  70.             lock throttle to pthrot.
  71.         }
  72. }
  73. lock throttle to 0.
  74. until ship:periapsis / ship:apoapsis > 0.9999 {
  75.     set tta to -1 * eta:apoapsis.
  76.     set pthrot to -1/(1+5^(tta+3))+1.
  77.     lock throttle to pthrot.
  78. }
  79. lock throttle to 0.
  80. print "Program Ended.".
  81. wait until false.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement