Advertisement
sumguytwitches

Inclination match launch

Jan 31st, 2023
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if not (defined launch_margin) declare global launch_margin is 60.
  2. if not (defined orbital_speed_multiplier) declare global orbital_speed_multiplier is 0.6.
  3. function hdg {parameter x. return mod(360+arctan2(x*vcrs(up:vector,north:vector),x*north:vector),360).}
  4. set t0 to time:seconds.
  5. set r0 to ship:position-body:position.
  6. set rh to vxcl(v(0,1,0),r0).
  7. set rv to vxcl(rh,r0).
  8. set ph to vcrs(rh,v(0,1,0)).
  9. lock t to time:seconds.
  10. function pos {parameter x. return positionat(x,t)-x:body:position.}
  11. function vel {parameter x. return velocityat(x,t):obt.}
  12. function nrm {parameter x. return vcrs(vel(x),pos(x)):normalized.}
  13. lock rs to pos(ship). lock vs to vel(ship). lock ns to nrm(ship).
  14. lock rt to pos(target). lock vt to vel(target). lock nt to nrm(target).
  15. set a to vdot(rh,nt).
  16. set b to vdot(ph,nt).
  17. set arg to -vdot(rv,nt)/sqrt(a^2+b^2).
  18. if(abs(arg) > 1) log_error("no solution").
  19. set theta1 to arccos(arg).
  20. set theta2 to 360-theta1.
  21. set q1 to mod(360+theta1+arctan2(b,a),360).
  22. set q2 to mod(360+theta2+arctan2(b,a),360).
  23. set first to min(q1,q2).
  24. set tlaunch to t0 + (first/360)*body:rotationperiod - launch_margin.
  25. print "Warping to launch window...".
  26. if time:seconds < tlaunch-300 {warpto(tlaunch-300). wait 0.}
  27. wait until warp=0 and kuniverse:timewarp:issettled and velocity:surface:mag < 0.1 and time:seconds > tlaunch-300.
  28. if time:seconds < tlaunch-10 {set warp to 1. wait 1. warpto(tlaunch-10). wait 0.}
  29. wait until warp=0 and kuniverse:timewarp:issettled and time:seconds > tlaunch-10.
  30. print "Waiting " + round(tlaunch-time:seconds) + " seconds for launch window...".
  31. wait until warp=0 and kuniverse:timewarp:issettled and time:seconds > tlaunch - 3.
  32. set h to hdg(vcrs(rs, nt):normalized*sqrt(body:mu/(body:radius+body:atm:height+10e3))*orbital_speed_multiplier - velocity:obt).
  33. print "please launch at heading " + h.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement