Advertisement
Guest User

Untitled

a guest
Apr 17th, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.24 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 4.41. //.530 for 3 clowns 0.26 for resupply
  7. set foreThrust to 8.67. //1.06 for 3 clowns 0.52 for resupply
  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. lock steering to prograde+r(0,0,180).
  53. clearscreen.
  54. print "Closing. Translating Downward".
  55. set traveldist to target:position:mag+200. //we want to maneuver 200m away
  56. set dv to traveldist/4000. //1 m/s downward moves the chaser ~4km Foreward
  57. set a to transThrust/ship:mass.
  58. set t to dv/a.
  59. set t0 to time:seconds.
  60. set ship:control:top to 1.
  61. set dX1 to target:altitude-ship:altitude.
  62.  
  63. until time:seconds>(t0+t){ //burning downward
  64. set periodDiff to (target:orbit:period-ship:orbit:period).
  65. set ship:control:fore to 10*periodDiff.
  66. print "Maneuver dV is "+(round(dv*100)/100)+" m/s".
  67. print "Closing. Translating Downward".
  68. print "Orbital period difference is: "+(round(periodDiff*1000))+" ms".
  69. wait 0.5.
  70. clearscreen.
  71. }
  72.  
  73.  
  74. //Warping to ~250m.
  75. set ship:control:neutralize to true.
  76. set dX2 to target:altitude-ship:altitude.
  77. set dX to dX2-dX1.
  78. lock steering to retrograde+r(0,0,180).
  79. set steeringmanager:maxstoppingtime to 5.
  80. until vang(-ship:velocity:orbit,ship:facing:vector) < 1 {
  81. wait 0.1.
  82. }
  83. wait 15.
  84. unlock steering.
  85. sas on.
  86. print "Warping".
  87. set t0 to time:seconds.
  88. set kuniverse:timewarp:warp to 1.
  89. wait until (target:altitude-ship:altitude)>(dx*1.51).
  90. set kuniverse:timewarp:warp to 2.
  91. wait until (target:altitude-ship:altitude < (dx*1.5)).
  92. set kuniverse:timewarp:warp to 1.
  93. wait until (target:altitude-ship:altitude < (dx*1.25)).
  94. set kuniverse:timewarp:warp to 0.
  95. sas off.
  96. lock steering to prograde + r(0,0,180).
  97. wait until (target:altitude-ship:altitude) < dX.
  98.  
  99. print "Beginning Second Stationkeeping Burn".
  100. set ship:control:top to 1.
  101. wait until (target:altitude-ship:altitude)<10.
  102.  
  103.  
  104. sas off.
  105. rcs on.
  106. lock steering to retrograde + r(0,0,180).
  107.  
  108. set transVelocity to .5.
  109. set kpv to -5. set kps to 1.5.
  110. set kd to 5.
  111. set dLat to 50.
  112. set dVer to 50.
  113. set dTar to 50.
  114. set Vinput to 0. set Tinput to 0. set Linput to 0.
  115. ag6 off.
  116.  
  117. until ag6 { //stationkeeping loop around 8km from station
  118. set svh to vectorheading(-ship:velocity:orbit). //chaser velocity heading
  119. set tph to vectorheading(target:position). //target position heading
  120. set latdist1 to lateralDistance(svh,tph).
  121. set verdist1 to verticalDistance().
  122. set t1 to time:seconds.
  123. set tardistActual to targetDistance().
  124. set tardist1 to targetDistance()-100.
  125. wait 0.1.
  126.  
  127. clearscreen.
  128. print "Approaching Station".
  129. print "Press 6 to continue with docking".
  130. print " ".
  131. print "Station Distance is "+round(tardistActual)+" m".
  132. print "Warning, Station Distance number may be incorrect".
  133. print " ".
  134. print "Lateral Distance is "+(round(1000*latdist1)/1000)+" m".
  135. print "Vertical Distance is "+(round(1000*verdist1)/1000)+" m".
  136. print " ".
  137. Print "Vertical Control Input: "+(round(100*Vinput)/100).
  138. print "Lateral Control Input: "+(round(100*Linput)/100).
  139. print "Foreward Control Input: "+(round(100*Tinput)/100).
  140. print " ".
  141. print "Vertical Velocity: "+(round(1000000*dVer)/1000)+" mm/s".
  142. print "Lateral Velocity: "+(round(1000000*dLat)/1000)+" mm/s".
  143. print "Foreward Velocity: "+(-round(1000000*dtar)/1000)+" mm/s".
  144.  
  145.  
  146. set svh to vectorheading(-ship:velocity:orbit). //chaser velocity heading
  147. set tph to vectorheading(target:position). //target position heading
  148. set latdist2 to lateralDistance(svh,tph).
  149. set verdist2 to verticalDistance().
  150. set tardist2 to targetDistance()-100.
  151.  
  152. set t2 to time:seconds.
  153. set dLat to (latdist2-latdist1)/(t2-t1).
  154. set dVer to (verdist2-verdist1)/(t2-t1).
  155. set dtar to (tardist2-tardist1)/(t2-t1).
  156.  
  157.  
  158. if abs(latdist2) > 125 {
  159. set lateralVsetpoint to -4*transVelocity*latdist2/abs(latdist2).
  160. set Linput to (lateralVsetpoint-dLat)*kpv.
  161. } else if abs(latdist2) > 50 {
  162. set lateralVsetpoint to -2*transVelocity*latdist2/abs(latdist2).
  163. set Linput to (lateralVsetpoint-dLat)*kpv.
  164. } else if abs(latdist2) > 10 {
  165. set lateralVsetpoint to -transVelocity*latdist2/abs(latdist2).
  166. set Linput to (lateralVsetpoint-dLat)*kpv.
  167. } else if abs(latdist2) > 5 {
  168. set lateralVsetpoint to -0.5*transVelocity*latdist2/abs(latdist2).
  169. set Linput to (lateralVsetpoint-dLat)*kpv.
  170. } else {
  171. set Linput to (kps*latdist2)+(kd*dLat).
  172. }
  173.  
  174. if abs(verdist2) > 125 {
  175. set verticalVsetpoint to -4*transVelocity*verdist2/abs(verdist2).
  176. set Vinput to (verticalVsetpoint-dVer)*kpv.
  177. } else if abs(verdist2) > 50 {
  178. set verticalVsetpoint to -2*transVelocity*verdist2/abs(verdist2).
  179. set Vinput to (verticalVsetpoint-dVer)*kpv.
  180. } else if abs(verdist2)>10 {
  181. set verticalVsetpoint to -transVelocity*verdist2/abs(verdist2).
  182. set Vinput to (verticalVsetpoint-dVer)*kpv.
  183. } else if abs(verdist2) > 5 {
  184. set verticalVsetpoint to -0.5*transVelocity*verdist2/abs(verdist2).
  185. set Vinput to (verticalVsetpoint-dVer)*kpv.
  186. } else {
  187. set Vinput to (kps*verdist2)+(kd*dVer).
  188. }
  189.  
  190. if abs(tardist2) > 125 {
  191. set targetVsetpoint to -4*transVelocity.
  192. set Tinput to (targetVsetpoint-dtar)*kpv.
  193. } else if abs(tardist2) > 50 {
  194. set targetVsetpoint to -2*transVelocity.
  195. set Tinput to (targetVsetpoint-dTar)*kpv.
  196. } else if abs(tardist2)>10 {
  197. set targetVsetpoint to -transVelocity.
  198. set Tinput to (targetVsetpoint-dTar)*kpv.
  199. } else if abs(tardist2) > 5 {
  200. set targetVsetpoint to -0.5*transVelocity.
  201. set Tinput to (targetVsetpoint-dTar)*kpv.
  202. } else {
  203. set Tinput to (kps*tardist2)+(kd*dTar).
  204. }
  205.  
  206. set ship:control:fore to Tinput.
  207. set ship:control:starboard to Linput.
  208. set ship:control:top to Vinput.
  209.  
  210. }
  211.  
  212. ag6 off.
  213.  
  214. set ILat to 0.
  215. set IVer to 0.
  216. set KIs to .025.
  217.  
  218. until ag6 { //stationkeeping loop around 8km from station
  219. set svh to vectorheading(-ship:velocity:orbit). //chaser velocity heading
  220. set tph to vectorheading(target:position). //target position heading
  221. set latdist1 to lateralDistance(svh,tph).
  222. set verdist1 to verticalDistance().
  223. set t1 to time:seconds.
  224. set tardistActual to targetDistance().
  225. set tardist1 to targetDistance().
  226. wait 0.1.
  227.  
  228. clearscreen.
  229. print "Docking".
  230. print " ".
  231. print "Station Distance is "+round(tardistActual)+" m".
  232. print "Lateral Distance is "+(round(1000*latdist1)/1000)+" m".
  233. print "Vertical Distance is "+(round(1000*verdist1)/1000)+" m".
  234. print " ".
  235. Print "Vertical Control Input: "+(round(100*Vinput)/100).
  236. print "Lateral Control Input: "+(round(100*Linput)/100).
  237. print "Foreward Control Input: "+(round(100*Tinput)/100).
  238. print " ".
  239. print "Vertical Velocity: "+(round(1000000*dVer)/1000)+" mm/s".
  240. print "Lateral Velocity: "+(round(1000000*dLat)/1000)+" mm/s".
  241. print "Foreward Velocity: "+(-round(1000000*dtar)/1000)+" mm/s".
  242.  
  243.  
  244. set svh to vectorheading(-ship:velocity:orbit). //chaser velocity heading
  245. set tph to vectorheading(target:position). //target position heading
  246. set latdist2 to lateralDistance(svh,tph).
  247. set verdist2 to verticalDistance().
  248. set tardist2 to targetDistance().
  249.  
  250. set t2 to time:seconds.
  251. set dLat to (latdist2-latdist1)/(t2-t1).
  252. set dVer to (verdist2-verdist1)/(t2-t1).
  253. set dtar to (tardist2-tardist1)/(t2-t1).
  254.  
  255.  
  256.  
  257.  
  258.  
  259. if abs(latdist2) > 125 {
  260. set lateralVsetpoint to -4*transVelocity*latdist2/abs(latdist2).
  261. set Linput to (lateralVsetpoint-dLat)*kpv.
  262. } else if abs(latdist2) > 50 {
  263. set lateralVsetpoint to -2*transVelocity*latdist2/abs(latdist2).
  264. set Linput to (lateralVsetpoint-dLat)*kpv.
  265. } else if abs(latdist2) > 10 {
  266. set lateralVsetpoint to -transVelocity*latdist2/abs(latdist2).
  267. set Linput to (lateralVsetpoint-dLat)*kpv.
  268. } else if abs(latdist2) > 5 {
  269. set lateralVsetpoint to -0.5*transVelocity*latdist2/abs(latdist2).
  270. set Linput to (lateralVsetpoint-dLat)*kpv.
  271. set ILat to 0.
  272. } else {
  273. set ILat to (latdist2*(t2-t1))+ILat.
  274. set Linput to (kps*latdist2)+(kd*dLat)+(KIs*ILat).
  275. }
  276.  
  277. if abs(verdist2) > 125 {
  278. set verticalVsetpoint to -4*transVelocity*verdist2/abs(verdist2).
  279. set Vinput to (verticalVsetpoint-dVer)*kpv.
  280. } else if abs(verdist2) > 50 {
  281. set verticalVsetpoint to -2*transVelocity*verdist2/abs(verdist2).
  282. set Vinput to (verticalVsetpoint-dVer)*kpv.
  283. } else if abs(verdist2)>10 {
  284. set verticalVsetpoint to -transVelocity*verdist2/abs(verdist2).
  285. set Vinput to (verticalVsetpoint-dVer)*kpv.
  286. } else if abs(verdist2) > 5 {
  287. set verticalVsetpoint to -0.5*transVelocity*verdist2/abs(verdist2).
  288. set Vinput to (verticalVsetpoint-dVer)*kpv.
  289. set IVer to 0.
  290. } else {
  291. set IVer to (Verdist2*(t2-t1))+IVer.
  292. set Vinput to (kps*verdist2)+(kd*dVer)+(KIs*IVer).
  293. }
  294.  
  295. if abs(tardist2) > 125 {
  296. set targetVsetpoint to -2*transVelocity.
  297. set Tinput to (targetVsetpoint-dtar)*kpv.
  298. } else if abs(tardist2) > 35 {
  299. set targetVsetpoint to -1*transVelocity.
  300. set Tinput to (targetVsetpoint-dTar)*kpv.
  301. } else {
  302. set targetVsetpoint to -0.5*transVelocity.
  303. set Tinput to (targetVsetpoint-dTar)*kpv.
  304. }
  305.  
  306. set ship:control:fore to Tinput.
  307. set ship:control:starboard to Linput.
  308. set ship:control:top to Vinput.
  309.  
  310. }
  311.  
  312. ag6 off.
  313.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement