def circularize_at_intercept(conn): print("Plotting dV2 Burn to Circularize...") v = conn.space_center.active_vessel time = conn.space_center.ut node = circularize_at_apoapsis(v, time) print("Executing circularization burn of {} m/s...".format(node.delta_v)) execute_next_node(conn)
def match_planes(conn): print("Computing Plane Change Maneuver if Necessary...") sc = conn.space_center v = sc.active_vessel t = sc.target_vessel ascending = False time = sc.ut if v.orbit.relative_inclination(t) < 0.004363323129985824: #.25 degree print("Planes within .25 degree. Continuing with program...") return #figure out if AN or DN is soonest. Since Script assumes circular orbits #it doesn't worry about which is highest (cheapest burn). ut_an = v.orbit.ut_at_true_anomaly(v.orbit.true_anomaly_an(t)) ut_dn = v.orbit.ut_at_true_anomaly(v.orbit.true_anomaly_dn(t)) if ut_an < ut_dn: ascending = True time = ut_an else: ascending = False time = ut_dn #calculate plane change burn sp = v.orbit.orbital_speed_at(time) inc = v.orbit.relative_inclination(t) normal = sp * math.sin(inc) prograde = sp * math.cos(inc) - sp if ascending: normal *= -1 #antinormal at ascending node node = v.control.add_node(time, normal=normal, prograde=prograde) print("Executing Plane Change of {} m/s...".format(node.delta_v)) execute_next_node(conn)
def ascent(conn, launch_params): ''' Ascent Autopilot function. Goes to space, or dies trying. ''' #Setup KRPC and PIDs conn = krpc.connect(name='Launch') sc = conn.space_center v = sc.active_vessel telem=v.flight(v.orbit.body.reference_frame) thrust_controller = PID(P=.001, I=0.0001, D=0.01) thrust_controller.ClampI = launch_params.max_q thrust_controller.setpoint(launch_params.max_q) #Prepare for Launch v.auto_pilot.engage() v.auto_pilot.target_heading=inc_to_heading(launch_params.inclination) if launch_params.force_roll: v.auto_pilot.target_roll=launch_params.roll v.control.throttle=1.0 #Gravity Turn Loop while apoapsis_way_low(v, launch_params.orbit_alt): gravturn(conn, launch_params) autostage(v , launch_params.max_auto_stage) limitq(conn, thrust_controller) telemetry(conn) time.sleep(1.0 / REFRESH_FREQ) v.control.throttle = 0.0 # Fine Tune APA v.auto_pilot.disengage() v.auto_pilot.sas=True time.sleep(.1) v.auto_pilot.sas_mode = v.auto_pilot.sas_mode.prograde v.auto_pilot.wait() boostAPA(conn, launch_params) #fine tune APA # Coast Phase sc.physics_warp_factor = MAX_PHYSICS_WARP while still_in_atmosphere(conn): if apoapsis_little_low(v , launch_params.orbit_alt): sc.physics_warp_factor = 0 boostAPA(conn, launch_params) sc.physics_warp_factor = MAX_PHYSICS_WARP telemetry(conn) time.sleep(1.0 / REFRESH_FREQ) # Circularization Burn sc.physics_warp_factor = 0 planCirc(conn) telemetry(conn) execute_next_node(conn) # Finish Up if launch_params.deploy_solar: v.control.solar_panels=True telemetry(conn) v.auto_pilot.sas_mode= v.auto_pilot.sas_mode.prograde
def hohmann(conn): print("Plotting Hohmann Transfer Maneuver...") sc = conn.space_center v = sc.active_vessel t = sc.target_vessel time = sc.ut phase_angle = get_phase_angle(v, t) transfer_time = time_transfer(v, t, time, phase_angle) node = hohmann_transfer(v, t, transfer_time) print("Executing transfer injection burn {} m/s...".format(node.delta_v)) execute_next_node(conn)