Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attitude model #194

Merged
merged 58 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0610412
visualization code from examples, added thermal sim to get familiar (…
Mr-Medina Dec 25, 2023
fa7c867
added Earth-Centered Inertial Frame (ECI) to Roll-Pitch-Yaw (RPY) ref…
Mr-Medina Dec 26, 2023
01e9f74
added function to transform a vector from ECI to RPY. (also added a f…
Mr-Medina Dec 26, 2023
0242126
added transformation matrix for RPY to body fixed frames
Mr-Medina Dec 26, 2023
86c55ca
RPY to body fixed vector transformation functions added
Mr-Medina Dec 26, 2023
e967cc4
v1 reference frame transfer file. cleaned up comments. inputs: lists …
Mr-Medina Dec 26, 2023
53a8a34
Some cleaning up
Mr-Medina Dec 26, 2023
3993c6a
added functions for user to identify disturbances (aero, gravitationa…
Mr-Medina Dec 28, 2023
07047e4
created disturbance function file
Mr-Medina Dec 28, 2023
935ccc4
disturbance torque in attitude model
Mr-Medina Dec 28, 2023
dfa12e5
added case for zero euler angles (for ref frame transfers)
Mr-Medina Dec 28, 2023
7cd2e31
initial onditions added
Mr-Medina Dec 28, 2023
e2b5351
Now able to call attitude in rad and deg from spacecraft actor.
Mr-Medina Dec 28, 2023
ce85d15
added some dynamics to attitude model (not complete at all, needs to …
Mr-Medina Dec 28, 2023
eb4ba79
added more dynamics but I think its wrong (too simple)
Mr-Medina Dec 28, 2023
da4ba34
added has_attitude_model function
Mr-Medina Dec 28, 2023
3b214e4
fixed error converting angles
Mr-Medina Dec 28, 2023
70c9a61
added get_previous_position function
Mr-Medina Dec 28, 2023
8ebaeea
update atitude model in paseos
Mr-Medina Dec 28, 2023
0a0cdad
fixing ref frame transformations
Mr-Medina Dec 28, 2023
3cea066
TODO add pointing vector in inertial frame, updating extra component …
Mr-Medina Dec 28, 2023
608ef32
test file to see if model makes some sensez
Mr-Medina Dec 28, 2023
dd38d0c
added function (might be deleted later) and fixed some stuff
Mr-Medina Dec 29, 2023
62e97f5
play python file to plot attitude. Works with plotting Nadir vector
Mr-Medina Dec 29, 2023
b4080b3
commit attitude model before changing most of it (to get dynamics cor…
Mr-Medina Dec 29, 2023
8a67834
play file fixed
Mr-Medina Dec 29, 2023
385ccb0
tried to apply correct dynamics. Not there yet
Mr-Medina Dec 30, 2023
e28964e
get_euler, angles can now also be negative. Right handed system applied
Mr-Medina Dec 30, 2023
438eca6
Update base_actor.py
Mr-Medina Dec 30, 2023
4c0457b
Update spacecraft_actor.py
Mr-Medina Dec 30, 2023
7f7f893
Update play.py
Mr-Medina Dec 30, 2023
1494585
Update attitude_model.py
Mr-Medina Dec 30, 2023
a18cd6a
changed translation= to default False, Euler angle function is redund…
Mr-Medina Jan 2, 2024
195c28e
model "v3" works with constant angular velocity, breaks after certain…
Mr-Medina Jan 2, 2024
967b177
set_attitude_model: added correct arguments
Mr-Medina Jan 2, 2024
376a565
own test file
Mr-Medina Jan 2, 2024
0c90588
Attitude model now correctly models attitude with constant angular ve…
Mr-Medina Jan 2, 2024
78594d0
Needs to be fixed: with z angular velocity, roll is introduced
Mr-Medina Jan 2, 2024
fc3a857
different transformation matrix (roll pitch yaw angles are not the sa…
Mr-Medina Jan 3, 2024
0a537a7
one rotation (depending on the transformation sequence in body_to_rpy…
Mr-Medina Jan 3, 2024
3d4b351
Model works with constant angular velocity input, outputs correct poi…
Mr-Medina Jan 3, 2024
7f6f144
minor adjustments normalizing input pointing vector, todo added
Mr-Medina Jan 3, 2024
6f7c781
minor adjustments normalizing input pointing vector, sign fixed
Mr-Medina Jan 3, 2024
816f155
use rodriguez rotations instead of reference frame rotations (this do…
Mr-Medina Jan 4, 2024
4b1e5d3
added rodriguez rotation function
Mr-Medina Jan 4, 2024
aba8df1
implemented rodriguez rotation for both rotations of the body frame
Mr-Medina Jan 4, 2024
0b444dd
body to rpy convention: yaw - pitch - roll. transformation functions …
Mr-Medina Jan 4, 2024
4a5ebee
added function to get rpy angles, todo: perform actual body rotations…
Mr-Medina Jan 5, 2024
270d859
Now model works with initial attitude specified, calculates attitude …
Mr-Medina Jan 8, 2024
67864ff
Clean up code + added acceleration calculations (deleted possibility …
Mr-Medina Jan 9, 2024
4a130b3
fixed problem where when pitch = 90 deg, it stays 90.
Mr-Medina Jan 9, 2024
d8b6abe
code cleanup, more comments, rodrigues instead of rodriguez, moved re…
Mr-Medina Jan 9, 2024
a68f04d
renamed play file to test attitude plotting
Mr-Medina Jan 9, 2024
9e4b78d
attitude model pull request
Mr-Medina Jan 10, 2024
724e9f5
Removed own test files for pr
Mr-Medina Jan 10, 2024
6ce55d7
Added plotting file back to branch for visually checking attitude model
Mr-Medina Jan 10, 2024
3633631
implemented some feedback
Mr-Medina Jan 11, 2024
5fe2dc3
Merge branch 'attitude-model' into Attitude_pointing
Moanalengkeek Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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


class ActorBuilder:
Expand Down Expand Up @@ -490,6 +491,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
Loading