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

Student #205

Open
wants to merge 158 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 149 commits
Commits
Show all changes
158 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
ff93e5f
Merge pull request #194 from Mr-Medina/Attitude_pointing
Moanalengkeek Jan 19, 2024
db97bd7
Implemented geometric model, angular velocity vector is also possible…
Mr-Medina Jan 19, 2024
0f68861
visual test for attitude plotting cleaned up a bit
Mr-Medina Jan 19, 2024
0259866
Added the tests for the geometric_model
Moanalengkeek Jan 22, 2024
c792502
Created disturbance model function and partly implemented it in the a…
Moanalengkeek Jan 22, 2024
e8ceb9e
Found and fixed issue that the moment of inertia doesn't scale with mass
Moanalengkeek Jan 22, 2024
ba0f57c
updated test to match issue fixed
Moanalengkeek Jan 22, 2024
0d585f9
Updated test again
Moanalengkeek Jan 22, 2024
59c3599
Removed @propert on line 81 of geometric_model
Moanalengkeek Jan 23, 2024
a2ad9fb
Merge pull request #199 from aidotse/geometrical-model-tests
GabrieleMeoni Jan 23, 2024
64b1ece
pull request #198 feedback
Mr-Medina Jan 23, 2024
28c55de
pull request #198 feedback
Mr-Medina Jan 23, 2024
b645b3b
pull request #198 feedback
Mr-Medina Jan 23, 2024
612b3b2
pull request #198 feedback
Mr-Medina Jan 23, 2024
d818d3f
Apply suggestions from code review
Mr-Medina Jan 23, 2024
71c3f50
Apply suggestions from code review
Mr-Medina Jan 23, 2024
7dd542b
Apply suggestions from code review
Mr-Medina Jan 23, 2024
87e09b8
Student cleaned.
Jan 23, 2024
b6602e1
Pleasing flake.
Jan 23, 2024
aa21573
Apply suggestion from code review
Mr-Medina Jan 23, 2024
55b6443
Apply suggestion from code review
Mr-Medina Jan 23, 2024
50ceeac
Fixed time discrepancies of model. both rotations now applied at corr…
Mr-Medina Jan 24, 2024
428a75e
formatting
Mr-Medina Jan 24, 2024
acb6aee
Updates gravity model implementation
Moanalengkeek Jan 25, 2024
9732308
Attitude model also runs without set_disturbances (for test file)
Mr-Medina Jan 25, 2024
7b6db6d
Added two tests, one for attitude model with known angular velocity, …
Moanalengkeek Jan 25, 2024
11eb784
setting disturbances when no disturbances used.
Mr-Medina Jan 25, 2024
2f9969f
test commit for seeing if merge shows up.
Mr-Medina Jan 25, 2024
8b1d525
Added additional test to confirm conditions after 1 orbit are initial…
Moanalengkeek Jan 26, 2024
ccd3712
Aero disturbance files
GiordanoNesci Jan 26, 2024
aacaa42
Update and rename disturbance_calculations.py to paseos/disturbance_c…
GiordanoNesci Jan 26, 2024
93f6332
Delete paseos/attitude/disturbance_calculations.py
GiordanoNesci Jan 26, 2024
3ce7dae
Update and rename paseos/disturbance_calculations.py to paseos/attitu…
GiordanoNesci Jan 26, 2024
b42eac9
Update and rename aero_disturbance_test.py to paseos/attitude/aero_di…
GiordanoNesci Jan 26, 2024
0a66921
Merge remote-tracking branch 'origin/attitude-model' into attitude-model
Mr-Medina Jan 26, 2024
f0522e4
added attitude tests
Mr-Medina Jan 26, 2024
b56c076
added Earth magnetic dipole moment vector function
Mr-Medina Jan 27, 2024
ce74572
Commit (unimportant or placeholder files/changes)
Mr-Medina Jan 27, 2024
ddf1006
Detele file for pr
Mr-Medina Jan 27, 2024
536f606
Commenting
Mr-Medina Jan 27, 2024
d31310f
Added tests and removed bugs from gravity disturbance model
Moanalengkeek Jan 27, 2024
bdcd11b
magnetic disturbance code v1
Mr-Medina Jan 27, 2024
f64cc0e
fixed some stuff, added way to visualize B on actor position (needs t…
Mr-Medina Jan 27, 2024
dcdc6f1
Merge remote-tracking branch 'origin/student' into magnetic-disturbances
Mr-Medina Jan 28, 2024
30d108f
next position in disturbance calculations and cleanup
Mr-Medina Jan 28, 2024
e95504b
commit to save, but won't work (intentional)
Mr-Medina Jan 28, 2024
5a3dbc2
Merge remote-tracking branch 'origin/student' into attitude-model
Mr-Medina Jan 28, 2024
ac935cc
attitude model bug with geometric model interaction fixed
Mr-Medina Jan 28, 2024
437d908
Merge branch 'attitude-model' into magnetic-disturbances
Mr-Medina Jan 28, 2024
437b8d9
test for magnetic disturbance
Mr-Medina Jan 29, 2024
ef25a18
test for magnetic disturbance finished
Mr-Medina Jan 29, 2024
7914692
test for magnetic disturbance cleaned up
Mr-Medina Jan 29, 2024
21d9634
deleted unnecessary lines
Mr-Medina Jan 29, 2024
747a270
Apply suggestion from code review
Mr-Medina Jan 29, 2024
8e37a3b
no more next position in magnetic disturbance model.
Mr-Medina Jan 29, 2024
4240289
made functions in attitude model internal
Mr-Medina Jan 29, 2024
dee082b
made functions in attitude model internal
Mr-Medina Jan 29, 2024
43b29d9
Merge branch 'attitude-model' into magnetic-disturbances
Mr-Medina Jan 29, 2024
f257760
commenting & cleaning up
Mr-Medina Jan 29, 2024
e94520a
todo added
Mr-Medina Jan 29, 2024
e51829e
Deleted file
Mr-Medina Jan 29, 2024
bb1056f
Merge pull request #198 from aidotse/attitude-model
GabrieleMeoni Jan 30, 2024
3822fb5
Merge branch 'attitude-model' into gravity-disturbances
Moanalengkeek Jan 30, 2024
a2cb141
Merged final attitude model inot this branch, and implemented changes…
Moanalengkeek Jan 30, 2024
884c0a4
Merge branch 'student' into gravity-disturbances
Moanalengkeek Jan 30, 2024
70a4e27
Moved magnetic_dipole_moment function to central body.
Mr-Medina Jan 30, 2024
084ae6d
Merge pull request #202 from aidotse/attitude-magnetic-disturbance
GabrieleMeoni Jan 31, 2024
3f13190
Update paseos/attitude/attitude_model.py
Moanalengkeek Jan 31, 2024
a9dc4ab
Final commits
Moanalengkeek Jan 31, 2024
695f40e
Merge remote-tracking branch 'origin/gravity-disturbances' into gravi…
Moanalengkeek Jan 31, 2024
50f0456
Merge branch 'student' into gravity-disturbances
Moanalengkeek Jan 31, 2024
f1c3037
Update aero_disturbance_test.py
GiordanoNesci Jan 31, 2024
ed4828f
Update disturbance_calculations.py
GiordanoNesci Jan 31, 2024
4d7640b
Merge branch 'student' into student_clean
Feb 1, 2024
5987af2
Fixing wrong test function names.
Feb 1, 2024
96e2564
Merge branch 'student' into student_clean
Feb 1, 2024
0b2d549
Reformatting and pleasing flake.
Feb 1, 2024
df16bc4
Merge branch 'student' into gravity-disturbances
GabrieleMeoni Feb 1, 2024
e042180
Merge pull request #200 from aidotse/gravity-disturbances
GabrieleMeoni Feb 1, 2024
e1fb6ac
Merge branch 'student' into student_clean
Feb 1, 2024
3e117bd
Reformatting
Feb 1, 2024
333196d
Merge branch 'student' into aerodynamic-disturbances
GabrieleMeoni Feb 1, 2024
07d215b
Merge pull request #203 from aidotse/aerodynamic-disturbances
GabrieleMeoni Feb 1, 2024
a8032b1
Merging to PASEOS
Feb 1, 2024
0dd8c56
Merge branch 'student' into student_clean
Feb 1, 2024
ad72734
Adding version constraint to pytest to enable running tests with
Feb 1, 2024
f0e1a15
Reformatted with --line-length 100 option
Feb 1, 2024
ef1d0d7
Merge pull request #204 from aidotse/student_clean
GabrieleMeoni Feb 1, 2024
a6ef070
Rm unwanted files.
Feb 1, 2024
ff192ef
Removing unwanted files.
Feb 1, 2024
bc5bfd1
Removing unwanted files.
Feb 1, 2024
2e77458
Applying first suggestions.
Feb 13, 2024
624966d
Implementing other suggestions.
Feb 13, 2024
1d7df19
Removing aerodynamic modelling (it requires a major rewriting and
Feb 13, 2024
5d184cf
Adding commits according to Pablo's suggestions.
Feb 14, 2024
363c11f
Adding missing file.
Feb 14, 2024
e9d8fce
Fixing bug. Removing aerodisturbance test (model not implemented yet).
Feb 14, 2024
020e53b
Pleasing Flake.
Feb 14, 2024
54a8621
Removed unwanted test.
Feb 14, 2024
9245ccb
Fixing wrong comments
Feb 14, 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
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- myst-parser # for markdown math in docs
- pykep>=2.6 # core non-optional dependency
- pyquaternion>=0.9.9 # core non-optional dependency
- pytest # for tests
- pytest<8.0.0 # for tests
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
- pytest-asyncio # for tests involving activities
- python>=3.8 # core non-optional dependency
- scikit-spatial>=6.5.0 # core non-optional dependency
Expand Down
116 changes: 106 additions & 10 deletions paseos/actors/actor_builder.py
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from ..thermal.thermal_model import ThermalModel
from ..power.power_device_type import PowerDeviceType
from ..radiation.radiation_model import RadiationModel
from paseos.geometric_model.geometric_model import GeometricModel
from .spacecraft_body_model import SpacecraftBodyModel
from ..attitude.attitude_model import AttitudeModel


class ActorBuilder:
Expand Down Expand Up @@ -307,32 +308,49 @@ def set_position(actor: BaseActor, position: list):
logger.debug(f"Setting position {position} on actor {actor}")

@staticmethod
def set_geometric_model(
def set_spacecraft_body_model(
actor: SpacecraftActor, mass: float, vertices=None, faces=None, scale: float = 1
):
"""Define geometry of the spacecraft actor. This is done in the spacecraft body reference frame, and can be
transformed to the inertial/PASEOS reference frame using the reference frane transformations in the attitude
transformed to the inertial/PASEOS reference frame using the reference frame transformations in the attitude
model. When used in the attitude model, the geometric model is in the body reference frame.

Args:
actor (SpacecraftActor): Actor to update.
mass (float): Mass of the spacecraft in kg.
vertices (list): List of all vertices of the mesh in terms of distance (in m) from origin of body frame.
Coordinates of the corners of the object. If not selected, it will default to a cube that can be scaled.
vertices (list): List of coordinates [x, y, z] of the vertices of the mesh w.r.t. the body frame [m].
If not selected, it will default to a cube that can be scaled.
by the scale. Uses Trimesh to create the mesh from this and the list of faces.
faces (list): List of the indexes of the vertices of a face. This builds the faces of the satellite by
defining the three vertices to form a triangular face. For a cuboid each face is split into two
triangles. Uses Trimesh to create the mesh from this and the list of vertices.
scale (float): Parameter to scale the cuboid by, defaults to 1.
"""
# check for spacecraft actor
assert isinstance(
actor, SpacecraftActor
), "Body model is only supported for SpacecraftActors."

assert mass > 0, "Mass is > 0"

# Check if the actor already has mass.
if actor.mass:
logger.warning("The actor already had a mass. Overriding old mass value.")

actor._mass = mass
geometric_model = GeometricModel(
local_actor=actor, actor_mass=mass, vertices=vertices, faces=faces, scale=scale

# Check if the actor already had a has_spacecraft_body_model.
if actor.has_spacecraft_body_model:
logger.warning(
"The actor already had a spacecraft body model. Overriding old body bodel."
)

# Create a spacraft body model
actor._spacecraft_body_model = SpacecraftBodyModel(
actor_mass=mass, vertices=vertices, faces=faces, scale=scale
)
actor._mesh = geometric_model.set_mesh()
actor._moment_of_inertia = geometric_model.find_moment_of_inertia

# Check if the actor has a moment of inertia
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
def set_power_devices(
Expand Down Expand Up @@ -519,6 +537,81 @@ def set_thermal_model(
power_consumption_to_heat_ratio=power_consumption_to_heat_ratio,
)

@staticmethod
def set_attitude_disturbances(
actor: SpacecraftActor,
aerodynamic: bool = False,
gravitational: bool = False,
magnetic: bool = False,
):
"""Enables the attitude disturbances to be considered in the attitude modelling for an actor.

Args:
actor (SpacecraftActor): The actor to add to.
aerodynamic (bool): Whether to consider aerodynamic disturbances in the attitude model. Defaults to False.
gravitational (bool): Whether to consider gravity disturbances in the attitude model. Defaults to False.
magnetic (bool): Whether to consider magnetic disturbances in the attitude model. Defaults to False.
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
"""
# check for spacecraft actor
assert isinstance(
actor, SpacecraftActor
), "Attitude disturbances are only supported for SpacecraftActors."

assert (
actor.has_attitude_model
), "The actor has no attitude model. Impossible to set attitude disturbances."

# Create a list with user specified disturbances which are considered in the attitude modelling.
disturbance_list = []

if aerodynamic:
disturbance_list.append("aerodynamic")
if gravitational:
disturbance_list.append("gravitational")
if magnetic:
disturbance_list.append("magnetic")
# Set attitude models.
actor._attitude_model._disturbances = disturbance_list
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved

@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_residual_magnetic_field: list[float] = [0.0, 0.0, 0.0],
):
"""Add an attitude model to the actor based on initial conditions: attitude (roll, pitch & yaw angles)
and angular velocity vector, modeling the evolution of the user specified pointing vector.

Args:
actor (SpacecraftActor): Actor to model.
actor_initial_attitude_in_rad (list of floats): Actor's initial attitude. Defaults to [0.0, 0.0, 0.0].
actor_initial_angular_velocity (list of floats): Actor's initial angular velocity. Defaults to [0.0, 0.0, 0.0].
actor_pointing_vector_body (list of floats): Actor's pointing vector. Defaults to [0.0, 0.0, 1.0].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't attitude and pointing vec the same?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that a pointing vector alone is not sufficient to define the attitude (i.e., if you have a satellite pointing to a specific direction, all the rotations around the axis passing through the pointing vector will have a different attitude but the same pointing vector). So, the pointing vector definition is arbitrary, while the attitude is not.
Of course, in a practical application, if you have a preferred direction of appointing (e.g., Nadir if you want the camera to point to the ground). So, you can fix the attitude through (yaw, pitch, roll) angles and associate a target pointing vector to track.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be good add a link to explanation of attitude? ideally in the readme with the minimal example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is in my TODO list. But I am waiting that we are both happy with the class architecture, methods, and so on, to avoid to have to redo it.

GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
actor_residual_magnetic_field (list of floats): Actor's residual magnetic dipole moment vector.
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
Defaults to [0.0, 0.0, 0.0].
"""
# check for spacecraft actor
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
assert isinstance(
actor, SpacecraftActor
), "Attitude model is only supported for SpacecraftActors"

# Check if actor has already an attitude model.
if actor.has_attitude_model:
logger.warning(
"The actor already had an attitude model. Overriding old attitude model."
)

# Set attitude model.
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,
actor_residual_magnetic_field=actor_residual_magnetic_field,
)

@staticmethod
def add_comm_device(actor: BaseActor, device_name: str, bandwidth_in_kbps: float):
"""Creates a communication device.
Expand All @@ -539,7 +632,10 @@ def add_comm_device(actor: BaseActor, device_name: str, bandwidth_in_kbps: float

@staticmethod
def add_custom_property(
actor: BaseActor, property_name: str, initial_value: Any, update_function: Callable
actor: BaseActor,
property_name: str,
initial_value: Any,
update_function: Callable,
):
"""Adds a custom property to the actor. This e.g. allows tracking any physical
the user would like to track.
Expand Down
21 changes: 21 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

# Mass
_mass = None
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved

# 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 @@ -148,6 +151,15 @@ def has_radiation_model(self) -> bool:
"""
return hasattr(self, "_radiation_model") and self._radiation_model is not None

@property
def has_spacecraft_body_model(self) -> bool:
"""Returns true if actor's body is modeled, else false.

Returns:
bool: bool indicating presence.
"""
return hasattr(self, "_spacecraft_body_model") and self._spacecraft_body_model is not None
gomezzz marked this conversation as resolved.
Show resolved Hide resolved

@property
def has_thermal_model(self) -> bool:
"""Returns true if actor's temperature is modeled, else false.
Expand All @@ -157,6 +169,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

gomezzz marked this conversation as resolved.
Show resolved Hide resolved
@property
def mass(self) -> float:
"""Returns actor's mass in kg.
Expand Down
89 changes: 88 additions & 1 deletion paseos/actors/spacecraft_actor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from loguru import logger
import numpy as np
import pykep as pk
from loguru import logger

from paseos.actors.base_actor import BaseActor
from paseos.power import discharge_model
Expand All @@ -19,8 +20,10 @@ class SpacecraftActor(BaseActor):
# Actor's mass in kg
_mass = None

_spacecraft_body_model = None
_thermal_model = None
_radiation_model = None
_attitude_model = None

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, if I actually want to use this as a user I most likely don't want my spacecraft to just tumble out of control. I think we should add a function to set the actors attitude? (allowing users to simulate corrective maneuvers)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. There are two solutions:

  • We add the possibility to add a control torque (there is a TODO in the code, I can open an issue)
  • This can be avoided by disabling attitude disturbances. In this case, there is no tumbling.

Copy link
Collaborator

@gomezzz gomezzz Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just a function to setting the current pointing/attitude? Super simple to implement and allows you implement more complex interaction via custom parameters etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add it. But, just to clarify: if you do not call actor.set_attitude_disturbances(...), the attitude will stay fixed, because no disturbance will take place. Still, I agree with you that a setter will be useful.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(please don't resolve if I should read because it will be hidden :P)

I would suggest to move the attitude into actor (maybe even base_actor?) since pointing / attitude of the actor can be interesting even if it is not disturbed or maybe even for ground station (think ground station antenna pointing)?

Copy link
Collaborator Author

@GabrieleMeoni GabrieleMeoni Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I am resolving stuff because there are so many comments that I lose track of what I have to implement xD
Well, it could be smart, but for the way it works, the attitude model works for satellites only. So, at some point we will need to implement a ground_station attitude model.

# If radiation randomly restarted the device
_was_interrupted = False
Expand Down Expand Up @@ -104,6 +107,46 @@ def mass(self) -> float:
"""
return self._mass

@property
def body_mesh(self) -> np.array:
"""Gives the mesh of the satellite.

Returns:
np.array: Mesh of the satellite.
"""
GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
return self._spacecraft_body_model._body_mesh

@property
def attitude_disturbances(self) -> list:
"""Gives attitude disturbances list.

Returns:
list: attitude disturbances list.
"""
return self._attitude_model._disturbances

@property
def body_moment_of_inertia(self) -> np.array:
"""Gives the moment of inertia of the actor, assuming constant density.

Returns:
np.array: Mass moments of inertia for the actor

GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
I is the moment of inertia, in the form of [[Ixx Ixy Ixz]
[Iyx Iyy Iyx]
[Izx Izy Izz]]
"""
return self._spacecraft_body_model._body_moment_of_inertia

@property
def body_center_of_gravity(self) -> np.array:
"""Gives the volumetric center of mass of the actor.

Returns:
np.array: Coordinates of the center of gravity of the mesh.
"""
return self._spacecraft_body_model._body_center_of_gravity

GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
@property
def temperature_in_K(self) -> float:
"""Returns the current temperature of the actor in K.
Expand Down Expand Up @@ -164,3 +207,47 @@ 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}")

@property
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) is np.ndarray:
return np.ndarray.tolist(self._attitude_model._actor_attitude_in_rad)
else:
return self._attitude_model._actor_attitude_in_rad

@property
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) is 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
)

@property
def pointing_vector(self):
"""Returns the spacecraft pointing vector in the Earth-centered inertial frame.

Returns:
np.ndarray (x, y, z).
"""
return self._attitude_model._actor_pointing_vector_eci

@property
def angular_velocity(self):
"""Returns the spacecraft angular velocity vector in the Earth-centered inertial frame.

Returns:
np.ndarray (owega_x, omega_y, omega_z).
"""
return self._attitude_model._actor_angular_velocity_eci
51 changes: 51 additions & 0 deletions paseos/actors/spacecraft_body.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate code of spacecraft_body_model.py , should probably be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it from the spacecraft_body_model, so you can access this from spacecraft actor.

GabrieleMeoni marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import trimesh


def create_body_mesh(vertices=None, faces=None, scale=1):
"""Creates the mesh of the satellite. If no vertices input is given, it defaults to a cuboid scaled by the
scale value. The default without scale values is a cube with 1m sides. This uses the python module Trimesh.
Args:
vertices (list): List of all vertices of the mesh in terms of distance (in m) from origin of body frame.
Coordinates of the corners of the object. If not selected, it will default to a cube that can be scaled
by the scale. Uses Trimesh to create the mesh from this and the list of faces.
faces (list): List of the indexes of the vertices of a face. This builds the faces of the satellite by
defining the three vertices to form a triangular face. For a cuboid each face is split into two
triangles. Uses Trimesh to create the mesh from this and the list of vertices.
scale (float): Parameter to scale the cuboid by, defaults to 1.

Returns:
mesh: Trimesh mesh of the satellite
"""
if vertices is None:
# Defines the corners of the mesh, values are in meters, from the origin of the body frame.
vertices = [
[-0.5, -0.5, -0.5],
[-0.5, -0.5, 0.5],
[-0.5, 0.5, -0.5],
[-0.5, 0.5, 0.5],
[0.5, -0.5, -0.5],
[0.5, -0.5, 0.5],
[0.5, 0.5, -0.5],
[0.5, 0.5, 0.5],
]
# List of three vertices to form a triangular face of the satellite.
# Two triangular faces are used per side of the cuboid.
faces = [
[0, 1, 3],
[0, 3, 2],
[0, 2, 6],
[0, 6, 4],
[1, 5, 3],
[3, 5, 7],
[2, 3, 7],
[2, 7, 6],
[4, 6, 7],
[4, 7, 5],
[0, 4, 1],
[1, 4, 5],
]

# Set mesh
mesh = trimesh.Trimesh(vertices, faces).apply_scale(scale)

return mesh
Loading
Loading