Advertisement
Guest User

Untitled

a guest
Apr 17th, 2021
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.17 KB | None | 0 0
  1.  
  2. clearscreen.
  3.  
  4. print "Yup, it's phase time, boiyos".
  5.  
  6. set mu to 3.986e14.
  7. set g to 9.81.
  8. set pi to 3.1415926535897932384626433832795028841971693993751058209749445923.
  9. set transThrust to 4.41. //.530 for 3 clowns 0.26 for resupply
  10. set foreThrust to 8.67. //1.06 for 3 clowns 0.52 for resupply
  11. set bodyRadius to 6371000.
  12. lights on.
  13.  
  14.  
  15. function vectorheading {
  16. parameter vector.
  17. set northvec to ship:north:vector.
  18. set westvec to vcrs(northvec,ship:up:vector).
  19. set vcrossup to vcrs(vector,ship:up:vector).
  20. if vang(vcrossup,northvec) > 90 {
  21. set hdg to -vang(vcrossup,westvec).
  22. } else {
  23. set hdg to vang(vcrossup,westvec).
  24. }
  25. return hdg.
  26. }
  27.  
  28. function targetAngle {
  29. set targetPosition to -ship:body:position+target:position.
  30. set theta to vang(targetPosition,-ship:body:position).
  31. return theta.
  32. }
  33.  
  34. function degreesPerOrbit {
  35. set DPO to 360*((target:orbit:period/ship:orbit:period)-1).
  36. return DPO.
  37. }
  38.  
  39. function relativeInclination {
  40. set targpos to target:position-ship:body:position.
  41. set htarg to vcrs(targpos,target:velocity:orbit).
  42. set hship to -vcrs(ship:body:position,ship:velocity:orbit).
  43. set relinc to vang(htarg,hship).
  44. return relinc.
  45. }
  46.  
  47. lock steering to prograde+R(0,0,180).
  48. set ship:control:pilotmainthrottle to 0.
  49. lock throttle to 0.
  50. sas off.
  51. rcs on.
  52. wait 10.
  53. sas on.
  54. unlock steering.
  55. wait 3.
  56.  
  57. set targAngle to targetAngle.
  58. set dpo to degreesPerOrbit.
  59.  
  60.  
  61. //FIRST PHASING ORBIT
  62.  
  63. set t0 to time:seconds.
  64. set kuniverse:timewarp:warp to 1.
  65. wait until time:seconds>(t0+10).
  66. set t0 to time:seconds.
  67. set kuniverse:timewarp:warp to 2.
  68. wait until time:seconds > (t0+100).
  69. set kuniverse:timewarp:warp to 3.
  70.  
  71. until targangle<(2.1*dpo) {
  72. set targAngle to targetAngle.
  73. set dpo to degreesPerOrbit.
  74. print "Target/Chaser angle: "+(round(10*targAngle)/10)+" degrees".
  75. print "Degrees per Orbit: "+(round(10*dpo)/10)+" degrees".
  76. wait 0.1.
  77. clearscreen.
  78. }
  79.  
  80.  
  81.  
  82. //Warping to apogee
  83.  
  84. until ship:verticalspeed > 0 and abs(ship:altitude-ship:apoapsis) <10000 {
  85. set targAngle to targetAngle.
  86. set dpo to degreesPerOrbit.
  87. print "Target/Chaser angle: "+(round(10*targAngle)/10)+" degrees".
  88. print "Degrees per Orbit: "+(round(10*dpo)/10)+" degrees".
  89. wait 0.1.
  90. clearscreen.
  91. }
  92.  
  93. //DE-WARPING SLOWLY
  94. print "De-Warping".
  95. set kuniverse:timewarp:warp to 2.
  96. wait until abs(ship:altitude-ship:apoapsis) < 500.
  97. set kuniverse:timewarp:warp to 1.
  98. wait until abs(ship:altitude-ship:apoapsis) < 5.
  99. set kuniverse:timewarp:warp to 0.
  100.  
  101. //Circularizing at Apogee
  102. lock steering to prograde+R(0,0,180).
  103. sas off.
  104. wait 10.
  105. clearscreen.
  106. print "Circularizing".
  107. lock throttle to 1.
  108. set orbitalv to sqrt(mu/(ship:body:position:mag)).
  109. until ship:velocity:orbit:mag > orbitalv {
  110. lock steering to heading(vectorheading(ship:velocity:orbit),0)+R(0,0,180).
  111. set ship:control:top to 3*ship:verticalspeed.
  112. wait 0.05.
  113. }
  114. set ship:control:neutralize to true.
  115. //Warping to next phasing burn
  116. clearscreen.
  117. print "Phasing and Warping to next burn".
  118. lock throttle to 0.
  119. unlock steering.
  120. sas on.
  121. wait 5.
  122.  
  123. //SECOND PHASING ORBIT
  124. set t0 to time:seconds.
  125. set kuniverse:timewarp:warp to 1.
  126. wait until time:seconds>(t0+10).
  127. set t0 to time:seconds.
  128. set kuniverse:timewarp:warp to 2.
  129. wait until time:seconds > (t0+100).
  130. set kuniverse:timewarp:warp to 3.
  131.  
  132. set targAngle to targetAngle.
  133. set dpo to degreesPerOrbit.
  134. until targangle<(1.1*dpo) {
  135. set targAngle to targetAngle.
  136. set dpo to degreesPerOrbit.
  137. print "Target/Chaser angle: "+(round(10*targAngle)/10)+" degrees".
  138. print "Degrees per Orbit: "+(round(10*dpo)/10)+" degrees".
  139. wait 0.1.
  140. clearscreen.
  141. }
  142.  
  143. //Warping and Dewarping to station apsis
  144. if target:verticalspeed < 0 {
  145. until abs(target:periapsis-target:altitude)<100 {
  146. set targAngle to targetAngle.
  147. set dpo to degreesPerOrbit.
  148. print "Target/Chaser angle: "+(round(10*targAngle)/10)+" degrees".
  149. print "Degrees per Orbit: "+(round(10*dpo)/10)+" degrees".
  150. wait 0.1.
  151. clearscreen.
  152. }
  153. set kuniverse:timewarp:warp to 2.
  154. until abs(target:periapsis-target:altitude)<10 {
  155. set targAngle to targetAngle.
  156. set dpo to degreesPerOrbit.
  157. print "Target/Chaser angle: "+(round(10*targAngle)/10)+" degrees".
  158. print "Degrees per Orbit: "+(round(10*dpo)/10)+" degrees".
  159. wait 0.1.
  160. clearscreen.
  161. }
  162. set kuniverse:timewarp:warp to 1.
  163. until abs(target:periapsis-target:altitude)<1 {
  164. set targAngle to targetAngle.
  165. set dpo to degreesPerOrbit.
  166. print "Target/Chaser angle: "+(round(10*targAngle)/10)+" degrees".
  167. print "Degrees per Orbit: "+(round(10*dpo)/10)+" degrees".
  168. wait 0.1.
  169. clearscreen.
  170. }
  171. set kuniverse:timewarp:warp to 0.
  172. } else {
  173. until abs(target:apoapsis-target:altitude)<100 {
  174. set targAngle to targetAngle.
  175. set dpo to degreesPerOrbit.
  176. print "Target/Chaser angle: "+(round(10*targAngle)/10)+" degrees".
  177. print "Degrees per Orbit: "+(round(10*dpo)/10)+" degrees".
  178. wait 0.1.
  179. clearscreen.
  180. }
  181. set kuniverse:timewarp:warp to 2.
  182. until abs(target:apoapsis-target:altitude)<10 {
  183. set targAngle to targetAngle.
  184. set dpo to degreesPerOrbit.
  185. print "Target/Chaser angle: "+(round(10*targAngle)/10)+" degrees".
  186. print "Degrees per Orbit: "+(round(10*dpo)/10)+" degrees".
  187. wait 0.1.
  188. clearscreen.
  189. }
  190. set kuniverse:timewarp:warp to 1.
  191. until abs(target:apoapsis-target:altitude)<1 {
  192. set targAngle to targetAngle.
  193. set dpo to degreesPerOrbit.
  194. print "Target/Chaser angle: "+(round(10*targAngle)/10)+" degrees".
  195. print "Degrees per Orbit: "+(round(10*dpo)/10)+" degrees".
  196. wait 0.1.
  197. clearscreen.
  198. }
  199. set kuniverse:timewarp:warp to 0.
  200. }
  201.  
  202. if target:verticalspeed > 0 { //this helps determine if the next target apsis is apogee or perigee
  203. set isApo to 1.
  204. } else {
  205. set isApo to 0.
  206. }
  207. wait 5.
  208.  
  209. //Waiting to burn then burning. Raising apogee to 5km below station apsis
  210. lock steering to prograde+R(0,0,180).
  211. sas off.
  212. set waitTime to (ship:body:position:mag*targAngle*pi/180)/ship:velocity:orbit:mag.
  213. set initialmissiontime to time:seconds.
  214. sas on.
  215. set kuniverse:timewarp:warp to 1.
  216. wait until time:seconds>(initialmissiontime+(0.8*waittime)).
  217. set kuniverse:timewarp:warp to 0.
  218. sas off.
  219. wait until time:seconds>(initialmissiontime+waittime).
  220. clearscreen.
  221. print "Raising Apogee to -5km".
  222. lock throttle to 1.
  223.  
  224. if isApo = 1 {
  225. until ship:apoapsis > (target:periapsis-5500) {
  226. set ship:control:top to 3*ship:verticalspeed.
  227. lock steering to heading(vectorheading(ship:velocity:orbit),0)+R(0,0,180).
  228. wait 0.1.
  229. }
  230. } else {
  231. until ship:apoapsis > (target:apoapsis-5500){
  232. set ship:control:top to 3*ship:verticalspeed.
  233. lock steering to heading(vectorheading(ship:velocity:orbit),0)+R(0,0,180).
  234. wait 0.1.
  235. }
  236. }
  237. set ship:control:neutralize to true.
  238. lock throttle to 0.
  239.  
  240. //Raising Perigee to 5km below apsis
  241. clearscreen.
  242. print "Warping to next burn".
  243. lock throttle to 0.
  244. unlock steering.
  245. sas on.
  246. wait 5.
  247.  
  248. set t0 to time:seconds.
  249. set kuniverse:timewarp:warp to 1.
  250. wait until time:seconds>(t0+10).
  251. set t0 to time:seconds.
  252. set kuniverse:timewarp:warp to 2.
  253. wait until time:seconds > (t0+100).
  254. set kuniverse:timewarp:warp to 3.
  255. wait until abs(ship:altitude-ship:apoapsis) < 5000.
  256. set kuniverse:timewarp:warp to 2.
  257. wait until abs(ship:altitude-ship:apoapsis) < 500.
  258. set kuniverse:timewarp:warp to 1.
  259. wait until abs(ship:altitude-ship:apoapsis) < 5.
  260. set kuniverse:timewarp:warp to 0.
  261. wait 10.
  262. sas off.
  263. lock steering to prograde+R(0,0,180).
  264. clearscreen.
  265. print "Raising Perigee to -5km".
  266. lock throttle to 1.
  267.  
  268. if isApo = 1 {
  269. until ship:apoapsis > (target:apoapsis-5500){
  270. set ship:control:top to 3*ship:verticalspeed.
  271. lock steering to heading(vectorheading(ship:velocity:orbit),0)+R(0,0,180).
  272. wait 0.1.
  273. }
  274. } else {
  275. until ship:periapsis > (target:periapsis-5500) {
  276. set ship:control:top to 3*ship:verticalspeed.
  277. lock steering to heading(vectorheading(ship:velocity:orbit),0)+R(0,0,180).
  278. wait 0.1.
  279. }
  280. }
  281. set ship:control:neutralize to true.
  282. lock throttle to 0.
  283. wait 5.
  284.  
  285.  
  286. //Matching Vertical Speeds of chaser and station
  287. until abs(ship:verticalspeed-target:verticalspeed)<0.01 {
  288. print "Matching Vertical Speeds".
  289. print " ".
  290. print "Chaser VS: "+(round(ship:verticalspeed*100)/100)+" m/s".
  291. print "Station VS: "+(round(target:verticalspeed*100)/100)+" m/s".
  292. set VSerror to target:verticalspeed-ship:verticalspeed.
  293. set ship:control:top to -15*VSerror.
  294. wait 0.1.
  295. clearscreen.
  296. }
  297. set ship:control:neutralize to true.
  298. unlock steering.
  299. sas on.
  300.  
  301.  
  302. //Warping ahead to match planes
  303. set kuniverse:timewarp:warp to 2.
  304. set killLoop to 1000.
  305. until killLoop < 0.001{
  306. set tvh to vectorheading(target:velocity:orbit).
  307. set svh to vectorheading(ship:velocity:orbit).
  308. set ri to relativeInclination().
  309. set killLoop to abs(svh-tvh-ri).
  310. print "Preparing to match planes: "+killLoop.
  311. wait 0.1.
  312. clearscreen.
  313. }
  314. set kuniverse:timewarp:warp to 1.
  315. set killLoop to 1000.
  316. until killLoop < 0.0001 {
  317. set tvh to vectorheading(target:velocity:orbit).
  318. set svh to vectorheading(ship:velocity:orbit).
  319. set ri to relativeInclination().
  320. set killLoop to abs(svh-tvh-ri).
  321. print "Preparing to match planes: "+killLoop.
  322. wait 0.1.
  323. clearscreen.
  324. }
  325.  
  326.  
  327. //Matching planes
  328. set kuniverse:timewarp:warp to 0.
  329. wait 5.
  330. sas off.
  331. lock steering to prograde+r(0,0,180).
  332. clearscreen.
  333. print "Matching Planes".
  334. set ship:control:starboard to 1.
  335. set initialPeriod to ship:orbit:period.
  336. set killLoop to -1.
  337. wait 3.
  338. until killLoop > 0 {
  339. clearscreen.
  340. print "Matching Planes".
  341. set r1 to relativeInclination().
  342. print "Relative Inclination is: "+(round(10000*r1)/10000)+" degrees".
  343. set ship:control:fore to initialPeriod-ship:orbit:period.
  344. wait 0.1.
  345. set r2 to relativeInclination().
  346. set killLoop to r2-r1.
  347. }
  348. clearscreen.
  349. set ship:control:neutralize to true.
  350.  
  351. wait 10.
  352. unlock steering.
  353. sas on.
  354.  
  355. set t0 to time:seconds.
  356. set kuniverse:timewarp:warp to 1.
  357. wait until time:seconds>(t0+10).
  358. set t0 to time:seconds.
  359. set kuniverse:timewarp:warp to 2.
  360. wait until time:seconds > (t0+100).
  361. set kuniverse:timewarp:warp to 3.
  362.  
  363.  
  364. //warping to intercept burn
  365. set yburn to 2.
  366. set y to 30000000.
  367.  
  368. until y<(yburn+20000) {
  369. set targang to targetAngle().
  370. set y to (targang/360)*2*pi*(bodyRadius+target:altitude).
  371. set yburn to ((target:altitude-ship:altitude)*2.35)+8000.
  372. print "Loop One".
  373. print "Commencing burn at Y = "+round(yburn).
  374. print "Current Y value = "+round(y).
  375. wait 0.1.
  376. clearscreen.
  377. }
  378. set kuniverse:timewarp:warp to 2.
  379. until y<(yburn+4000) {
  380. set targang to targetAngle().
  381. set y to (targang/360)*2*pi*(bodyRadius+target:altitude).
  382. set yburn to ((target:altitude-ship:altitude)*2.35)+8000.
  383. print "Loop Two".
  384. print "Commencing burn at Y = "+round(yburn).
  385. print "Current Y value = "+round(y).
  386. wait 0.1.
  387. clearscreen.
  388. }
  389. set kuniverse:timewarp:warp to 1.
  390. until y<(yburn+150) {
  391. set targang to targetAngle().
  392. set y to (targang/360)*2*pi*(bodyRadius+target:altitude).
  393. set yburn to ((target:altitude-ship:altitude)*2.35)+8000.
  394. print "Loop Three".
  395. print "Commencing burn at Y = "+round(yburn).
  396. print "Current Y value = "+round(y).
  397. wait 0.1.
  398. clearscreen.
  399. }
  400. set kuniverse:timewarp:warp to 0.
  401. sas off.
  402. lock steering to prograde+r(0,0,180).
  403. until y<(yburn) {
  404. set targang to targetAngle().
  405. set y to (targang/360)*2*pi*(bodyRadius+target:altitude).
  406. set yburn to ((target:altitude-ship:altitude)*2.35)+8000.
  407. print "Commencing burn at Y = "+round(yburn).
  408. print "Current Y value = "+round(y).
  409. wait 0.1.
  410. clearscreen.
  411. }
  412.  
  413.  
  414. //calculating and beginning intercept burn
  415. set w to 2*pi/ship:orbit:period.
  416. set dv to .25*w*(target:altitude-ship:altitude).
  417.  
  418. set a to foreThrust/ship:mass.
  419. set t to dv/a.
  420.  
  421. set ship:control:fore to 1.
  422.  
  423. set t0 to time:seconds.
  424. until time:seconds > (t0+t) { //intercept 8km aft of station
  425. lock steering to heading(vectorheading(ship:velocity:orbit),0)+R(0,0,180).
  426. clearscreen.
  427. print "Initiating Final Transfer Burn".
  428. wait 0.05.
  429. }
  430. set ship:control:fore to 0.
  431. set ship:control:neutralize to true.
  432. unlock steering.
  433. sas on.
  434. wait 5.
  435.  
  436. clearscreen.
  437. print "Please Run the finalapproach.ks file".
  438.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement