Skip to content

Commit

Permalink
Delta V tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark2000 committed Dec 19, 2024
1 parent d16821d commit f45b18c
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/bsk_rl/sim/fsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from bsk_rl.sim import dyn
from bsk_rl.utils.functional import (
AbstractClassProperty,
aliveness_checker,
check_aliveness_checkers,
default_args,
)
Expand Down Expand Up @@ -1000,6 +1001,29 @@ class MagicOrbitalManeuverFSWModel(BasicFSWModel):
def __init__(self, *args, **kwargs) -> None:
"""Model that allows for instantaneous Delta V maneuvers."""
super().__init__(*args, **kwargs)
self.setup_fuel(**kwargs)

@property
def dv_available(self):
"""Delta-V available for the satellite."""
return self._dv_available

@aliveness_checker
def fuel_remaining(self) -> bool:
"""Check if the satellite has fuel remaining."""
return self.dv_available > 0

@default_args(dv_available_init=100.0)
def setup_fuel(self, dv_available_init: float, **kwargs):
"""Set up available fuel for the satellite.
# TODO: may adjust names for consistency with modelled fuel take in future.
Args:
dv_available_init: [m/s] Initial fuel level.
kwargs: Passed to other setup functions.
"""
self._dv_available = dv_available_init

@action
def action_magic_thrust(self, dv_N: np.ndarray) -> None:
Expand All @@ -1008,15 +1032,17 @@ def action_magic_thrust(self, dv_N: np.ndarray) -> None:
Args:
dv_N: [m/s] Inertial Delta V.
"""
if np.linalg.norm(dv_N) > self.dv_available:
self.satellite.logger.warning(
f"Maneuver exceeds available Delta V ({np.linalg.norm(dv_N)}/{self.fuel_remaining} m/s)."
)

self._dv_available -= np.linalg.norm(dv_N)

self.dynamics.scObject.dynManager.getStateObject(
self.dynamics.scObject.hub.nameOfHubVelocity
).setState(list(np.array(self.dynamics.v_BN_N) + np.array(dv_N)))

# # Teleporting
# self.dynamics.scObject.dynManager.getStateObject(
# self.dynamics.scObject.hub.nameOfHubPosition
# ).setState(list(np.array(dv_N)))


class RSOImagingFSWModel(ContinuousImagingFSWModel):
def set_target_rso(self, rso: "Satellite") -> None:
Expand Down

0 comments on commit f45b18c

Please sign in to comment.