Skip to content

Commit

Permalink
Merge pull request #194 from Mr-Medina/Attitude_pointing
Browse files Browse the repository at this point in the history
Attitude model
  • Loading branch information
Moanalengkeek authored Jan 19, 2024
2 parents c7a9030 + 5fe2dc3 commit ff93e5f
Show file tree
Hide file tree
Showing 15 changed files with 804 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/PASEOS.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions paseos/actors/actor_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ..thermal.thermal_model import ThermalModel
from ..power.power_device_type import PowerDeviceType
from ..radiation.radiation_model import RadiationModel
from ..attitude.attitude_model import AttitudeModel
from paseos.geometric_model.geometric_model import GeometricModel


Expand Down Expand Up @@ -519,6 +520,40 @@ def set_thermal_model(
power_consumption_to_heat_ratio=power_consumption_to_heat_ratio,
)

@staticmethod
def set_disturbances(
actor: SpacecraftActor,
aerodynamic: bool = False,
gravitational: bool = False,
magnetic: bool = False,
):
disturbance_list = []
if aerodynamic:
disturbance_list.append("aerodynamic")
if gravitational:
disturbance_list.append("gravitational")
if magnetic:
disturbance_list.append("magnetic")
actor._disturbances = disturbance_list

@staticmethod
def set_attitude_model(
actor: SpacecraftActor,
actor_initial_attitude_in_rad: list[float] = [0.0, 0.0, 0.0],
actor_initial_angular_velocity: list[float] = [0.0, 0.0, 0.0],
actor_pointing_vector_body: list[float] = [0.0, 0.0, 1.0]

):

actor._attitude_model = AttitudeModel(
local_actor=actor,
actor_initial_attitude_in_rad=actor_initial_attitude_in_rad,
actor_initial_angular_velocity=actor_initial_angular_velocity,
actor_pointing_vector_body=actor_pointing_vector_body,


)

@staticmethod
def add_comm_device(actor: BaseActor, device_name: str, bandwidth_in_kbps: float):
"""Creates a communication device.
Expand Down
20 changes: 20 additions & 0 deletions paseos/actors/base_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class BaseActor(ABC):
# Tracks the current activity
_current_activity = None

# Attitude disturbances experienced by the actor
_disturbances = None

# The following variables are used to track last evaluated state vectors to avoid recomputation.
_previous_position = None
_time_of_previous_position = None
Expand Down Expand Up @@ -157,6 +160,15 @@ def has_thermal_model(self) -> bool:
"""
return hasattr(self, "_thermal_model") and self._thermal_model is not None

@property
def has_attitude_model(self) -> bool:
"""Returns true if actor's attitude is modeled, else false.
Returns:
bool: bool indicating presence.
"""
return hasattr(self, "_attitude_model") and self._attitude_model is not None

@property
def mass(self) -> float:
"""Returns actor's mass in kg.
Expand Down Expand Up @@ -328,6 +340,14 @@ def get_position_velocity(self, epoch: pk.epoch):
self._time_of_previous_position = epoch.mjd2000
return pos, vel

def get_disturbances(self):
"""Get the user specified spacecraft attitude disturbances
Returns:
list[string]: name of disturbances
"""
return self._disturbances

def is_in_line_of_sight(
self,
other_actor: "BaseActor",
Expand Down
33 changes: 33 additions & 0 deletions paseos/actors/spacecraft_actor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
from loguru import logger
import pykep as pk

Expand All @@ -21,6 +22,7 @@ class SpacecraftActor(BaseActor):

_thermal_model = None
_radiation_model = None
_attitude_model = None

# If radiation randomly restarted the device
_was_interrupted = False
Expand Down Expand Up @@ -164,3 +166,34 @@ def charge(self, duration_in_s: float):
self = charge_model.charge(self, duration_in_s)

logger.debug(f"New battery level is {self.battery_level_in_Ws}")

def attitude_in_rad(self):
"""Returns the current attitude of the actor in radians
Returns:
list[floats]: actor attitude in radians
"""
if type(self._attitude_model._actor_attitude_in_rad) == np.ndarray:
return np.ndarray.tolist(self._attitude_model._actor_attitude_in_rad)
else:
return self._attitude_model._actor_attitude_in_rad

def attitude_in_deg(self):
"""Returns the current attitude of the actor in degrees
Returns:
list[floats]: actor attitude in degrees
"""
if type(self._attitude_model._actor_attitude_in_rad) == np.ndarray:
return np.ndarray.tolist(self._attitude_model._actor_attitude_in_rad * 180 / np.pi)
else:
return np.ndarray.tolist(np.array(self._attitude_model._actor_attitude_in_rad) * 180 / np.pi)


def pointing_vector(self):
"""Returns the spacecraft pointing vector
Returns:
numpy ndarray (x, y, z)
"""
return self._attitude_model._actor_pointing_vector_eci
Loading

0 comments on commit ff93e5f

Please sign in to comment.