Basic mission vessel tunnel
This commit is contained in:
@@ -1,103 +1,87 @@
|
||||
import numpy as np
|
||||
|
||||
from utils import execute_node, magnitude
|
||||
from .utils import magnitude
|
||||
|
||||
from maneuver_scheduler import ManeuverScheduler
|
||||
|
||||
from . import MechJebManeuver
|
||||
|
||||
|
||||
def align_orbit_planes(conn):
|
||||
print("Aligning planes")
|
||||
mj = conn.mech_jeb
|
||||
mp = mj.maneuver_planner
|
||||
oi = mp.operation_inclination
|
||||
oi.time_selector.time_reference = mj.TimeReference.eq_nearest_ad
|
||||
nodes = oi.make_nodes()
|
||||
class RendezvousManeuver(MechJebManeuver):
|
||||
def start(self):
|
||||
self.plan_next_maneuver()
|
||||
|
||||
# kac = conn.kerbal_alarm_clock
|
||||
# kac.create_alarm(
|
||||
# kac.AlarmType.maneuver,
|
||||
# "{}'s Orbital transfer".format(v.name),
|
||||
# nodes[0].ut
|
||||
# )
|
||||
def plan_next_maneuver(self):
|
||||
sc = self.conn.space_center
|
||||
vessel = sc.active_vessel
|
||||
target = sc.target_vessel
|
||||
|
||||
execute_node(conn)
|
||||
if vessel.orbit.distance_at_closest_approach(target.orbit) > 1000:
|
||||
if vessel.orbit.relative_inclination(target.orbit) > 0.0001:
|
||||
AlignOrbitPlaneWithTarget(self.conn, vessel).prepare_maneuver()
|
||||
|
||||
print("Planes aligned!")
|
||||
elif vessel.orbit.distance_at_closest_approach(target.orbit) > 10000:
|
||||
InterceptTargetOrbit(self.conn, vessel).prepare_maneuver()
|
||||
|
||||
else:
|
||||
TuneClosestApproach(self.conn, vessel).prepare_maneuver()
|
||||
return False
|
||||
|
||||
elif vessel.orbit.distance_at_closest_approach(target.orbit) <= 1000 < magnitude(
|
||||
np.array(vessel.position(vessel.reference_frame)) - np.array(target.position(vessel.reference_frame))):
|
||||
MatchVelocityWithTarget(self.conn, vessel).prepare_maneuver()
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def intercepting_target_orbit(conn):
|
||||
print("Intercepting target orbit")
|
||||
sc = conn.space_center
|
||||
v = sc.active_vessel
|
||||
mj = conn.mech_jeb
|
||||
mp = mj.maneuver_planner
|
||||
ot = mp.operation_transfer
|
||||
ot.time_selector.time_reference = mj.TimeReference.computed
|
||||
nodes = ot.make_nodes()
|
||||
nodes[0].ut = nodes[0].ut + 0.1
|
||||
class AlignOrbitPlaneWithTarget(RendezvousManeuver):
|
||||
name = "Align orbit plane with target's"
|
||||
|
||||
# kac = conn.kerbal_alarm_clock
|
||||
# kac.create_alarm(
|
||||
# kac.AlarmType.maneuver,
|
||||
# "{}'s Orbital transfer".format(v.name),
|
||||
# nodes[0].ut
|
||||
# )
|
||||
def prepare_maneuver(self):
|
||||
oi = self.maneuver_planner.operation_inclination
|
||||
oi.time_selector.time_reference = self.mech_jeb.TimeReference.eq_nearest_ad
|
||||
nodes = oi.make_nodes()
|
||||
|
||||
execute_node(conn)
|
||||
node = nodes[0]
|
||||
|
||||
print("Target orbit intercepted!")
|
||||
ManeuverScheduler.book_timeslot_for_node(self.vessel, node, self)
|
||||
|
||||
|
||||
def tune_closest_approach(conn):
|
||||
print("Tuning closest approach")
|
||||
sc = conn.space_center
|
||||
v = sc.active_vessel
|
||||
mj = conn.mech_jeb
|
||||
mp = mj.maneuver_planner
|
||||
occ = mp.operation_course_correction
|
||||
nodes = occ.make_nodes()
|
||||
class InterceptTargetOrbit(RendezvousManeuver):
|
||||
name = "Intercept target's orbit"
|
||||
|
||||
# kac = conn.kerbal_alarm_clock
|
||||
# kac.create_alarm(
|
||||
# kac.AlarmType.maneuver,
|
||||
# "{}'s Orbital transfer".format(v.name),
|
||||
# nodes[0].ut
|
||||
# )
|
||||
def prepare_maneuver(self):
|
||||
ot = self.maneuver_planner.operation_transfer
|
||||
ot.time_selector.time_reference = self.mech_jeb.TimeReference.computed
|
||||
nodes = ot.make_nodes()
|
||||
|
||||
execute_node(conn)
|
||||
node = nodes[0]
|
||||
node.ut = node.ut + 1
|
||||
|
||||
print("Closest approach tuned!")
|
||||
ManeuverScheduler.book_timeslot_for_node(self.vessel, node, self)
|
||||
|
||||
|
||||
def match_velocities(conn):
|
||||
print("Matching velocities")
|
||||
sc = conn.space_center
|
||||
v = sc.active_vessel
|
||||
mj = conn.mech_jeb
|
||||
mp = mj.maneuver_planner
|
||||
okrv = mp.operation_kill_rel_vel
|
||||
nodes = okrv.make_nodes()
|
||||
class TuneClosestApproach(RendezvousManeuver):
|
||||
name = "Tune closest approach with target"
|
||||
|
||||
# kac = conn.kerbal_alarm_clock
|
||||
# kac.create_alarm(
|
||||
# kac.AlarmType.maneuver,
|
||||
# "{}'s Orbital transfer".format(v.name),
|
||||
# nodes[0].ut
|
||||
# )
|
||||
def prepare_maneuver(self):
|
||||
occ = self.maneuver_planner.operation_course_correction
|
||||
nodes = occ.make_nodes()
|
||||
|
||||
execute_node(conn)
|
||||
node = nodes[0]
|
||||
|
||||
print("Velocities matched!")
|
||||
ManeuverScheduler.book_timeslot_for_node(self.vessel, node, self)
|
||||
|
||||
|
||||
def maneuver_to_rendezvous(conn, vessel, target):
|
||||
if vessel.orbit.distance_at_closest_approach(target.orbit) > 1000:
|
||||
if vessel.orbit.relative_inclination(target.orbit) > 0.0001:
|
||||
align_orbit_planes(conn)
|
||||
class MatchVelocityWithTarget(RendezvousManeuver):
|
||||
name = "Math velocity with target's"
|
||||
duration = 10 * 60
|
||||
|
||||
if vessel.orbit.distance_at_closest_approach(target.orbit) > 10000:
|
||||
intercepting_target_orbit(conn)
|
||||
def prepare_maneuver(self):
|
||||
okrv = self.maneuver_planner.operation_kill_rel_vel
|
||||
nodes = okrv.make_nodes()
|
||||
|
||||
tune_closest_approach(conn)
|
||||
node = nodes[0]
|
||||
|
||||
if vessel.orbit.distance_at_closest_approach(target.orbit) <= 1000 < magnitude(
|
||||
np.array(vessel.position(vessel.reference_frame)) - np.array(target.position(vessel.reference_frame))):
|
||||
match_velocities(conn)
|
||||
ManeuverScheduler.book_timeslot_for_node(self.vessel, node, self, duration=self.duration)
|
||||
|
||||
Reference in New Issue
Block a user