Advertisement
Guest User

Untitled

a guest
May 25th, 2015
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. PARAMETER targetAltitude.
  2. PARAMETER targetInclination.
  3.  
  4. set launchLatitude to SHIP:LATITUDE.
  5.  
  6. set targetFacing to Arcsin(Max(-1, Min(1, Cos(targetInclination)/Cos(launchLatitude)))).
  7. lock currentInclination to Ship:Obt:Inclination.
  8.  
  9. set v_orbit to SQRT(BODY:MU / (SHIP:BODY:RADIUS + targetAltitude)).
  10. set v_orbit_x to COS(targetInclination)*v_orbit.
  11.  
  12. set v_equatorial to (2*CONSTANT():PI*SHIP:BODY:RADIUS)/SHIP:BODY:ROTATIONPERIOD.
  13. set v_rot to COS(SHIP:LATITUDE)*v_equatorial.
  14.  
  15. function getHorizontalSpeed {
  16. return cos(currentInclination)*Ship:SurfaceSpeed.
  17. }
  18.  
  19. print "Preparing ascent...".
  20.  
  21. if (v_orbit_x > v_rot) {
  22.  
  23. lock error to targetInclination - currentInclination. // positive [0, ~90]
  24. set maxError to error.
  25. lock transformedError to Log10(error + 1)/Log10(maxError + 1).
  26.  
  27. set maxCorrection to 90-targetInclination. // positive
  28. lock correction to maxCorrection*transformedError. // positive, aproaching zero as error aproaches zero.
  29.  
  30. lock correctedFacing to targetFacing - correction.
  31.  
  32. } else {
  33. // DOESNT WORK
  34.  
  35. set error to targetInclination - currentInclination. // 89
  36. set maxError to error. // 89
  37. lock transformedError to Log10(error + 1)/Log10(maxError + 1). // 1
  38.  
  39. set maxCorrection to 180 - targetInclination. // 91
  40. lock correction to maxCorrection*transformedError.
  41.  
  42. lock correctedFacing to targetFacing - correction.
  43. }
  44.  
  45. print "Throttling...".
  46.  
  47. set THROTTLEBUFFER to 1.
  48. lock THROTTLE to MAX(MIN(THROTTLEBUFFER, 1), 0).
  49.  
  50. set runmode to 1.
  51. until (runmode = 0) {
  52.  
  53. if (runmode = 1) {
  54. lock STEERING to heading(correctedFacing, 90).
  55. set THROTTLEBUFFER to 1.
  56. stage.
  57. set runmode to 2.
  58. }
  59.  
  60. else if (runmode = 2) {
  61. lock STEERING to heading(correctedFacing, 90).
  62.  
  63. if (SHIP:ALTITUDE > 2000) {
  64. set runmode to 3.
  65. }
  66. }
  67.  
  68. else if (runmode = 3) {
  69. lock STEERING to heading(correctedFacing, 90 * (1 - ALT:RADAR / 80000)).
  70. set THROTTLEBUFFER to 0.6.
  71.  
  72. if (SHIP:APOAPSIS > 100000) {
  73. set runmode to 4.
  74. }
  75. }
  76.  
  77. else {
  78. print "Illegal runmode: " + runmode + "! Terminating.".
  79. set runmode to 0.
  80. }
  81.  
  82. clearscreen.
  83. print "Error: " + Round(error, 2) at (5,5).
  84. print "TransformedError: " + Round(transformedError, 2) at (5,6).
  85. print "Correction: " + Round(correction, 2) at (5,7).
  86. print "Corrected: " + Round(correctedFacing, 2) at (5,8).
  87. print "Speed: " + Round(getHorizontalSpeed(), 2) at (5,9).
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement