Skip to content

Commit

Permalink
Merge pull request #50 from larshinueber/feature/update-interfaces
Browse files Browse the repository at this point in the history
Use recommended interfaces for body creation, result retrieval and imports
  • Loading branch information
DominicDirkx authored Sep 3, 2024
2 parents 7f88ddb + 163a735 commit d79bf8c
Show file tree
Hide file tree
Showing 42 changed files with 882 additions and 809 deletions.
105 changes: 57 additions & 48 deletions estimation/covariance_estimated_parameters.ipynb

Large diffs are not rendered by default.

44 changes: 23 additions & 21 deletions estimation/covariance_estimated_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
To create the systems of bodies for the simulation, one first has to define a list of strings of all bodies that are to be included. Note that the default body settings (such as atmosphere, body shape, rotation model) are taken from the `SPICE` kernel.
These settings, however, can be adjusted. Please refer to the [Available Environment Models](https://tudat-space.readthedocs.io/en/latest/_src_user_guide/state_propagation/environment_setup/create_models/available.html#available-environment-models) in the user guide for more details.
Finally, the system of bodies is created using the settings. This system of bodies is stored into the variable `bodies`.
"""

# Create default body settings for "Sun", "Earth", "Moon", "Mars", and "Venus"
Expand All @@ -82,37 +80,43 @@
body_settings = environment_setup.get_default_body_settings(
bodies_to_create, global_frame_origin, global_frame_orientation)

# Create system of bodies
bodies = environment_setup.create_system_of_bodies(body_settings)


### Create the vehicle and its environment interface
"""
We will now create the satellite - called Delfi-C3 - for which an orbit will be simulated. Using an `empty_body` as a blank canvas for the satellite, we define mass of 400kg, a reference area (used both for aerodynamic and radiation pressure) of 4m$^2$, and a aerodynamic drag coefficient of 1.2. Idem for the radiation pressure coefficient. Finally, when setting up the radiation pressure interface, the Earth is set as a body that can occult the radiation emitted by the Sun.
"""

# Create vehicle objects.
bodies.create_empty_body("Delfi-C3")
bodies.get("Delfi-C3").mass = 2.2
# Create empty body settings for the satellite
body_settings.add_empty_settings("Delfi-C3")

body_settings.get("Delfi-C3").constant_mass = 2.2

# Create aerodynamic coefficient interface settings
reference_area = (4*0.3*0.1+2*0.1*0.1)/4 # Average projection area of a 3U CubeSat
reference_area_drag = (4*0.3*0.1+2*0.1*0.1)/4 # Average projection area of a 3U CubeSat
drag_coefficient = 1.2
aero_coefficient_settings = environment_setup.aerodynamic_coefficients.constant(
reference_area, [drag_coefficient, 0.0, 0.0]
reference_area_drag, [drag_coefficient, 0.0, 0.0]
)
# Add the aerodynamic interface to the environment
environment_setup.add_aerodynamic_coefficient_interface(bodies, "Delfi-C3", aero_coefficient_settings)

# Add the aerodynamic interface to the body settings
body_settings.get("Delfi-C3").aerodynamic_coefficient_settings = aero_coefficient_settings

# Create radiation pressure settings
reference_area_radiation = (4*0.3*0.1+2*0.1*0.1)/4 # Average projection area of a 3U CubeSat
radiation_pressure_coefficient = 1.2
occulting_bodies = ["Earth"]
radiation_pressure_settings = environment_setup.radiation_pressure.cannonball(
"Sun", reference_area_radiation, radiation_pressure_coefficient, occulting_bodies
)
# Add the radiation pressure interface to the environment
environment_setup.add_radiation_pressure_interface(bodies, "Delfi-C3", radiation_pressure_settings)
occulting_bodies_dict = dict()
occulting_bodies_dict["Sun"] = ["Earth"]
vehicle_target_settings = environment_setup.radiation_pressure.cannonball_radiation_target(
reference_area_radiation, radiation_pressure_coefficient, occulting_bodies_dict )

# Add the radiation pressure interface to the body settings
body_settings.get("Delfi-C3").radiation_pressure_target_settings = vehicle_target_settings


# Finally, the system of bodies is created using the settings. This system of bodies is stored into the variable `bodies`.

# Create system of bodies
bodies = environment_setup.create_system_of_bodies(body_settings)


## Set up the propagation
Expand Down Expand Up @@ -147,7 +151,7 @@
# Define the accelerations acting on Delfi-C3
accelerations_settings_delfi_c3 = dict(
Sun=[
propagation_setup.acceleration.cannonball_radiation_pressure(),
propagation_setup.acceleration.radiation_pressure(),
propagation_setup.acceleration.point_mass_gravity()
],
Mars=[
Expand Down Expand Up @@ -350,8 +354,6 @@
bodies)


# <a id='covariance_section'></a>

## Perform the covariance analysis
"""
Having simulated the observations and created the `Estimator` object - containing the variational equations for the parameters to estimate - we have defined everything to conduct the actual estimation. Realise that up to this point, we have not yet specified whether we want to perform a covariance analysis or the full estimation of all parameters. It should be stressed that the general setup for either path to be followed is entirely identical.
Expand Down
53 changes: 19 additions & 34 deletions estimation/estimation_dynamical_models.ipynb

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions estimation/estimation_dynamical_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,24 @@
body_settings = environment_setup.get_default_body_settings(
bodies_to_create, global_frame_origin, global_frame_orientation)

# Create system of bodies
bodies = environment_setup.create_system_of_bodies(body_settings)

### VEHICLE BODY ###
# Create vehicle object
bodies.create_empty_body("MEX")
bodies.get("MEX").mass = 1000.0
body_settings.add_empty_settings("MEX")
body_settings.get("MEX").constant_mass = 1000.0

# Create radiation pressure settings
reference_area_radiation = (4*0.3*0.1+2*0.1*0.1)/4 # Average projection area of a 3U CubeSat
radiation_pressure_coefficient = 1.2
occulting_bodies = ["Mars"]
radiation_pressure_settings = environment_setup.radiation_pressure.cannonball(
"Sun", reference_area_radiation, radiation_pressure_coefficient, occulting_bodies
)
# Add the radiation pressure interface to the environment
environment_setup.add_radiation_pressure_interface(bodies, "MEX", radiation_pressure_settings)
occulting_bodies_dict = dict()
occulting_bodies_dict["Sun"] = ["Mars"]
vehicle_target_settings = environment_setup.radiation_pressure.cannonball_radiation_target(
reference_area_radiation, radiation_pressure_coefficient, occulting_bodies_dict )

# Add the radiation pressure interface to the body settings
body_settings.get("MEX").radiation_pressure_target_settings = vehicle_target_settings

# Create system of bodies
bodies = environment_setup.create_system_of_bodies(body_settings)

# Define bodies that are propagated
bodies_to_propagate = ["MEX"]
Expand Down Expand Up @@ -250,7 +251,7 @@
],
Sun=[
propagation_setup.acceleration.point_mass_gravity(),
propagation_setup.acceleration.cannonball_radiation_pressure()
propagation_setup.acceleration.radiation_pressure()
])


Expand Down Expand Up @@ -302,7 +303,7 @@
propagator_settings_simulation.processing_settings.set_integrated_result = True
# Run propagation
dynamics_simulator = create_dynamics_simulator(bodies, propagator_settings_simulation)
state_history_simulated_observations = dynamics_simulator.state_history
state_history_simulated_observations = dynamics_simulator.propagation_results.state_history

# Create observation simulators
observation_simulators = estimation_setup.create_observation_simulators(
Expand Down
54 changes: 27 additions & 27 deletions estimation/estimation_with_mpc.ipynb

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions estimation/estimation_with_mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
## Import statements
"""
# Tudat imports for propagation and estimation
from tudatpy.kernel.interface import spice
from tudatpy.kernel import numerical_simulation
from tudatpy.kernel.numerical_simulation import environment_setup
from tudatpy.kernel.numerical_simulation import propagation_setup
from tudatpy.kernel.numerical_simulation import estimation, estimation_setup
from tudatpy.kernel.numerical_simulation.estimation_setup import observation
from tudatpy.interface import spice
from tudatpy import numerical_simulation
from tudatpy.numerical_simulation import environment_setup
from tudatpy.numerical_simulation import propagation_setup
from tudatpy.numerical_simulation import estimation, estimation_setup
from tudatpy.numerical_simulation.estimation_setup import observation
"""

# import MPC interface
Expand Down Expand Up @@ -232,14 +232,14 @@
)

# Add random offset for initial guess
np.random.seed = 1
rng = np.random.default_rng(seed=1)

initial_position_offset = 1e6 * 1000
initial_velocity_offset = 100

initial_guess = initial_states.copy()
initial_guess[0:3] += (2 * np.random.rand(3) - 1) * initial_position_offset
initial_guess[3:6] += (2 * np.random.rand(3) - 1) * initial_velocity_offset
initial_guess[0:3] += (2 * rng.random(3) - 1) * initial_position_offset
initial_guess[3:6] += (2 * rng.random(3) - 1) * initial_velocity_offset

print("Error between the real initial state and our initial guess:")
print(initial_guess - initial_states)
Expand Down
Loading

0 comments on commit d79bf8c

Please sign in to comment.