Guest User

Untitled

a guest
May 26th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.37 KB | None | 0 0
  1.  
  2.  
  3. clearscreen.
  4. set pi to 3.1415926535897932384626433832795028841971693993751058209749445923.
  5. set mu to 3.986*(10^14).
  6. ag1 off.
  7.  
  8. set lateraloffset to 0.
  9. set verticaloffset to 0.
  10. rcs on.
  11. sas off.
  12. gear off.
  13. lock steering to prograde + r(0,0,180).
  14.  
  15. set latint to 0.
  16. set verint to 0.
  17. set maneuverSpeed to .7.
  18.  
  19. function lateraldist {
  20. set uct to vcrs(ship:up:vector,target:position). //up cross target
  21. set ev to vcrs(ship:body:position,ship:north:vector).
  22.  
  23. if vang(uct,ship:north:vector) > 90 {
  24. set thdg to vang(uct,ev).
  25. } else {
  26. set thdg to 360-vang(uct,ev). //heading of the target vector
  27. }.
  28. if thdg > 360 {
  29. set thdg to thdg-360.
  30. }.
  31. set ucv to vcrs(ship:up:vector,ship:velocity:orbit).
  32. if vang(ucv,ship:north:vector) > 90 {
  33. set vhdg to vang(ucv,ev).
  34. } else {
  35. set vhdg to 360-vang(ucv,ev). //heading of the velocity vector
  36. }
  37.  
  38. if vhdg-thdg > 180{
  39. set hdgdiff to vhdg-thdg-360.
  40. }. else {
  41. set hdgdiff to vhdg-thdg.
  42. }.
  43. set latdist to sin(hdgdiff)*target:position:mag.
  44. return latdist.
  45. }.
  46. function verticaldist {
  47. set velangle to vang(ship:velocity:orbit,ship:up:vector).
  48. set targangle to vang(target:position,ship:up:vector).
  49. set pitchdiff to velangle-(targangle-verticaloffset).
  50. set vdist to sin(pitchdiff)*target:position:mag.
  51. return vdist.
  52. }.
  53. function depthdist {
  54. set targpos to (target:position+ship:body:position).
  55. set ang to vang(targpos,ship:body:position)*pi/180.
  56. set ddist to ang*ship:body:position:mag.
  57. return ddist.
  58. }
  59. function lateralinputFunction {
  60. if abs(lateraldistance2) > 10 {
  61. set vlat to (lateralDistance2-lateralDistance1)/(dt).
  62. if lateralDistance2 > 0 {
  63. set ms to -maneuverSpeed.
  64. }. else {
  65. set ms to maneuverSpeed.
  66. }
  67. set vlatError to ms-vlat.
  68. set latinput to kpv*vlatError.
  69. }. else {
  70. set slatError to lateralDistance2.
  71. set vlat to (lateralDistance2-lateralDistance1)/(dt).
  72. set latinput to -((kps*lateralDistance2)+(kds*vlat)+(kis*latint)).
  73. }.
  74. return latinput.
  75. }
  76. function verticalinputFunction {
  77. if abs(verticalDistance2+extraH) > 10 {
  78. set vver to (verticalDistance2-verticalDistance1)/(dt).
  79. if verticaldistance2+extraH > 0 {
  80. set ms to -maneuverSpeed.
  81. }. else {
  82. set ms to maneuverSpeed.
  83. }
  84. set vverError to ms-vver.
  85. set vertinput to kpv*vverError.
  86. ///////////////////////////////////////////
  87. }. else {
  88. set sverError to (verticaldistance2+extraH).
  89. set vver to (verticalDistance2-verticalDistance1)/(dt).
  90. set vertinput to -((kps*sverError)+(kds*vver)+(verint*kis)).
  91. }.
  92. return vertinput.
  93. }.
  94. function depthinputFunction {
  95. if abs(depthDistance2-depthoffset) > 10 {
  96. set vdep to (depthDistance2-depthDistance1)/(dt).
  97. if depthdistance2-depthoffset > 0 {
  98. set ms to -maneuverSpeed.
  99. }. else {
  100. set ms to maneuverSpeed.
  101. }
  102. set vdepError to ms-vdep.
  103. set depinput to -kpv*vdepError.
  104. ///////////////////////////////////////////
  105. }. else {
  106. set sdepError to depthdistance2-depthoffset.
  107. set vdep to ((depthDistance2)-(depthDistance1))/(dt).
  108. set depinput to ((kps*sdepError)+(kds*vdep)).
  109. }.
  110. return depinput.
  111. }
  112.  
  113. set kpv to 1.
  114. set kps to .3.
  115. set kds to 1.7.
  116. set kis to 0.01.
  117.  
  118. set latinput to 0.
  119. set verticalinput to 0.
  120. set depthinput to 0.
  121. set extraH to 0.
  122. set vver to 0.
  123.  
  124. set depthoffset to target:position:mag.
  125.  
  126. //Approaching for docking
  127.  
  128. until ag1 {
  129. if 2 > 1 {
  130. set lateralDistance1 to lateraldist().
  131. set verticalDistance1 to verticaldist().
  132. set depthDistance1 to target:position:mag.
  133. set t1 to time:seconds.
  134. print "Lateral Difference "+round(lateralDistance1)+" m".
  135. print "Vertical Difference "+round(verticalDistance1)+" m".
  136. print "Depth Difference "+round(depthDistance1)+" m".
  137. print " ".
  138. print "Lateral Input "+round(100*latinput).
  139. print "Vertical Input "+round(100*verticalinput).
  140. print "Depth Input "+round(100*depthinput).
  141. print " ".
  142. print "Depth Offset "+round(depthoffset)+" m".
  143. wait 0.2.
  144. clearscreen.
  145. set lateralDistance2 to lateraldist().
  146. set verticalDistance2 to verticaldist().
  147. set depthDistance2 to target:position:mag.
  148. set t2 to time:seconds.
  149. set dt to t2-t1.
  150. }. //this is just so i can hide it easily
  151. ////////////////////////////////////////////
  152. set lateralinput to lateralinputFunction().
  153. set verticalinput to verticalinputfunction().
  154. set depthinput to depthinputfunction().
  155. ///////////////////////////////////////////
  156. set ship:control:starboard to lateralinput.
  157. set ship:control:top to verticalinput.
  158. set ship:control:fore to depthinput.
  159. }.
  160. ag1 off.
  161.  
  162. clearscreen.
  163. print "Go for docking".
  164.  
  165. set depthoffset to 0.
  166. set t0 to time:seconds.
  167. set latint to 0.
  168. set verint to 0.
  169.  
  170. until hastarget = false {
  171. if hastarget = true {
  172. set lateralDistance1 to lateraldist().
  173. set verticalDistance1 to verticaldist().
  174. set depthDistance1 to target:position:mag.
  175. set t1 to time:seconds.
  176. print "Go for Docking".
  177. print " ".
  178. print "Lateral Difference "+lateralDistance1+" m".
  179. print "Vertical Difference "+verticalDistance1+" m".
  180. print "Depth Difference "+round(depthDistance1)+" m".
  181. print " ".
  182. print "Lateral Input "+round(100*latinput).
  183. print "Vertical Input "+round(100*verticalinput).
  184. print "Depth Input "+round(100*depthinput).
  185. print " ".
  186. print "Depth Offset "+round(depthoffset)+" m".
  187. wait 0.2.
  188. clearscreen.
  189. if hastarget = true {
  190. set lateralDistance2 to lateraldist().
  191. set verticalDistance2 to verticaldist().
  192. set depthDistance2 to target:position:mag.
  193. set t2 to time:seconds.
  194. set dt to t2-t1.
  195. }.
  196. }. //this is just so i can hide it easily
  197. ////////////////////////////////////////////
  198. //giving the integral gain something to multiply
  199. set latint to (((lateraldistance2+lateraldistance1)/2)*dt)+latint.
  200. set verint to (((verticaldistance2+verticaldistance1)/2)*dt)+verint.
  201.  
  202. set lateralinput to lateralinputFunction().
  203. set verticalinput to verticalinputfunction().
  204. set depthinput to depthinputfunction().
  205. ///////////////////////////////////////////
  206.  
  207. set ship:control:starboard to lateralinput.
  208. set ship:control:top to verticalinput.
  209. set ship:control:fore to depthinput.
  210. if depthdistance2 < 20 {
  211. set maneuverspeed to 0.3.
  212. }.
  213. }.
  214. clearscreen.
  215. set ship:control:neutralize to true.
  216. print " ".
  217. print "Docked!".
  218. print " ".
Add Comment
Please, Sign In to add comment