Advertisement
Guest User

Untitled

a guest
Apr 17th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.58 KB | None | 0 0
  1.  
  2. clearscreen.
  3. set mu to 3.986e14.
  4. set g to 9.81.
  5. set pi to 3.1415926535897932384626433832795028841971693993751058209749445923.
  6. set transThrust to .26. //.530 for 3 clowns
  7. set foreThrust to .52. //1.06 for 3 clowns
  8. set bodyRadius to 6371000.
  9. lights on.
  10.  
  11.  
  12.  
  13. function relativeInclination {
  14. set targpos to target:position-ship:body:position.
  15. set htarg to vcrs(targpos,target:velocity:orbit).
  16. set hship to -vcrs(ship:body:position,ship:velocity:orbit).
  17. set relinc to vang(htarg,hship).
  18. return relinc.
  19. }
  20.  
  21. function vectorheading {
  22. parameter vector.
  23. set northvec to ship:north:vector.
  24. set westvec to vcrs(northvec,ship:up:vector).
  25. set vcrossup to vcrs(vector,ship:up:vector).
  26. if vang(vcrossup,northvec) > 90 {
  27. set hdg to -vang(vcrossup,westvec).
  28. } else {
  29. set hdg to vang(vcrossup,westvec).
  30. }
  31. return hdg.
  32. }
  33.  
  34. function targetDistance {
  35. set td to target:position:mag.//(TARGET:ROOTPART:POSITION - SHIP:ROOTPART:POSITION):MAG
  36. return td.
  37. }
  38.  
  39. function lateralDistance {
  40. parameter sv.
  41. parameter tp.
  42. set theta to (pi/180)*(sv-tp).
  43. set ld to theta*target:position:mag.
  44. return ld.
  45. }
  46. function verticalDistance {
  47. set theta to (pi/180)*(vang(target:position,(-1*ship:up:vector))-90).
  48. set ld to -theta*target:position:mag.
  49. return ld.
  50. }
  51.  
  52. sas off.
  53. rcs on.
  54. lock steering to prograde + r(0,0,180).
  55.  
  56. set transVelocity to .5.
  57. set kpv to -5. set kps to 1.5.
  58. set kd to 5.
  59. set dLat to 50.
  60. set dVer to 50.
  61. set dTar to 50.
  62. set Vinput to 0. set Tinput to 0. set Linput to 0.
  63. ag6 off.
  64.  
  65. until ag6 { //stationkeeping loop around 8km from station
  66. set svh to vectorheading(ship:velocity:orbit). //chaser velocity heading
  67. set tph to vectorheading(target:position). //target position heading
  68. set latdist1 to lateralDistance(svh,tph).
  69. set verdist1 to verticalDistance().
  70. set t1 to time:seconds.
  71. set tardistActual to targetDistance().
  72. set tardist1 to targetDistance()-100.
  73. wait 0.1.
  74.  
  75. clearscreen.
  76. print "Approaching Station".
  77. print "Press 6 to continue with docking".
  78. print " ".
  79. print "Station Distance is "+round(tardistActual)+" m".
  80. print "Warning, Station Distance number may be incorrect".
  81. print " ".
  82. print "Lateral Distance is "+(round(1000*latdist1)/1000)+" m".
  83. print "Vertical Distance is "+(round(1000*verdist1)/1000)+" m".
  84. print " ".
  85. Print "Vertical Control Input: "+(round(100*Vinput)/100).
  86. print "Lateral Control Input: "+(round(100*Linput)/100).
  87. print "Foreward Control Input: "+(round(100*Tinput)/100).
  88. print " ".
  89. print "Vertical Velocity: "+(round(1000000*dVer)/1000)+" mm/s".
  90. print "Lateral Velocity: "+(round(1000000*dLat)/1000)+" mm/s".
  91. print "Foreward Velocity: "+(-round(1000000*dtar)/1000)+" mm/s".
  92.  
  93.  
  94. set svh to vectorheading(ship:velocity:orbit). //chaser velocity heading
  95. set tph to vectorheading(target:position). //target position heading
  96. set latdist2 to lateralDistance(svh,tph).
  97. set verdist2 to verticalDistance().
  98. set tardist2 to targetDistance()-100.
  99.  
  100. set t2 to time:seconds.
  101. set dLat to (latdist2-latdist1)/(t2-t1).
  102. set dVer to (verdist2-verdist1)/(t2-t1).
  103. set dtar to (tardist2-tardist1)/(t2-t1).
  104.  
  105.  
  106. if abs(latdist2) > 125 {
  107. set lateralVsetpoint to -4*transVelocity*latdist2/abs(latdist2).
  108. set Linput to (lateralVsetpoint-dLat)*kpv.
  109. } else if abs(latdist2) > 50 {
  110. set lateralVsetpoint to -2*transVelocity*latdist2/abs(latdist2).
  111. set Linput to (lateralVsetpoint-dLat)*kpv.
  112. } else if abs(latdist2) > 10 {
  113. set lateralVsetpoint to -transVelocity*latdist2/abs(latdist2).
  114. set Linput to (lateralVsetpoint-dLat)*kpv.
  115. } else if abs(latdist2) > 5 {
  116. set lateralVsetpoint to -0.5*transVelocity*latdist2/abs(latdist2).
  117. set Linput to (lateralVsetpoint-dLat)*kpv.
  118. } else {
  119. set Linput to (kps*latdist2)+(kd*dLat).
  120. }
  121.  
  122. if abs(verdist2) > 125 {
  123. set verticalVsetpoint to -4*transVelocity*verdist2/abs(verdist2).
  124. set Vinput to (verticalVsetpoint-dVer)*kpv.
  125. } else if abs(verdist2) > 50 {
  126. set verticalVsetpoint to -2*transVelocity*verdist2/abs(verdist2).
  127. set Vinput to (verticalVsetpoint-dVer)*kpv.
  128. } else if abs(verdist2)>10 {
  129. set verticalVsetpoint to -transVelocity*verdist2/abs(verdist2).
  130. set Vinput to (verticalVsetpoint-dVer)*kpv.
  131. } else if abs(verdist2) > 5 {
  132. set verticalVsetpoint to -0.5*transVelocity*verdist2/abs(verdist2).
  133. set Vinput to (verticalVsetpoint-dVer)*kpv.
  134. } else {
  135. set Vinput to (kps*verdist2)+(kd*dVer).
  136. }
  137.  
  138. if abs(tardist2) > 125 {
  139. set targetVsetpoint to -4*transVelocity.
  140. set Tinput to (targetVsetpoint-dtar)*kpv.
  141. } else if abs(tardist2) > 50 {
  142. set targetVsetpoint to -2*transVelocity.
  143. set Tinput to (targetVsetpoint-dTar)*kpv.
  144. } else if abs(tardist2)>10 {
  145. set targetVsetpoint to -transVelocity.
  146. set Tinput to (targetVsetpoint-dTar)*kpv.
  147. } else if abs(tardist2) > 5 {
  148. set targetVsetpoint to -0.5*transVelocity.
  149. set Tinput to (targetVsetpoint-dTar)*kpv.
  150. } else {
  151. set Tinput to (kps*tardist2)+(kd*dTar).
  152. }
  153.  
  154. set ship:control:fore to Tinput.
  155. set ship:control:starboard to Linput.
  156. set ship:control:top to Vinput.
  157.  
  158. }
  159.  
  160. ag6 off.
  161.  
  162. set ILat to 0.
  163. set IVer to 0.
  164. set KIs to .025.
  165.  
  166. until ag6 { //stationkeeping loop around 8km from station
  167. set svh to vectorheading(ship:velocity:orbit). //chaser velocity heading
  168. set tph to vectorheading(target:position). //target position heading
  169. set latdist1 to lateralDistance(svh,tph).
  170. set verdist1 to verticalDistance().
  171. set t1 to time:seconds.
  172. set tardistActual to targetDistance().
  173. set tardist1 to targetDistance().
  174. wait 0.1.
  175.  
  176. clearscreen.
  177. print "Docking".
  178. print " ".
  179. print "Station Distance is "+round(tardistActual)+" m".
  180. print "Lateral Distance is "+(round(1000*latdist1)/1000)+" m".
  181. print "Vertical Distance is "+(round(1000*verdist1)/1000)+" m".
  182. print " ".
  183. Print "Vertical Control Input: "+(round(100*Vinput)/100).
  184. print "Lateral Control Input: "+(round(100*Linput)/100).
  185. print "Foreward Control Input: "+(round(100*Tinput)/100).
  186. print " ".
  187. print "Vertical Velocity: "+(round(1000000*dVer)/1000)+" mm/s".
  188. print "Lateral Velocity: "+(round(1000000*dLat)/1000)+" mm/s".
  189. print "Foreward Velocity: "+(-round(1000000*dtar)/1000)+" mm/s".
  190.  
  191.  
  192. set svh to vectorheading(ship:velocity:orbit). //chaser velocity heading
  193. set tph to vectorheading(target:position). //target position heading
  194. set latdist2 to lateralDistance(svh,tph).
  195. set verdist2 to verticalDistance().
  196. set tardist2 to targetDistance().
  197.  
  198. set t2 to time:seconds.
  199. set dLat to (latdist2-latdist1)/(t2-t1).
  200. set dVer to (verdist2-verdist1)/(t2-t1).
  201. set dtar to (tardist2-tardist1)/(t2-t1).
  202.  
  203.  
  204.  
  205.  
  206.  
  207. if abs(latdist2) > 125 {
  208. set lateralVsetpoint to -4*transVelocity*latdist2/abs(latdist2).
  209. set Linput to (lateralVsetpoint-dLat)*kpv.
  210. } else if abs(latdist2) > 50 {
  211. set lateralVsetpoint to -2*transVelocity*latdist2/abs(latdist2).
  212. set Linput to (lateralVsetpoint-dLat)*kpv.
  213. } else if abs(latdist2) > 10 {
  214. set lateralVsetpoint to -transVelocity*latdist2/abs(latdist2).
  215. set Linput to (lateralVsetpoint-dLat)*kpv.
  216. } else if abs(latdist2) > 5 {
  217. set lateralVsetpoint to -0.5*transVelocity*latdist2/abs(latdist2).
  218. set Linput to (lateralVsetpoint-dLat)*kpv.
  219. set ILat to 0.
  220. } else {
  221. set ILat to (latdist2*(t2-t1))+ILat.
  222. set Linput to (kps*latdist2)+(kd*dLat)+(KIs*ILat).
  223. }
  224.  
  225. if abs(verdist2) > 125 {
  226. set verticalVsetpoint to -4*transVelocity*verdist2/abs(verdist2).
  227. set Vinput to (verticalVsetpoint-dVer)*kpv.
  228. } else if abs(verdist2) > 50 {
  229. set verticalVsetpoint to -2*transVelocity*verdist2/abs(verdist2).
  230. set Vinput to (verticalVsetpoint-dVer)*kpv.
  231. } else if abs(verdist2)>10 {
  232. set verticalVsetpoint to -transVelocity*verdist2/abs(verdist2).
  233. set Vinput to (verticalVsetpoint-dVer)*kpv.
  234. } else if abs(verdist2) > 5 {
  235. set verticalVsetpoint to -0.5*transVelocity*verdist2/abs(verdist2).
  236. set Vinput to (verticalVsetpoint-dVer)*kpv.
  237. set IVer to 0.
  238. } else {
  239. set IVer to (Verdist2*(t2-t1))+IVer.
  240. set Vinput to (kps*verdist2)+(kd*dVer)+(KIs*IVer).
  241. }
  242.  
  243. if abs(tardist2) > 125 {
  244. set targetVsetpoint to -2*transVelocity.
  245. set Tinput to (targetVsetpoint-dtar)*kpv.
  246. } else if abs(tardist2) > 35 {
  247. set targetVsetpoint to -1*transVelocity.
  248. set Tinput to (targetVsetpoint-dTar)*kpv.
  249. } else {
  250. set targetVsetpoint to -0.1*transVelocity.
  251. set Tinput to (targetVsetpoint-dTar)*kpv.
  252. }
  253.  
  254. set ship:control:fore to Tinput.
  255. set ship:control:starboard to Linput.
  256. set ship:control:top to Vinput.
  257.  
  258. }
  259.  
  260. ag6 off.
  261.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement