Advertisement
wirawafiy1

Untitled

Oct 19th, 2023
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. // This script will launch a rocket into a circular orbit around Kerbin
  2. // It assumes the rocket has at least two stages and a fairing
  3. // It also assumes the rocket has the following mods installed:
  4. // KRPC, KOS, KOS-StockCamera, KOS-Scansat, KOS-EVA, KOS-Career, QuickStart
  5.  
  6. // Set the desired apoapsis and inclination of the orbit
  7. set target_apo to 200000. // in meters
  8. set target_inc to 0. // in degrees
  9.  
  10. // Set the launch time (optional)
  11. set launch_time to "10:00:00". // in 00:00:05 format
  12.  
  13. // Set the maximum thrust-to-weight ratio (optional)
  14. set max_twr to 1.5.
  15.  
  16. // Initialize some variables
  17. set stage_number to stage:number.
  18. set stage_liquidfuel to stage:liquidfuel.
  19. set throttle to 1.
  20. set steering to 90.
  21.  
  22. // Wait for the launch time (optional)
  23. if launch_time <> "" {
  24. print "Waiting for launch time: " + launch_time.
  25. wait until time:seconds = time:seconds(launch_time).
  26. }
  27.  
  28. // Activate the first stage and lock the steering to east
  29. print "Liftoff!".
  30. stage.
  31. lock steering to heading(steering, 90).
  32.  
  33. // Main ascent loop
  34. until apoapsis > target_apo or stage_number = 0 {
  35.  
  36. // Throttle down if twr is too high
  37. if ship:maxthrust / ship:mass > max_twr {
  38. set throttle to max_twr * ship:mass / ship:maxthrust.
  39. }
  40.  
  41. // Throttle up if twr is too low
  42. if ship:maxthrust / ship:mass < max_twr * 0.9 {
  43. set throttle to 1.
  44. }
  45.  
  46. // Stage when out of liquid fuel
  47. if stage_liquidfuel = 0 {
  48. print "Staging.".
  49. stage.
  50. set stage_number to stage:number.
  51. set stage_liquidfuel to stage:liquidfuel.
  52. }
  53.  
  54. // Jettison fairing when above 70 km
  55. if altitude > 70000 and ship:fairing {
  56. print "Jettisoning fairing.".
  57. ship:fairing:jettison().
  58. }
  59.  
  60. // Adjust steering based on altitude and velocity
  61. if altitude < 10000 {
  62. // Stay vertical until 10 km
  63. set steering to 90.
  64. } else if altitude < 40000 {
  65. // Gradually pitch down until 40 km
  66. set steering to 90 - (altitude - 10000) / 1000.
  67. } else {
  68. // Follow prograde until apoapsis
  69. set steering to velocity:orbit.
  70. }
  71.  
  72. // Lock steering to the desired direction
  73. lock steering to heading(steering, 90 - target_inc * sin(longitude)).
  74. }
  75.  
  76. // Cut off engines and coast to apoapsis
  77. print "Coasting to apoapsis.".
  78. set throttle to 0.
  79.  
  80. // Circularize at apoapsis
  81. print "Circularizing.".
  82. lock steering to prograde.
  83. wait until eta:apoapsis < 30.
  84. set throttle to 1.
  85. wait until periapsis > target_apo - 1000.
  86. set throttle to 0.
  87.  
  88. // Print orbital parameters and end the script
  89. print "Orbit achieved.".
  90. print "Apoapsis: " + round(apoapsis) + " m.".
  91. print "Periapsis: " + round(periapsis) + " m.".
  92. print "Inclination: " + round(inclination) + " deg.".
  93. print "End of script.".
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement