-
Notifications
You must be signed in to change notification settings - Fork 9
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 v2 #198
Merged
Merged
Attitude model v2 #198
Changes from 11 commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
0610412
visualization code from examples, added thermal sim to get familiar (…
Mr-Medina fa7c867
added Earth-Centered Inertial Frame (ECI) to Roll-Pitch-Yaw (RPY) ref…
Mr-Medina 01e9f74
added function to transform a vector from ECI to RPY. (also added a f…
Mr-Medina 0242126
added transformation matrix for RPY to body fixed frames
Mr-Medina 86c55ca
RPY to body fixed vector transformation functions added
Mr-Medina e967cc4
v1 reference frame transfer file. cleaned up comments. inputs: lists …
Mr-Medina 53a8a34
Some cleaning up
Mr-Medina 3993c6a
added functions for user to identify disturbances (aero, gravitationa…
Mr-Medina 07047e4
created disturbance function file
Mr-Medina 935ccc4
disturbance torque in attitude model
Mr-Medina dfa12e5
added case for zero euler angles (for ref frame transfers)
Mr-Medina 7cd2e31
initial onditions added
Mr-Medina e2b5351
Now able to call attitude in rad and deg from spacecraft actor.
Mr-Medina ce85d15
added some dynamics to attitude model (not complete at all, needs to …
Mr-Medina eb4ba79
added more dynamics but I think its wrong (too simple)
Mr-Medina da4ba34
added has_attitude_model function
Mr-Medina 3b214e4
fixed error converting angles
Mr-Medina 70c9a61
added get_previous_position function
Mr-Medina 8ebaeea
update atitude model in paseos
Mr-Medina 0a0cdad
fixing ref frame transformations
Mr-Medina 3cea066
TODO add pointing vector in inertial frame, updating extra component …
Mr-Medina 608ef32
test file to see if model makes some sensez
Mr-Medina dd38d0c
added function (might be deleted later) and fixed some stuff
Mr-Medina 62e97f5
play python file to plot attitude. Works with plotting Nadir vector
Mr-Medina b4080b3
commit attitude model before changing most of it (to get dynamics cor…
Mr-Medina 8a67834
play file fixed
Mr-Medina 385ccb0
tried to apply correct dynamics. Not there yet
Mr-Medina e28964e
get_euler, angles can now also be negative. Right handed system applied
Mr-Medina 438eca6
Update base_actor.py
Mr-Medina 4c0457b
Update spacecraft_actor.py
Mr-Medina 7f7f893
Update play.py
Mr-Medina 1494585
Update attitude_model.py
Mr-Medina a18cd6a
changed translation= to default False, Euler angle function is redund…
Mr-Medina 195c28e
model "v3" works with constant angular velocity, breaks after certain…
Mr-Medina 967b177
set_attitude_model: added correct arguments
Mr-Medina 376a565
own test file
Mr-Medina 0c90588
Attitude model now correctly models attitude with constant angular ve…
Mr-Medina 78594d0
Needs to be fixed: with z angular velocity, roll is introduced
Mr-Medina fc3a857
different transformation matrix (roll pitch yaw angles are not the sa…
Mr-Medina 0a537a7
one rotation (depending on the transformation sequence in body_to_rpy…
Mr-Medina 3d4b351
Model works with constant angular velocity input, outputs correct poi…
Mr-Medina 7f6f144
minor adjustments normalizing input pointing vector, todo added
Mr-Medina 6f7c781
minor adjustments normalizing input pointing vector, sign fixed
Mr-Medina 816f155
use rodriguez rotations instead of reference frame rotations (this do…
Mr-Medina 4b1e5d3
added rodriguez rotation function
Mr-Medina aba8df1
implemented rodriguez rotation for both rotations of the body frame
Mr-Medina 0b444dd
body to rpy convention: yaw - pitch - roll. transformation functions …
Mr-Medina 4a5ebee
added function to get rpy angles, todo: perform actual body rotations…
Mr-Medina 270d859
Now model works with initial attitude specified, calculates attitude …
Mr-Medina 67864ff
Clean up code + added acceleration calculations (deleted possibility …
Mr-Medina 4a130b3
fixed problem where when pitch = 90 deg, it stays 90.
Mr-Medina d8b6abe
code cleanup, more comments, rodrigues instead of rodriguez, moved re…
Mr-Medina a68f04d
renamed play file to test attitude plotting
Mr-Medina 9e4b78d
attitude model pull request
Mr-Medina 724e9f5
Removed own test files for pr
Mr-Medina 6ce55d7
Added plotting file back to branch for visually checking attitude model
Mr-Medina 3633631
implemented some feedback
Mr-Medina 5fe2dc3
Merge branch 'attitude-model' into Attitude_pointing
Moanalengkeek ff93e5f
Merge pull request #194 from Mr-Medina/Attitude_pointing
Moanalengkeek db97bd7
Implemented geometric model, angular velocity vector is also possible…
Mr-Medina 0f68861
visual test for attitude plotting cleaned up a bit
Mr-Medina 64b1ece
pull request #198 feedback
Mr-Medina 28c55de
pull request #198 feedback
Mr-Medina b645b3b
pull request #198 feedback
Mr-Medina 612b3b2
pull request #198 feedback
Mr-Medina d818d3f
Apply suggestions from code review
Mr-Medina 71c3f50
Apply suggestions from code review
Mr-Medina 7dd542b
Apply suggestions from code review
Mr-Medina aa21573
Apply suggestion from code review
Mr-Medina 55b6443
Apply suggestion from code review
Mr-Medina 50ceeac
Fixed time discrepancies of model. both rotations now applied at corr…
Mr-Medina 428a75e
formatting
Mr-Medina 9732308
Attitude model also runs without set_disturbances (for test file)
Mr-Medina 7b6db6d
Added two tests, one for attitude model with known angular velocity, …
Moanalengkeek 11eb784
setting disturbances when no disturbances used.
Mr-Medina 8b1d525
Added additional test to confirm conditions after 1 orbit are initial…
Moanalengkeek 0a66921
Merge remote-tracking branch 'origin/attitude-model' into attitude-model
Mr-Medina f0522e4
added attitude tests
Mr-Medina ddf1006
Detele file for pr
Mr-Medina 536f606
Commenting
Mr-Medina 5a3dbc2
Merge remote-tracking branch 'origin/student' into attitude-model
Mr-Medina ac935cc
attitude model bug with geometric model interaction fixed
Mr-Medina 747a270
Apply suggestion from code review
Mr-Medina 4240289
made functions in attitude model internal
Mr-Medina dee082b
made functions in attitude model internal
Mr-Medina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
"""Tests to see whether the attitude and disturbance models work as intended""" | ||
|
||
import numpy as np | ||
import pykep as pk | ||
import sys | ||
|
||
sys.path.append("../..") | ||
import paseos | ||
from paseos import ActorBuilder, SpacecraftActor | ||
|
||
|
||
def attitude_model_test(): | ||
"""Testing the attitude model with no disturbances and known angular velocity. | ||
One actor has orbit in Earth inertial x-y plane (equatorial) with initial velocity which rotates the actor with 180° | ||
in 20 steps advancing time 100 seconds (pi/ (20 * 100)). | ||
Another one has zero initial angular velocity. | ||
This test mainly checks whether the model correctly models constant angular velocity without disturbances | ||
""" | ||
|
||
earth = pk.planet.jpl_lp("earth") | ||
|
||
# First actor constant angular acceleration | ||
omega = np.pi/2000 | ||
|
||
# Define first local actor with angular velocity | ||
sat1 = ActorBuilder.get_actor_scaffold("sat1", SpacecraftActor, pk.epoch(0)) | ||
ActorBuilder.set_orbit(sat1, [7000000, 0, 0], [0, 8000.0, 0], pk.epoch(0), earth) | ||
ActorBuilder.set_geometric_model(sat1, mass=100) | ||
ActorBuilder.set_attitude_model( | ||
sat1, | ||
actor_initial_angular_velocity=[0.0, omega, 0.0], | ||
actor_pointing_vector_body=[0, 0, 1], | ||
) | ||
|
||
# Define second local actor without angular velocity | ||
sat2 = ActorBuilder.get_actor_scaffold("sat2", SpacecraftActor, pk.epoch(0)) | ||
ActorBuilder.set_orbit(sat2, [7000000, 0, 0], [0, 8000.0, 0], pk.epoch(0), earth) | ||
ActorBuilder.set_geometric_model(sat2, mass=100) | ||
ActorBuilder.set_attitude_model( | ||
sat2, | ||
actor_initial_angular_velocity=[0.0, 0.0, 0.0], | ||
actor_pointing_vector_body=[0, 0, 1], | ||
) | ||
|
||
# Check Initial values | ||
|
||
# sat1 | ||
assert np.all(sat1._attitude_model._actor_pointing_vector_body == [0.0, 0.0, 1.0]) | ||
assert np.all(sat1._attitude_model._actor_pointing_vector_eci == [-1.0, 0.0, 0.0]) | ||
assert np.all(sat1._attitude_model._actor_attitude_in_rad == [0.0, 0.0, 0.0]) | ||
# positive angular velocity in body y direction is negative angular velocity in Earth inertial z direction: | ||
assert np.all(sat1._attitude_model._actor_angular_velocity_eci == [0.0, 0.0, -omega]) | ||
|
||
# sat2 | ||
assert np.all(sat2._attitude_model._actor_pointing_vector_body == [0.0, 0.0, 1.0]) | ||
assert np.all(sat2._attitude_model._actor_pointing_vector_eci == [-1.0, 0.0, 0.0]) | ||
assert np.all(sat2._attitude_model._actor_attitude_in_rad == [0.0, 0.0, 0.0]) | ||
|
||
# Initialise simulation | ||
sim = paseos.init_sim(sat1) | ||
sim.add_known_actor(sat2) | ||
# Run simulation 20 steps | ||
for i in range(20): | ||
sim.advance_time(100, 0) | ||
|
||
# Testing the simulation went as intended | ||
# Pointing vector from sat1 must be rotated from [-1, 0, 0] to [1, 0, 0]: | ||
assert np.all(np.isclose(sat1.pointing_vector(), np.array([1.0, 0.0, 0.0]))) | ||
# Sat1 angular velocity in the body frame must stay constant: | ||
assert np.all( | ||
np.isclose( | ||
sat1._attitude_model._actor_angular_velocity, | ||
np.array([0.0, omega, 0.0]), | ||
) | ||
) | ||
# Sat1 angular velocity in the Earth inertial frame must stay constant: | ||
assert np.all( | ||
np.isclose( | ||
sat1.angular_velocity(), | ||
np.array([0.0, 0.0, -omega]), | ||
) | ||
) | ||
|
||
# Pointing vector from sat2 must not be rotated. | ||
assert np.all(sat2.pointing_vector() == np.array([-1.0, 0.0, 0.0])) | ||
# Sat2 angular velocity in the body frame must stay zero: | ||
assert np.all(sat2._attitude_model._actor_angular_velocity == np.array([0.0, 0.0, 0.0])) | ||
|
||
|
||
def attitude_thermal_model_test(): | ||
"""Testing the attitude model with no disturbances and no angular velocity, and ensuring the attitude model doesn't | ||
break the thermal model (or vice versa)""" | ||
earth = pk.planet.jpl_lp("earth") | ||
|
||
# Define local actor | ||
sat1 = ActorBuilder.get_actor_scaffold("sat1", SpacecraftActor, pk.epoch(0)) | ||
ActorBuilder.set_orbit(sat1, [7000000, 0, 0], [0, 8000.0, 0], pk.epoch(0), earth) | ||
ActorBuilder.set_geometric_model(sat1, mass=100) | ||
ActorBuilder.set_thermal_model( | ||
actor=sat1, | ||
actor_mass=sat1.mass, | ||
actor_initial_temperature_in_K=273.15, | ||
actor_sun_absorptance=1.0, | ||
actor_infrared_absorptance=1.0, | ||
actor_sun_facing_area=1.0, | ||
actor_central_body_facing_area=1.0, | ||
actor_emissive_area=1.0, | ||
actor_thermal_capacity=1000, | ||
) | ||
ActorBuilder.set_attitude_model(sat1, actor_pointing_vector_body=[0, 0, 1]) | ||
|
||
# Check Initial values | ||
assert np.all(sat1._attitude_model._actor_pointing_vector_body == [0.0, 0.0, 1.0]) | ||
assert np.all(sat1._attitude_model._actor_attitude_in_rad == [0.0, 0.0, 0.0]) | ||
assert sat1.temperature_in_K == 273.15 | ||
|
||
# Initialise simulation | ||
sim = paseos.init_sim(sat1) | ||
|
||
# Run simulation 20 steps | ||
for i in range(21): | ||
vector = sat1.pointing_vector() | ||
sim.advance_time(100, 0) | ||
|
||
# Testing the simulation went as intended | ||
assert vector[0] == -1.0 | ||
assert sat1._attitude_model._actor_angular_velocity[1] == 0.0 | ||
assert np.round(sat1._attitude_model._actor_attitude_in_rad[0], 3) == 3.142 | ||
assert np.round(sat1.temperature_in_K, 3) == 278.522 | ||
|
||
|
||
def attitude_and_orbit_test(): | ||
"""This test checks both the orbit calculations, as well as the attitude. | ||
The input is a simple orbit, and the angular velocity if 2pi/period. This means the initial conditions should be | ||
the same as the conditions after one orbit""" | ||
|
||
earth = pk.planet.jpl_lp("earth") | ||
|
||
# Define local actor | ||
sat1 = ActorBuilder.get_actor_scaffold("sat1", SpacecraftActor, pk.epoch(0)) | ||
ActorBuilder.set_orbit(sat1, [7000000, 0, 0], [0, 5460.0, 0], pk.epoch(0), earth) | ||
ActorBuilder.set_geometric_model(sat1, mass=100) | ||
orbit_period = 2 * np.pi * np.sqrt((6371000 + 7000000) ** 3 / 3.986004418e14) | ||
ActorBuilder.set_attitude_model( | ||
sat1, | ||
actor_initial_angular_velocity=[0.0, 2 * np.pi / orbit_period, 0.0], | ||
actor_pointing_vector_body=[0, 0, 1], | ||
) | ||
ActorBuilder.set_disturbances(sat1) | ||
|
||
# Check Initial values | ||
assert np.all(sat1._attitude_model._actor_pointing_vector_body == [0.0, 0.0, 1.0]) | ||
assert np.all(sat1._attitude_model._actor_attitude_in_rad == [0.0, 0.0, 0.0]) | ||
vector = sat1.pointing_vector() | ||
assert vector[0] == -1.0 | ||
|
||
# Initialise simulation | ||
sim = paseos.init_sim(sat1) | ||
|
||
# Run simulation 10 steps | ||
for i in range(11): | ||
vector = sat1.pointing_vector() | ||
sim.advance_time(orbit_period / 10, 0) | ||
|
||
# Testing the simulation went as intended | ||
assert sat1._attitude_model._actor_pointing_vector_body[2] == 1.0 | ||
assert vector[0] == -1.0 | ||
|
||
|
||
attitude_model_test() | ||
Mr-Medina marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you check with the others what is supposed to happen when all disturbances are set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will add seperate disturbance tests in this file for every disturbance. This line could be deleted.