Advertisement
Guest User

Untitled

a guest
May 28th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. //hellolaunch
  2.  
  3. //First, we'll clear the terminal screen to make it look nice
  4. CLEARSCREEN.
  5.  
  6. if ADDONS:TR:AVAILABLE {
  7. if ADDONS:TR:HASIMPACT {
  8. PRINT ADDONS:TR:IMPACTPOS.
  9. } else {
  10. PRINT "Impact position is not available".
  11. }
  12. } else {
  13. PRINT "Trajectories is not available.".
  14. }
  15.  
  16. SET TR1 TO LATLNG(5.360278, -52.951944).
  17. PRINT TR1:DISTANCE / 1000. // Print distance from vessel to x
  18. PRINT TR1:HEADING. // Print the heading to the point
  19. PRINT TR1:BEARING.
  20.  
  21. WAIT 0.5.
  22.  
  23. //Next, we'll lock our throttle to 100%.
  24. LOCK THROTTLE TO 1.0. // 1.0 is the max, 0.0 is idle.
  25.  
  26.  
  27.  
  28. SET MYSTEER TO HEADING(90,90). //90 degrees east and pitched up 90 degrees (straight up)
  29. LOCK STEERING TO MYSTEER. // from now on we'll be able to change steering by just assigning a new value to MYSTEER
  30.  
  31. STAGE.
  32. WAIT 0.5.
  33. UNTIL SHIP:VERTICALSPEED > 140
  34.  
  35.  
  36. {SET MYSTEER TO HEADING(90,90).}
  37.  
  38. set imptrghdg to 0.
  39.  
  40. SET Kp TO 0.01.
  41. SET Ki TO 0.006.
  42. SET Kd TO 0.006.
  43. SET PID TO PIDLOOP(Kp, Ki, Kd).
  44. SET PID:SETPOINT TO 0.
  45.  
  46. // setting pitch and yaw to an aproximate heading and a designated pitch until 20km
  47. UNTIL SHIP:ALTITUDE > 20000 {
  48. SET MYSTEER TO HEADING(TR1:HEADING - PID:UPDATE(TIME:SECONDS, tr1:bearing),60). //ship:srfprograde:pitch
  49. // Print the heading to the point
  50. PRINT TR1:BEARING.
  51. // pid:update() is given the input time and input and returns the output. gforce is the input.
  52. WAIT 0.3.
  53. }
  54.  
  55. // loop with PID to maintain heading that is parallel to the heading from the estimated impact location to the target
  56. UNTIL SHIP:ALTITUDE > 400000 {
  57. set deltaLong to (tr1:LNG - ADDONS:TR:IMPACTPOS:LNG).
  58.  
  59. // calculating heading from predicted impact location to the target
  60. set imptrghdg to arctan2(sin(deltaLong) * cos(tr1:lat), cos(ADDONS:TR:IMPACTPOS:lat) * sin(tr1:lat) - sin(ADDONS:TR:IMPACTPOS:lat) * cos(tr1:lat) * cos(deltaLong)).
  61.  
  62. //calcuating the difference between heading from ship to target and heading from impact to target
  63. SET DIFFDIR TO (tr1:HEADING - imptrghdg).
  64.  
  65.  
  66. //PID loop to lower the difference above to zero
  67. SET MYSTEER TO HEADING((142 - PID:UPDATE(TIME:SECONDS, DIFFDIR)),45). //ship:srfprograde:pitch
  68. // Print the heading to the point
  69. //PRINT TR1:BEARING.
  70.  
  71.  
  72. //printing values to monitor during flight
  73. PRINT "AAAAAA".
  74. print tr1:heading.
  75.  
  76.  
  77.  
  78.  
  79. print imptrghdg.
  80. PRINT (DIFFDIR).
  81.  
  82. //PRINT ADDONS:TR:IMPACTPOS.
  83. // pid:update() is given the input time and input and returns the output. gforce is the input.
  84. WAIT 0.01.
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. WAIT UNTIL SHIP:ALTITUDE > 70000.
  94.  
  95. // NOTE that it is vital to not just let the script end right away
  96. // here. Once a kOS script just ends, it releases all the controls
  97. // back to manual piloting so that you can fly the ship by hand again.
  98. // If the program just ended here, then that would cause the throttle
  99. // to turn back off again right away and nothing would happen.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement