Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @clobberbuiltins on.
- clearscreen.
- main().
- correction().
- function main {
- set Tar to body("Kerbin").
- set tap to body:soiradius+13600000.
- lock steering to prograde.
- until vang(ship:velocity:orbit,ship:facing:vector)<0.5 {
- printing().
- }
- unlock steering.
- set status1 to "All Controls Are Unlocked.We Are Coasting.Awaiting for user input to search needed phase angle for burn(AG9)".
- until ag9 {
- printing().
- }
- toggle ag9.
- set status1 to "Awaiting for -180 degrees phase angle".
- until checkang {
- printing().
- print checkang.
- }
- set status1 to "Phase angle reached, aiming and awaiting for burn".
- set maneuvertime to time:seconds + ((abs(targetang)-abs(cur_angle))/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
- 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^(-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.
- set status to "One Minute Till Burn.".
- //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 "SM Engine Activated".
- until ti > burn_duration and orbit:hasnextpatch and orbit:nextpatch:periapsis < 150000 {
- until t > burn_duration - 1 {
- set myvel1 to ship:velocity:orbit:mag.
- print "Time left: " + (burn_duration-ti) + " Seconds".
- print "Speed left: " + (tvel-myvel1) + " m/s".
- wait 0.1.
- printing().
- }
- set myvel1 to ship:velocity:orbit:mag.
- print "Time left: " + (burn_duration-ti) + " Seconds".
- print "Speed left: " + (tvel-myvel1) + " m/s".
- wait 0.1.
- 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.
- set status1 to "To Kerbin Burn Completed.Unlocking all controls, waiting for Mun Sphere of Influence Exit".
- }
- function correction {
- until ship:body:name = "Kerbin" {
- printing().
- print "Left to Mun Sphere of Inluence Exit: " + (orbit:nextpatcheta/60) + " Minutes".
- }
- set status1 to "Mun Sphere of influence is passed.Waiting for input command for Kerbin correction burn(AG9)".
- until ag9 {
- printing().
- }
- lock steering to retrograde.
- toggle ag9.
- set ship:control:fore to 1.
- set status1 to "Kerbin Correction burn".
- until orbit:periapsis < 40000 {
- printing().
- }
- set ship:control:fore to 0.
- set status1 to "Correction to Kerbin completed".
- unlock steering.
- unlock throttle.
- }
- function checkang {
- set VecS to ship:position - body("Mun"):position.
- set VecT to Tar:position - body("Mun"):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 -180.
- if vang(Vect, VecS)>90 {
- set cur_angle to -cur_angle.
- }
- print cur_angle.
- print targetang.
- return cur_angle < targetang + 25 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