Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wait 0.
- clearscreen.
- set targetinc to 45. // Your target inclination
- lock steering to prograde.
- set TA1 to (360-ship:orbit:argumentofperiapsis).
- set E1 to arctan2((sqrt(1-orbit:eccentricity^2)*sin(TA1)), (orbit:eccentricity + cos(TA1))).
- set E2 to arctan2((sqrt(1-orbit:eccentricity^2)*sin(orbit:trueanomaly)), orbit:eccentricity + cos(orbit:trueanomaly)).
- set M1 to E1-(orbit:eccentricity*(sin(E1)*180/constant:pi)).
- set M2 to E2-(orbit:eccentricity*(sin(E2)*180/constant:pi)).
- set n1 to M1-M2.
- set n2 to n1+180.
- print n1.
- print n2.
- if n1 <= 270 and n1 >= 90 {
- set n3 to n1.
- set inc to orbit:inclination-targetinc.
- } else if n2 >= 90 and n2 <= 270 {
- set n3 to n2.
- set inc to targetinc-orbit:inclination.
- }
- wait 0.5.
- set T to (n3/360)*orbit:period.
- set maneuvertime to time:seconds + T. // when the burn should start
- set myvel to velocityat(ship,maneuvertime):orbit.
- set ap to ship:body:altitudeOf(positionAt(ship,maneuvertime))+body:radius. // altitude on burn point
- set TargetAp to ap. // your target apoapsis.
- set rad to positionat(ship,maneuvertime)-body:position.
- set dir to angleaxis(inc, rad). // rotating radial vector on your inclination degrees
- set smja to (ap + TargetAp) / 2. // your final semimajoraxis
- set targetvel to sqrt(body:mu*((2/ap)-(1/smja))). // target speed
- set targetvel1 to sqrt(myvel:mag^2+targetvel^2-2*myvel:mag*targetvel*cos(inc)).
- set targetvec to dir*myvel. // target vector
- set targetvec:mag to targetvel.
- set result to targetvec-myvel. // burn vector
- print vdot(targetvec,myvel).
- set apvel to myvel:mag. // burn point speed
- set needvel to targetvel-apvel. // needed speed
- print needvel.
- list engines in engList.
- set thr to engList[0]:maxthrust. // Engine Thrust
- set m to ship:mass. // Mass
- set e to constant():E. // E constant
- set p to engList[0]:isp. // ISP
- set g to constant:g0. // Gravitational acceleration constant
- set burn_duration to abs(g * m * p * (1 - e^(-targetvel1/(g*p))) / thr). // burn duration
- print "Crude Estimated burn duration: " + round(burn_duration) + "s".
- print "Needed dv: " + abs(needvel) + " m/s".
- lock steering to prograde.
- lock t to time:seconds.
- until maneuvertime-t-burn_duration/2 <= 60 and maneuvertime-t-burn_duration/2 > 0 {
- clearscreen.
- set TA1 to (360-ship:orbit:argumentofperiapsis).
- set E1 to arctan2((sqrt(1-orbit:eccentricity^2)*sin(TA1)), (orbit:eccentricity + cos(TA1))).
- set E2 to arctan2((sqrt(1-orbit:eccentricity^2)*sin(orbit:trueanomaly)), orbit:eccentricity + cos(orbit:trueanomaly)).
- set M1 to E1-(orbit:eccentricity*(sin(E1)*180/constant:pi)).
- set M2 to E2-(orbit:eccentricity*(sin(E2)*180/constant:pi)).
- set n1 to M1-M2.
- set n2 to n1+180.
- if n1 <= 270 and n1 >= 90 {
- set n3 to n1.
- } else if n2 >= 90 and n2 <= 270 {
- set n3 to n2.
- }
- print "Angle till node: " + n3 + " Degrees".
- print "To maneuver left: " + (maneuvertime-t-burn_duration/2) + " Seconds".
- print "Needed dv: " + abs(needvel) + " m/s".
- wait 0.1.
- }
- lock steering to result.
- //now we need to wait until the burn vector and ship's facing are aligned
- until vang(result, ship:facing:vector) < 0.25 {
- clearscreen.
- set myvel to ship:velocity:orbit.
- set targetvec to dir*myvel.
- set result to targetvec-myvel.
- print "To maneuver left: " + (maneuvertime-t-burn_duration/2) + " Seconds".
- print "Needed dv: " + abs(needvel) + " m/s".
- wait 0.1.
- }
- until maneuvertime-t-burn_duration/2 <= 10 {
- clearscreen.
- set myvel to ship:velocity:orbit.
- set targetvec to dir*myvel.
- set result to targetvec-myvel.
- print "To maneuver left: " + (maneuvertime-t-(burn_duration/2)) + " Seconds".
- print "Needed dv: " + abs(needvel) + " m/s".
- wait 0.1.
- }
- set ship:control:fore to 1.
- until maneuvertime-t-burn_duration/2 <= 1 {
- clearscreen.
- set myvel to ship:velocity:orbit.
- set targetvec to dir*myvel.
- set result to targetvec-myvel.
- print "To maneuver left: " + (maneuvertime-t-(burn_duration/2)) + " Seconds".
- print "Needed dv: " + abs(needvel) + " m/s".
- wait 0.1.
- }
- set ship:control:fore to 0.
- until maneuvertime-t-burn_duration/2 <= 0.5 {
- clearscreen.
- set myvel to ship:velocity:orbit.
- set targetvec to dir*myvel.
- set result to targetvec-myvel.
- print "To maneuver left: " + (maneuvertime-t-(burn_duration/2)) + " Seconds".
- wait 0.1.
- }
- set now to time:seconds.
- lock t to time:seconds - now.
- set myvel1 to ship:velocity:orbit:mag.
- set tvel to targetvel.
- set thrv to 1.
- lock throttle to thrv.
- until vang(targetvec, myvel) < 0.5 {
- clearscreen.
- set myvel to ship:velocity:orbit.
- set result to targetvec-myvel.
- set myvel1 to ship:velocity:orbit:mag.
- print vang(targetvec, myvel).
- print "Time left: " + (burn_duration-t) + " Seconds".
- print "Speed left: " + (tvel-myvel1) + " m/s".
- wait 0.1.
- }
- set targetvec to myvel.
- set result to targetvec.
- set thr to 0.3.
- until myvel1 > tvel {
- clearscreen.
- set result to targetvec.
- set myvel to ship:velocity:orbit.
- set myvel1 to ship:velocity:orbit:mag.
- print "Time left: " + (burn_duration-t) + " Seconds".
- print "Speed left: " + (tvel-myvel1) + " m/s".
- wait 0.1.
- }
- lock throttle to max(0, thrv-t/0.3).
- lock steering to prograde.
- set ship:control:fore to -1.
- wait 1.
- set ship:control:fore to 0.
- wait 5.
- unlock steering.
- unlock throttle.
Advertisement
Add Comment
Please, Sign In to add comment