From eb97c1d6d5cd8b9e6f8046a70f5969eb0d6607e3 Mon Sep 17 00:00:00 2001 From: MateusStano Date: Fri, 16 Aug 2024 21:51:06 +0200 Subject: [PATCH 1/9] BUG: calculate moments wrt CDM --- rocketpy/simulation/flight.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 73bc715cb..7bf4d2af5 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -1503,8 +1503,8 @@ def u_dot( R1 += comp_lift_xb R2 += comp_lift_yb # Add to total moment - M1 -= (comp_cp + a) * comp_lift_yb - M2 += (comp_cp + a) * comp_lift_xb + M1 -= (comp_cp) * comp_lift_yb + M2 += (comp_cp) * comp_lift_xb # Calculates Roll Moment try: clf_delta, cld_omega, cant_angle_rad = aero_surface.roll_parameters @@ -1779,8 +1779,8 @@ def u_dot_generalized( R1 += comp_lift_xb R2 += comp_lift_yb # Add to total moment - M1 -= (comp_cpz + r_CM_t) * comp_lift_yb - M2 += (comp_cpz + r_CM_t) * comp_lift_xb + M1 -= (comp_cpz) * comp_lift_yb + M2 += (comp_cpz) * comp_lift_xb # Calculates Roll Moment try: clf_delta, cld_omega, cant_angle_rad = aero_surface.roll_parameters From 0673a3ef12420effbb4ce82f1eb6691d19e368cb Mon Sep 17 00:00:00 2001 From: MateusStano Date: Fri, 16 Aug 2024 21:51:19 +0200 Subject: [PATCH 2/9] BUG: calculate inertias wrt CDM --- rocketpy/rocket/rocket.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index 952390723..0ed62cc02 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -714,20 +714,20 @@ def evaluate_inertias(self): """ # Get masses prop_mass = self.motor.propellant_mass # Propellant mass as a function of time - dry_mass = self.dry_mass # Constant rocket mass with motor, without propellant # Compute axes distances - CM_to_CDM = self.center_of_mass - self.center_of_dry_mass_position - CM_to_CPM = self.center_of_mass - self.center_of_propellant_position + CDM_to_CPM = ( + self.center_of_dry_mass_position - self.center_of_propellant_position + ) # Compute inertias - self.I_11 = parallel_axis_theorem_from_com( - self.dry_I_11, dry_mass, CM_to_CDM - ) + parallel_axis_theorem_from_com(self.motor.I_11, prop_mass, CM_to_CPM) + self.I_11 = self.dry_I_11 + parallel_axis_theorem_from_com( + self.motor.I_11, prop_mass, CDM_to_CPM + ) - self.I_22 = parallel_axis_theorem_from_com( - self.dry_I_22, dry_mass, CM_to_CDM - ) + parallel_axis_theorem_from_com(self.motor.I_22, prop_mass, CM_to_CPM) + self.I_22 = self.dry_I_22 + parallel_axis_theorem_from_com( + self.motor.I_22, prop_mass, CDM_to_CPM + ) self.I_33 = self.dry_I_33 + self.motor.I_33 self.I_12 = self.dry_I_12 + self.motor.I_12 From 3cd297241ab0650559e27ed54e81793fb94da290 Mon Sep 17 00:00:00 2001 From: MateusStano Date: Sun, 18 Aug 2024 20:46:43 +0200 Subject: [PATCH 3/9] DOC: update and clarify inertia docs --- docs/user/rocket/rocket_usage.rst | 10 ++++++---- rocketpy/rocket/rocket.py | 28 ++++++++++++++-------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/docs/user/rocket/rocket_usage.rst b/docs/user/rocket/rocket_usage.rst index d25608dc7..5a4212187 100644 --- a/docs/user/rocket/rocket_usage.rst +++ b/docs/user/rocket/rocket_usage.rst @@ -41,6 +41,8 @@ and radius: Pay special attention to the following: - ``mass`` is the rocket's mass, **without the motor**, in kg. + - All ``inertia`` values are given in relation to the rocket's center of + mass without motor. - ``inertia`` is defined as a tuple of the form ``(I11, I22, I33)``. Where ``I11`` and ``I22`` are the inertia of the mass around the perpendicular axes to the rocket, and ``I33`` is the inertia around the @@ -432,10 +434,10 @@ The lets check all the information available about the rocket: 7. Inertia Tensors ------------------ -The inertia tensor of the rocket at a given time can be obtained using the -``get_inertia_tensor_at_time`` method. This method evaluates each component of -the inertia tensor at the specified time and returns a -:class:`rocketpy.mathutils.Matrix` object. +The inertia tensor in relation to the center of dry mass of the rocket at a +given time can be obtained using the ``get_inertia_tensor_at_time`` method. +This method evaluates each component of the inertia tensor at the specified +time and returns a :class:`rocketpy.mathutils.Matrix` object. The inertia tensor is a matrix that looks like this: diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index 0ed62cc02..12516e2e2 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -596,7 +596,7 @@ def evaluate_static_margin(self): def evaluate_dry_inertias(self): """Calculates and returns the rocket's dry inertias relative to - the rocket's center of mass. The inertias are saved and returned + the rocket's center of dry mass. The inertias are saved and returned in units of kg*m². This does not consider propellant mass but does take into account the motor dry mass. @@ -605,27 +605,27 @@ def evaluate_dry_inertias(self): self.dry_I_11 : float Float value corresponding to rocket inertia tensor 11 component, which corresponds to the inertia relative to the - e_1 axis, centered at the instantaneous center of mass. + e_1 axis, centered at the center of dry mass. self.dry_I_22 : float Float value corresponding to rocket inertia tensor 22 component, which corresponds to the inertia relative to the - e_2 axis, centered at the instantaneous center of mass. + e_2 axis, centered at the center of dry mass. self.dry_I_33 : float Float value corresponding to rocket inertia tensor 33 component, which corresponds to the inertia relative to the - e_3 axis, centered at the instantaneous center of mass. + e_3 axis, centered at the center of dry mass. self.dry_I_12 : float Float value corresponding to rocket inertia tensor 12 component, which corresponds to the inertia relative to the - e_1 and e_2 axes, centered at the instantaneous center of mass. + e_1 and e_2 axes, centered at the center of dry mass. self.dry_I_13 : float Float value corresponding to rocket inertia tensor 13 component, which corresponds to the inertia relative to the - e_1 and e_3 axes, centered at the instantaneous center of mass. + e_1 and e_3 axes, centered at the center of dry mass. self.dry_I_23 : float Float value corresponding to rocket inertia tensor 23 component, which corresponds to the inertia relative to the - e_2 and e_3 axes, centered at the instantaneous center of mass. + e_2 and e_3 axes, centered at the center of dry mass. Notes ----- @@ -681,7 +681,7 @@ def evaluate_dry_inertias(self): def evaluate_inertias(self): """Calculates and returns the rocket's inertias relative to - the rocket's center of mass. The inertias are saved and returned + the rocket's center of dry mass. The inertias are saved and returned in units of kg*m². Returns @@ -689,15 +689,15 @@ def evaluate_inertias(self): self.I_11 : float Float value corresponding to rocket inertia tensor 11 component, which corresponds to the inertia relative to the - e_1 axis, centered at the instantaneous center of mass. + e_1 axis, centered at the center of dry mass. self.I_22 : float Float value corresponding to rocket inertia tensor 22 component, which corresponds to the inertia relative to the - e_2 axis, centered at the instantaneous center of mass. + e_2 axis, centered at the center of dry mass. self.I_33 : float Float value corresponding to rocket inertia tensor 33 component, which corresponds to the inertia relative to the - e_3 axis, centered at the instantaneous center of mass. + e_3 axis, centered at the center of dry mass. Notes ----- @@ -814,7 +814,7 @@ def evaluate_com_to_cdm_function(self): def get_inertia_tensor_at_time(self, t): """Returns a Matrix representing the inertia tensor of the rocket with - respect to the rocket's center of mass at a given time. It evaluates + respect to the rocket's center of dry mass at a given time. It evaluates each inertia tensor component at the given time and returns a Matrix with the computed values. @@ -844,8 +844,8 @@ def get_inertia_tensor_at_time(self, t): def get_inertia_tensor_derivative_at_time(self, t): """Returns a Matrix representing the time derivative of the inertia - tensor of the rocket with respect to the rocket's center of mass at a - given time. It evaluates each inertia tensor component's derivative at + tensor of the rocket with respect to the rocket's center of dry mass at + a given time. It evaluates each inertia tensor component's derivative at the given time and returns a Matrix with the computed values. Parameters From 1e8b05858494e05382a55c5db73bf6614570da0e Mon Sep 17 00:00:00 2001 From: MateusStano Date: Sun, 18 Aug 2024 20:46:52 +0200 Subject: [PATCH 4/9] TST: tests --- tests/unit/test_flight.py | 21 ++++++++++++--------- tests/unit/test_rocket.py | 8 ++++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/unit/test_flight.py b/tests/unit/test_flight.py index cea54e575..3ee6d7637 100644 --- a/tests/unit/test_flight.py +++ b/tests/unit/test_flight.py @@ -167,9 +167,9 @@ def test_out_of_rail_stability_margin(flight_calisto_custom_wind): @pytest.mark.parametrize( "flight_time, expected_values", [ - ("t_initial", (0.17179073815516033, -0.431117, 0)), - ("out_of_rail_time", (0.543760, -1.364593, 0)), - ("apogee_time", (-0.5874848151271623, -0.7563596, 0)), + ("t_initial", (0.258818, -0.649515, 0)), + ("out_of_rail_time", (0.788918, -1.979828, 0)), + ("apogee_time", (-0.531829, -0.754103, 0)), ("t_final", (0, 0, 0)), ], ) @@ -208,7 +208,7 @@ def test_aerodynamic_moments(flight_calisto_custom_wind, flight_time, expected_v [ ("t_initial", (1.6542528, 0.65918, -0.067107)), ("out_of_rail_time", (5.05334, 2.01364, -1.7541)), - ("apogee_time", (2.366258, -1.830744, -0.875342)), + ("apogee_time", (2.378161, -1.677083, -0.933044)), ("t_final", (0, 0, 159.2212)), ], ) @@ -247,7 +247,10 @@ def test_aerodynamic_forces(flight_calisto_custom_wind, flight_time, expected_va [ ("t_initial", (0, 0, 0)), ("out_of_rail_time", (0, 2.248727, 25.703072)), - ("apogee_time", (-13.204789, 15.990903, -0.000138)), + ( + "apogee_time", + (-14.426265, 15.596488, -0.000254), + ), ("t_final", (5, 2, -5.65998)), ], ) @@ -334,10 +337,10 @@ def test_rail_buttons_forces(flight_calisto_custom_wind): """ test = flight_calisto_custom_wind atol = 5e-3 - assert pytest.approx(3.876749, abs=atol) == test.max_rail_button1_normal_force - assert pytest.approx(1.544799, abs=atol) == test.max_rail_button1_shear_force - assert pytest.approx(1.178420, abs=atol) == test.max_rail_button2_normal_force - assert pytest.approx(0.469574, abs=atol) == test.max_rail_button2_shear_force + assert pytest.approx(1.825283, abs=atol) == test.max_rail_button1_normal_force + assert pytest.approx(0.727335, abs=atol) == test.max_rail_button1_shear_force + assert pytest.approx(3.229578, abs=atol) == test.max_rail_button2_normal_force + assert pytest.approx(1.286915, abs=atol) == test.max_rail_button2_shear_force def test_max_values(flight_calisto_robust): diff --git a/tests/unit/test_rocket.py b/tests/unit/test_rocket.py index e36302c3e..75faa36af 100644 --- a/tests/unit/test_rocket.py +++ b/tests/unit/test_rocket.py @@ -458,8 +458,8 @@ def test_evaluate_com_to_cdm_function(calisto): def test_get_inertia_tensor_at_time(calisto): # Expected values (for t = 0) # TODO: compute these values by hand or using CAD. - I_11 = 10.31379 - I_22 = 10.31379 + I_11 = 10.64885 + I_22 = 10.64885 I_33 = 0.039942 # Set tolerance threshold @@ -484,8 +484,8 @@ def test_get_inertia_tensor_at_time(calisto): def test_get_inertia_tensor_derivative_at_time(calisto): # Expected values (for t = 2s) # TODO: compute these values by hand or using CAD. - I_11_dot = -0.634805230901143 - I_22_dot = -0.634805230901143 + I_11_dot = -0.718752566200817 + I_22_dot = -0.718752566200817 I_33_dot = -0.000671493662305 # Set tolerance threshold From 4ad4003adf53db43ea06615e6af6031e1d7d3faa Mon Sep 17 00:00:00 2001 From: MateusStano Date: Sun, 18 Aug 2024 21:28:57 +0200 Subject: [PATCH 5/9] MNT: pylint --- .pylintrc | 3 +-- rocketpy/simulation/flight.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index dbb2cb11d..2dddcb3bf 100644 --- a/.pylintrc +++ b/.pylintrc @@ -225,8 +225,7 @@ good-names=FlightPhases, motor_I_11_derivative_at_t, M3_forcing, M3_damping, - CM_to_CDM, - CM_to_CPM, + CDM_to_CPM, center_of_mass_without_motor_to_CDM, motor_center_of_dry_mass_to_CDM, generic_motor_cesaroni_M1520, diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 7bf4d2af5..d7e51a768 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -1400,7 +1400,6 @@ def u_dot( * self.rocket._csys ) c = self.rocket.nozzle_to_cdm - a = self.rocket.com_to_cdm_function.get_value_opt(t) nozzle_radius = self.rocket.motor.nozzle_radius # Prepare transformation matrix a11 = 1 - 2 * (e2**2 + e3**2) From edd24264577dd32e352d5237d1ad88d1607ae02b Mon Sep 17 00:00:00 2001 From: MateusStano Date: Tue, 20 Aug 2024 23:26:42 +0200 Subject: [PATCH 6/9] DEV: changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dced5f94c..d32298636 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,7 +42,7 @@ Attention: The newest changes should be on top --> ### Fixed - +- BUG: Rotational EOMs Not Relative To CDM [#674](https://github.com/RocketPy-Team/RocketPy/pull/674) ## [v1.4.2] - 2024-08-03 From 8da14258204b74e87178ba81aa20dfeedcf89550 Mon Sep 17 00:00:00 2001 From: MateusStano <69485049+MateusStano@users.noreply.github.com> Date: Fri, 23 Aug 2024 07:18:19 -0300 Subject: [PATCH 7/9] MNT: typos in rocket_usage.rst Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com> --- docs/user/rocket/rocket_usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user/rocket/rocket_usage.rst b/docs/user/rocket/rocket_usage.rst index 5a4212187..2604c60db 100644 --- a/docs/user/rocket/rocket_usage.rst +++ b/docs/user/rocket/rocket_usage.rst @@ -434,7 +434,7 @@ The lets check all the information available about the rocket: 7. Inertia Tensors ------------------ -The inertia tensor in relation to the center of dry mass of the rocket at a +The inertia tensor relative to the center of dry mass of the rocket at a given time can be obtained using the ``get_inertia_tensor_at_time`` method. This method evaluates each component of the inertia tensor at the specified time and returns a :class:`rocketpy.mathutils.Matrix` object. From 9eda7b371105ceccfbfecec271293ca554b8ebb6 Mon Sep 17 00:00:00 2001 From: MateusStano Date: Fri, 23 Aug 2024 12:19:01 +0200 Subject: [PATCH 8/9] BUG: Update rocket inertia calculations with propellant inertias instead of motor --- rocketpy/motors/motor.py | 6 ++++++ rocketpy/rocket/rocket.py | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/rocketpy/motors/motor.py b/rocketpy/motors/motor.py index 63b407ed8..b37172348 100644 --- a/rocketpy/motors/motor.py +++ b/rocketpy/motors/motor.py @@ -1352,6 +1352,12 @@ def __init__(self): self.dry_I_12 = 0 self.dry_I_13 = 0 self.dry_I_23 = 0 + self.propellant_I_11 = Function(0, "Time (s)", "Propellant I_11 (kg m²)") + self.propellant_I_22 = Function(0, "Time (s)", "Propellant I_22 (kg m²)") + self.propellant_I_33 = Function(0, "Time (s)", "Propellant I_33 (kg m²)") + self.propellant_I_12 = Function(0, "Time (s)", "Propellant I_12 (kg m²)") + self.propellant_I_13 = Function(0, "Time (s)", "Propellant I_13 (kg m²)") + self.propellant_I_23 = Function(0, "Time (s)", "Propellant I_23 (kg m²)") self.I_11 = Function(0) self.I_22 = Function(0) self.I_33 = Function(0) diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index 12516e2e2..0e3024ecf 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -722,17 +722,17 @@ def evaluate_inertias(self): # Compute inertias self.I_11 = self.dry_I_11 + parallel_axis_theorem_from_com( - self.motor.I_11, prop_mass, CDM_to_CPM + self.motor.propellant_I_11, prop_mass, CDM_to_CPM ) self.I_22 = self.dry_I_22 + parallel_axis_theorem_from_com( - self.motor.I_22, prop_mass, CDM_to_CPM + self.motor.propellant_I_22, prop_mass, CDM_to_CPM ) - self.I_33 = self.dry_I_33 + self.motor.I_33 - self.I_12 = self.dry_I_12 + self.motor.I_12 - self.I_13 = self.dry_I_13 + self.motor.I_13 - self.I_23 = self.dry_I_23 + self.motor.I_23 + self.I_33 = self.dry_I_33 + self.motor.propellant_I_33 + self.I_12 = self.dry_I_12 + self.motor.propellant_I_12 + self.I_13 = self.dry_I_13 + self.motor.propellant_I_13 + self.I_23 = self.dry_I_23 + self.motor.propellant_I_23 # Return inertias return ( From 3a4c742bf17b09610c78fc57e76293f44118eb9c Mon Sep 17 00:00:00 2001 From: MateusStano Date: Fri, 23 Aug 2024 12:33:53 +0200 Subject: [PATCH 9/9] TST: inertia values on tests --- tests/unit/test_flight.py | 6 +++--- tests/unit/test_rocket.py | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/unit/test_flight.py b/tests/unit/test_flight.py index 3ee6d7637..e5446966d 100644 --- a/tests/unit/test_flight.py +++ b/tests/unit/test_flight.py @@ -169,7 +169,7 @@ def test_out_of_rail_stability_margin(flight_calisto_custom_wind): [ ("t_initial", (0.258818, -0.649515, 0)), ("out_of_rail_time", (0.788918, -1.979828, 0)), - ("apogee_time", (-0.531829, -0.754103, 0)), + ("apogee_time", (-0.522394, -0.744154, 0)), ("t_final", (0, 0, 0)), ], ) @@ -208,7 +208,7 @@ def test_aerodynamic_moments(flight_calisto_custom_wind, flight_time, expected_v [ ("t_initial", (1.6542528, 0.65918, -0.067107)), ("out_of_rail_time", (5.05334, 2.01364, -1.7541)), - ("apogee_time", (2.378161, -1.677083, -0.933044)), + ("apogee_time", (2.354663, -1.652953, -0.936126)), ("t_final", (0, 0, 159.2212)), ], ) @@ -249,7 +249,7 @@ def test_aerodynamic_forces(flight_calisto_custom_wind, flight_time, expected_va ("out_of_rail_time", (0, 2.248727, 25.703072)), ( "apogee_time", - (-14.426265, 15.596488, -0.000254), + (-14.485655, 15.580647, -0.000240), ), ("t_final", (5, 2, -5.65998)), ], diff --git a/tests/unit/test_rocket.py b/tests/unit/test_rocket.py index 75faa36af..a0d9b79a3 100644 --- a/tests/unit/test_rocket.py +++ b/tests/unit/test_rocket.py @@ -458,9 +458,9 @@ def test_evaluate_com_to_cdm_function(calisto): def test_get_inertia_tensor_at_time(calisto): # Expected values (for t = 0) # TODO: compute these values by hand or using CAD. - I_11 = 10.64885 - I_22 = 10.64885 - I_33 = 0.039942 + I_11 = 10.516647727227216 + I_22 = 10.516647727227216 + I_33 = 0.0379420341586346 # Set tolerance threshold atol = 1e-5 @@ -484,9 +484,9 @@ def test_get_inertia_tensor_at_time(calisto): def test_get_inertia_tensor_derivative_at_time(calisto): # Expected values (for t = 2s) # TODO: compute these values by hand or using CAD. - I_11_dot = -0.718752566200817 - I_22_dot = -0.718752566200817 - I_33_dot = -0.000671493662305 + I_11_dot = -0.7164327431607691 + I_22_dot = -0.7164327431607691 + I_33_dot = -0.0006714936623050 # Set tolerance threshold atol = 1e-3