Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set T to vessel("Iss").
- lock steering to prograde.
- rcs on.
- b1().
- function b1 {
- wait 0.
- set TargetAp to ship:apoapsis + body:radius.
- lock ap to ship:apoapsis + body:radius.
- set smja to (ap + TargetAp) / 2.
- set targetvel to sqrt(body:mu*((2/ap)-(1/smja))).
- print targetvel.
- set maneuvertime to time + eta:apoapsis.
- set apvel to velocityat(ship, maneuvertime):orbit:mag.
- print apvel.
- set needvel to targetvel - apvel.
- print needvel.
- set nd to node(maneuvertime, 0, 0, needvel).
- add nd.
- set max_acc to 8/ship:mass.
- set burn_duration to nd:deltav:mag/max_acc.
- print "Crude Estimated burn duration: " + round(burn_duration) + "s".
- lock steering to prograde.
- wait until nd:eta <= (burn_duration/2 + 60).
- set np to nd:deltav. //points to node, don't care about the roll direction.
- lock steering to np.
- //now we need to wait until the burn vector and ship's facing are aligned
- wait until vang(np, ship:facing:vector) < 0.25.
- //the ship is facing the right direction, let's wait for our burn time
- wait until nd:eta <= (burn_duration/2).
- //we only need to lock throttle once to a certain variable in the beginning of the loop, and adjust only the variable itself inside it
- set ship:control:fore to 0.
- set done to False.
- //initial deltav
- set dv0 to nd:deltav.
- until done
- {
- set max_acc to 8/ship:mass.
- //throttle is 100% until there is less than 1 second of time left to burn
- //when there is less than 1 second - decrease the throttle linearly
- set ship:control:fore to min(nd:deltav:mag/max_acc, 1).
- //here's the tricky part, we need to cut the throttle as soon as our nd:deltav and initial deltav start facing opposite directions
- //this check is done via checking the dot product of those 2 vectors
- if vdot(dv0, nd:deltav) < 0
- {
- print "End burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
- set ship:control:fore to 0.
- break.
- }
- //we have very little left to burn, less then 0.1m/s
- if nd:deltav:mag < 0.1
- {
- print "Finalizing burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
- //we burn slowly until our node vector starts to drift significantly from initial vector
- //this usually means we are on point
- wait until vdot(dv0, nd:deltav) < 0.5.
- set ship:control:fore to 0.
- print "End burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
- set done to True.
- }
- }
- unlock steering.
- unlock throttle.
- wait 1.
- //we no longer need the maneuver node
- remove nd.
- //set throttle to 0 just in case.
- SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
- }
- function b2 {
- wait 0.
- set TargetAp to T:apoapsis + body:radius.
- set ap to ship:apoapsis + body:radius.
- set smja to (ap + TargetAp) / 2.
- set targetvel to sqrt(body:mu*((2/ap)-(1/smja))).
- print targetvel.
- set now to time:seconds + 30.
- set maneuvertime to now.
- set apvel to velocityat(ship, maneuvertime):orbit:mag.
- print apvel.
- set needvel to targetvel - apvel.
- print needvel.
- set nd to node(maneuvertime, 0, 0, needvel).
- add nd.
- set max_acc to 8/ship:mass.
- set burn_duration to nd:deltav:mag/max_acc.
- print "Crude Estimated burn duration: " + round(burn_duration) + "s".
- lock steering to prograde.
- wait until nd:eta <= (burn_duration/2 + 60).
- set np to nd:deltav. //points to node, don't care about the roll direction.
- lock steering to np.
- //now we need to wait until the burn vector and ship's facing are aligned
- wait until vang(np, ship:facing:vector) < 0.25.
- //the ship is facing the right direction, let's wait for our burn time
- wait until nd:eta <= (burn_duration/2).
- //we only need to lock throttle once to a certain variable in the beginning of the loop, and adjust only the variable itself inside it
- set ship:control:fore to 0.
- set done to False.
- //initial deltav
- set dv0 to nd:deltav.
- until done
- {
- set max_acc to 8/ship:mass.
- //throttle is 100% until there is less than 1 second of time left to burn
- //when there is less than 1 second - decrease the throttle linearly
- set ship:control:fore to min(nd:deltav:mag/max_acc, 1).
- //here's the tricky part, we need to cut the throttle as soon as our nd:deltav and initial deltav start facing opposite directions
- //this check is done via checking the dot product of those 2 vectors
- if vdot(dv0, nd:deltav) < 0
- {
- print "End burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
- set ship:control:fore to 0.
- break.
- }
- //we have very little left to burn, less then 0.1m/s
- if nd:deltav:mag < 0.1
- {
- print "Finalizing burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
- //we burn slowly until our node vector starts to drift significantly from initial vector
- //this usually means we are on point
- wait until vdot(dv0, nd:deltav) < 0.5.
- set ship:control:fore to 0.
- print "End burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
- set done to True.
- }
- }
- unlock steering.
- unlock throttle.
- wait 1.
- //we no longer need the maneuver node
- remove nd.
- //set throttle to 0 just in case.
- SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
- }
- function calcangle {
- set sa to (2*body("Kerbin"):radius + T:altitude + ship:altitude)/2.
- set ta to body("Kerbin"):radius + T:altitude.
- print sa.
- print ta.
- return 180*(1-(sa/ta)^1.5).
- }
- function checkang {
- set VecS to ship:position - body("Kerbin"):position.
- set VecT to T:position - body("Kerbin"):position.
- set VecHV to vxcl(ship:up:vector, ship:velocity:orbit).
- set VecST to T:position - ship:position.
- set t_angle to calcangle.
- set cur_angle to vang(VecT, VecS).
- if vang(Vect, VecS)>90 {
- set cur_angle to -cur_angle.
- }
- print cur_angle - t_angle.
- return abs(cur_angle - t_angle) < 6.
- }
- until checkang {
- lock steering to prograde.
- print checkang.
- wait 1.
- clearscreen.
- }
- b2().
- LOCK TargetVector TO Target:ORBIT:POSITION-SHIP:ORBIT:POSITION.
- wait until TargetVector:mag < 5000.
- run approach.
- run dock.
Add Comment
Please, Sign In to add comment