Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @clobberbuiltins on.
- clearscreen.
- main().
- coastandcor().
- function main {
- set Tar to body("Mun").
- set tap to Tar:altitude+body:radius.
- lock steering to prograde.
- set status1 to "Awaiting for user input to search needed phase angle for burn(AG9)".
- until ag9 {
- printing().
- }
- toggle ag9.
- set status1 to "Awaiting for 90 degrees phase angle".
- lock steering to prograde.
- until checkang {
- printing().
- print checkang.
- }
- set status1 to "Phase angle reached, awaiting for burn".
- set maneuvertime to time:seconds + ((abs(cur_angle)-90)/360)*orbit:period. // 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 tap. // your target apoapsis.
- set smja to (ap + TargetAp) / 2. // your final semimajoraxis
- set targetvel to sqrt(body:mu*((2/ap)-(1/smja))). // target speed
- set apvel to myvel:mag. // burn point speed
- set needvel to targetvel-apvel. // needed speed
- set thr to ship:partstagged("TE")[0]:maxthrust. // Engine Thrust
- set m to ship:mass. // Mass
- set e to constant():E. // E constant
- set p to ship:partstagged("TE")[0]:isp. // ISP
- set g to constant:g0. // Gravitational acceleration constant.
- set burn_duration to abs(g * m * p * (1 - e^(-needvel/(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 ti to time:seconds.
- wait 1.
- until maneuvertime-ti-burn_duration/2 <= 60 and maneuvertime-ti-burn_duration/2 > 0 {
- print "To maneuver left: " + (maneuvertime-ti-burn_duration/2) + " Seconds".
- print "Needed dv: " + abs(needvel) + " m/s".
- wait 0.1.
- printing().
- }
- lock steering to prograde.
- //now we need to wait until the burn vector and ship's facing are aligned
- until vang(ship:velocity:orbit, ship:facing:vector) < 0.25 {
- print "To maneuver left: " + (maneuvertime-ti-burn_duration/2) + " Seconds".
- print "Needed dv: " + abs(needvel) + " m/s".
- wait 0.1.
- printing().
- }
- until maneuvertime-ti-burn_duration/2 <= 10 {
- print "To maneuver left: " + (maneuvertime-ti-(burn_duration/2)) + " Seconds".
- print "Needed dv: " + abs(needvel) + " m/s".
- wait 0.1.
- printing().
- }
- set ship:control:fore to 0.5.
- set status1 to "RCS activated for ullage".
- until maneuvertime-ti-burn_duration/2 <= 1 {
- print "To maneuver left: " + (maneuvertime-ti-(burn_duration/2)) + " Seconds".
- print "Needed dv: " + abs(needvel) + " m/s".
- wait 0.1.
- printing().
- }
- set ship:control:fore to 0.
- until maneuvertime-ti-burn_duration/2 <= 0.5 {
- print "To maneuver left: " + (maneuvertime-ti-(burn_duration/2)) + " Seconds".
- wait 0.1.
- printing().
- }
- set now to time:seconds.
- lock ti to time:seconds - now.
- set myvel1 to ship:velocity:orbit:mag.
- set tvel to targetvel.
- lock throttle to 1.
- set status1 to "Third Stage Engine Activated".
- until ti > burn_duration or orbit:hasnextpatch = True {
- set myvel1 to ship:velocity:orbit:mag.
- print "Time left: " + (burn_duration-ti) + " Seconds".
- print "Speed left: " + (tvel-myvel1) + " m/s".
- wait 0.01.
- printing().
- }
- lock throttle to max(0, 1-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.
- stage.
- set status1 to "Third Stage Separation".
- }
- function coastandcor {
- lock steering to prograde.
- ag2 on.
- ag3 on.
- set status1 to "Antenna opened, fuel cells are working(AG2 to disable them).Waiting for input command for correction burn(AG9)".
- until ag9 {
- printing().
- }
- toggle ag9.
- set ship:control:fore to 0.4.
- set status1 to "Correction burn".
- set norm to vcrs(velocityAt(ship,orbit:nextpatch:eta:periapsis+time:seconds):orbit, -positionAt(Mun,orbit:nextpatch:eta:periapsis+time:seconds)).
- set rad to vcrs(velocityAt(ship,orbit:nextpatch:eta:periapsis+time:seconds):orbit, norm).
- set fore to vcrs(rad,norm).
- until orbit:nextpatch:periapsis > 55000 and orbit:apoapsis > 12380000 {
- printing().
- }
- set ship:control:fore to 0.
- set status1 to "Correction completed".
- }
- function checkang {
- set VecS to ship:position - body("Kerbin"):position.
- set VecT to Tar:position - body("Kerbin"):position.
- set VecHV to vxcl(ship:up:vector, ship:velocity:orbit).
- set VecST to Tar:position - ship:position.
- set cur_angle to vang(VecT, VecS).
- set targetang to 89.5.
- if vang(Vect, VecS)>90 {
- set cur_angle to -cur_angle.
- }
- print cur_angle.
- print targetang.
- wait 0.1.
- return cur_angle > -targetang - 30 and cur_angle < -targetang and vang(ship:velocity:orbit,Tar:position-ship:position)<50.
- }
- function printing {
- clearscreen.
- set t to (time:seconds-now1)/60.
- print "T+: " + t + " Minutes".
- print "Status: " + status1.
- wait 0.1.
- }
Advertisement
Add Comment
Please, Sign In to add comment