Trying to reach a working mini model

This commit is contained in:
2023-08-30 23:13:34 +02:00
parent 8fdf18f6a4
commit 2665e657ed
8 changed files with 189 additions and 77 deletions

View File

@@ -1,5 +1,9 @@
import math
from enum import Enum
from maneuver_scheduler import ManeuverScheduler
class ManeuverAlarmType(Enum):
ManeuverNode = 1,
@@ -7,8 +11,9 @@ class ManeuverAlarmType(Enum):
class Maneuver:
def __init__(self, conn, vessel):
self.vessel = vessel
def __init__(self, conn, mission_control):
self.mission_control = mission_control
self.vessel = mission_control.vessel
self.conn = conn
def plan_next_maneuver(self):
@@ -18,8 +23,8 @@ class Maneuver:
class NodeManeuver(Maneuver):
alarm_type = ManeuverAlarmType.ManeuverNode
def __init__(self, conn, vessel):
super().__init__(conn, vessel)
def __init__(self, conn, mission_control):
super().__init__(conn, mission_control)
self.mech_jeb = conn.mech_jeb
self.node_executor = self.mech_jeb.node_executor
@@ -42,9 +47,28 @@ class NodeManeuver(Maneuver):
while enabled():
enabled.wait()
def book_timeslot_for_node(self, node, maneuver, duration=None):
if node.time_to < 0:
node.remove()
planning_duration = 60
ut = ManeuverScheduler.next_free_timeslot(self.conn.space_center.ut + planning_duration, planning_duration)
ManeuverScheduler.book_timeslot(ut, self.vessel, duration=planning_duration)
time_required = (node.delta_v * self.vessel.mass) / self.vessel.available_thrust
duration = math.floor(2 * ManeuverScheduler.node_offsets + time_required)
alarm_start = node.ut - (duration / 2 + ManeuverScheduler.node_offsets)
if ManeuverScheduler.timeslot_is_free(alarm_start, duration):
ManeuverScheduler.book_timeslot_for_node(self.vessel, node, self, alarm_start=alarm_start, duration=duration)
else:
node.remove()
planning_duration = 60
ut = ManeuverScheduler.next_free_timeslot(alarm_start, planning_duration)
ManeuverScheduler.book_timeslot(ut, self.vessel, duration=planning_duration)
class MechJebManeuver(NodeManeuver):
def __init__(self, conn, vessel):
super().__init__(conn, vessel)
def __init__(self, conn, mission_control):
super().__init__(conn, mission_control)
self.maneuver_planner = self.mech_jeb.maneuver_planner

View File

@@ -10,8 +10,8 @@ from . import Maneuver
class ApproachManeuver(Maneuver):
def __init__(self, conn, vessel_id, reference_frame):
super().__init__(conn, vessel_id)
def __init__(self, conn, mission_control, reference_frame):
super().__init__(conn, mission_control)
self.reference_frame = reference_frame
def start(self):
@@ -64,10 +64,8 @@ def point_toward_direction(vessel, direction, reference_frame):
ap.target_roll = 0
ap.sas = False
ap.engage()
sleep(.1)
while magnitude(vessel.angular_velocity(reference_frame)) > .1:
sleep(.1)
sleep(1)
ap.wait()
ap.disengage()
ap.sas_mode = SASMode.stability_assist

View File

@@ -6,14 +6,14 @@ from . import MechJebManeuver
class ComsatManeuver(MechJebManeuver):
def __init__(self, conn, vessel, target_body):
super().__init__(conn, vessel)
def __init__(self, conn, mission_control, target_body):
super().__init__(conn, mission_control)
self.target_body = target_body
body = self.target_body
if body.satellites:
lowest_sat = min(body.satellites, key=lambda sat: sat.orbit.periapsis)
max_orbit = lowest_sat.orbit.periapsis - lowest_sat.sphere_of_influence
max_orbit = lowest_sat.orbit.periapsis_altitude - lowest_sat.sphere_of_influence
else:
max_orbit = body.sphere_of_influence
@@ -29,11 +29,11 @@ class ComsatManeuver(MechJebManeuver):
if vessel.orbit.body.name != self.target_body.name:
raise NotImplementedError
if not math.isclose(vessel.orbit.apoapsis, self.target_altitude, rel_tol=.01):
SetOrbitApoapsis(self.conn, vessel, self.target_altitude).prepare_maneuver()
elif not math.isclose(vessel.orbit.eccentricity, 0, rel_tol=.01):
CircularizeOrbitAndDeliver(self.conn, vessel, self.target_altitude).prepare_maneuver()
elif self.vessel.control.current_stage == 0:
if not math.isclose(vessel.orbit.apoapsis_altitude, self.target_altitude, rel_tol=.01):
SetOrbitApoapsis(self.conn, vessel, self.target_body).prepare_maneuver()
elif not math.isclose(vessel.orbit.eccentricity, 0, abs_tol=.001) or self.vessel.control.current_stage > 1:
CircularizeOrbitAndDeliver(self.conn, vessel, self.target_body).prepare_maneuver()
elif self.vessel.control.current_stage <= 1:
return True
return False
@@ -73,8 +73,13 @@ class CircularizeOrbitAndDeliver(ComsatManeuver):
while self.vessel.control.nodes:
self._execute_node()
if self.vessel.control.current_stage > 0:
self.vessel.control.activate_next_stage()
current_stage = self.vessel.control.current_stage
if current_stage > 1:
relay = self.vessel.control.activate_next_stage()
sc.active_vessel = relay[0]
sc.active_vessel.name = self.vessel.name + " " + current_stage
sc.active_vessel.control.solar_panels = True
sc.active_vessel = self.vessel
oro = self.maneuver_planner.operation_resonant_orbit
oro.resonance_numerator = 2

View File

@@ -6,8 +6,8 @@ from . import Maneuver
class DockingManeuver(Maneuver):
def __init__(self, conn, vessel_id, docking_part, reference_frame):
super().__init__(conn, vessel_id)
def __init__(self, conn, mission_control, docking_part, reference_frame):
super().__init__(conn, mission_control)
self.docking_part = docking_part
self.reference_frame = reference_frame