From cd9daa1a962a881714bd9153d38246be2a42ca55 Mon Sep 17 00:00:00 2001 From: MateusStano Date: Mon, 21 Apr 2025 18:27:50 +0200 Subject: [PATCH 1/8] BUG: fix wrong phi initialization for nose_to_tail rockets --- rocketpy/simulation/flight.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 01778915b..18023ceab 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -1156,7 +1156,9 @@ def __init_flight_state(self): try: self.phi_init += ( self.rocket.rail_buttons[0].component.angular_position_rad - * self.rocket._csys + if self.rocket._csys == 1 + else 2 * np.pi + - self.rocket.rail_buttons[0].component.angular_position_rad ) except IndexError: pass From 53c5dea4f363df3593b6c3a9dfade1001e9f2adc Mon Sep 17 00:00:00 2001 From: MateusStano Date: Mon, 21 Apr 2025 18:28:08 +0200 Subject: [PATCH 2/8] TST: add equivalence test for csys inversion --- tests/fixtures/flight/flight_fixtures.py | 14 ++++++ tests/fixtures/rockets/rocket_fixtures.py | 27 ++++++++++++ tests/integration/test_flight.py | 54 +++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/tests/fixtures/flight/flight_fixtures.py b/tests/fixtures/flight/flight_fixtures.py index 44f8b7c09..da47e6cdb 100644 --- a/tests/fixtures/flight/flight_fixtures.py +++ b/tests/fixtures/flight/flight_fixtures.py @@ -93,6 +93,20 @@ def flight_calisto_robust(calisto_robust, example_spaceport_env): ) +@pytest.fixture +def flight_calisto_nose_to_tail_robust( + calisto_nose_to_tail_robust, example_spaceport_env +): + return Flight( + environment=example_spaceport_env, + rocket=calisto_nose_to_tail_robust, + rail_length=5.2, + inclination=85, + heading=0, + terminate_on_apogee=False, + ) + + @pytest.fixture def flight_calisto_robust_solid_eom(calisto_robust, example_spaceport_env): """Similar to flight_calisto_robust, but with the equations of motion set to diff --git a/tests/fixtures/rockets/rocket_fixtures.py b/tests/fixtures/rockets/rocket_fixtures.py index 8d26bbc22..9cb3caa3c 100644 --- a/tests/fixtures/rockets/rocket_fixtures.py +++ b/tests/fixtures/rockets/rocket_fixtures.py @@ -184,6 +184,33 @@ def calisto_robust( return calisto +@pytest.fixture +def calisto_nose_to_tail_robust( + calisto_nose_to_tail, + calisto_nose_cone, + calisto_tail, + calisto_trapezoidal_fins, + calisto_main_chute, + calisto_drogue_chute, +): + """Calisto with nose to tail coordinate system orientation. This is the same + as calisto_robust, but with the coordinate system orientation set to + "nose_to_tail".""" + csys = -1 + # we follow this format: calisto.add_surfaces(surface, position) + calisto_nose_to_tail.add_surfaces(calisto_nose_cone, 1.160 * csys) + calisto_nose_to_tail.add_surfaces(calisto_tail, -1.313 * csys) + calisto_nose_to_tail.add_surfaces(calisto_trapezoidal_fins, -1.168 * csys) + calisto_nose_to_tail.set_rail_buttons( + upper_button_position=0.082 * csys, + lower_button_position=-0.618 * csys, + angular_position=360 - 0, + ) + calisto_nose_to_tail.parachutes.append(calisto_main_chute) + calisto_nose_to_tail.parachutes.append(calisto_drogue_chute) + return calisto_nose_to_tail + + @pytest.fixture def calisto_air_brakes_clamp_on(calisto_robust, controller_function): """Create an object class of the Rocket class to be used in the tests. This diff --git a/tests/integration/test_flight.py b/tests/integration/test_flight.py index e1606ce75..afa9d586c 100644 --- a/tests/integration/test_flight.py +++ b/tests/integration/test_flight.py @@ -521,3 +521,57 @@ def test_freestream_speed_at_apogee(example_plain_env, calisto): test_flight.free_stream_speed(test_flight.apogee_time), 0.0, atol=soft_atol ) assert np.isclose(test_flight.apogee_freestream_speed, 0.0, atol=soft_atol) + + +def test_rocket_csys_equivalence( + flight_calisto_robust, flight_calisto_nose_to_tail_robust +): + """Test the equivalence of the rocket coordinate systems between two + different flight simulations. + + Parameters + ---------- + flight_calisto_robust : rocketpy.Flight + Flight object to be tested. See the conftest.py file for more info. + flight_calisto_nose_to_tail_robust : rocketpy.Flight + Flight object to be tested. See the conftest.py file for more info. + """ + assert np.allclose( + flight_calisto_robust.x[:, 0], flight_calisto_nose_to_tail_robust.x[:, 0] + ) + assert np.allclose( + flight_calisto_robust.y[:, 0], flight_calisto_nose_to_tail_robust.y[:, 0] + ) + assert np.allclose( + flight_calisto_robust.z[:, 0], flight_calisto_nose_to_tail_robust.z[:, 0] + ) + assert np.allclose( + flight_calisto_robust.vx[:, 0], flight_calisto_nose_to_tail_robust.vx[:, 0] + ) + assert np.allclose( + flight_calisto_robust.vy[:, 0], flight_calisto_nose_to_tail_robust.vy[:, 0] + ) + assert np.allclose( + flight_calisto_robust.vz[:, 0], flight_calisto_nose_to_tail_robust.vz[:, 0] + ) + assert np.allclose( + flight_calisto_robust.e0[:, 0], flight_calisto_nose_to_tail_robust.e0[:, 0] + ) + assert np.allclose( + flight_calisto_robust.e1[:, 0], flight_calisto_nose_to_tail_robust.e1[:, 0] + ) + assert np.allclose( + flight_calisto_robust.e2[:, 0], flight_calisto_nose_to_tail_robust.e2[:, 0] + ) + assert np.allclose( + flight_calisto_robust.e3[:, 0], flight_calisto_nose_to_tail_robust.e3[:, 0] + ) + assert np.allclose( + flight_calisto_robust.w1[:, 0], flight_calisto_nose_to_tail_robust.w1[:, 0] + ) + assert np.allclose( + flight_calisto_robust.w2[:, 0], flight_calisto_nose_to_tail_robust.w2[:, 0] + ) + assert np.allclose( + flight_calisto_robust.w3[:, 0], flight_calisto_nose_to_tail_robust.w3[:, 0] + ) From 3685afb5c9ec9e7830c1d719ce1ec68a91c91c7c Mon Sep 17 00:00:00 2001 From: MateusStano Date: Mon, 21 Apr 2025 18:42:55 +0200 Subject: [PATCH 3/8] DEV: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4b7a9fd2..6ad077367 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Attention: The newest changes should be on top --> ### Changed +- BUG: Wrong Phi Initialization For nose_to_tail Rockets [#809](https://github.com/RocketPy-Team/RocketPy/pull/809) ### Fixed From 3b9cf7a91ac54f67dc85a90b2643ca280b85a83e Mon Sep 17 00:00:00 2001 From: MateusStano <69485049+MateusStano@users.noreply.github.com> Date: Tue, 22 Apr 2025 12:20:06 +0200 Subject: [PATCH 4/8] DEV: changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94e980c7e..2e866c575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,10 +40,10 @@ Attention: The newest changes should be on top --> ### Changed -- BUG: Wrong Phi Initialization For nose_to_tail Rockets [#809](https://github.com/RocketPy-Team/RocketPy/pull/809) ### Fixed - BUG: Non-overshootable simulations error on time parsing. [#807](https://github.com/RocketPy-Team/RocketPy/pull/807) +- BUG: Wrong Phi Initialization For nose_to_tail Rockets [#809](https://github.com/RocketPy-Team/RocketPy/pull/809) ## v1.9.0 - 2025-03-24 From 84e8d208341d2ddcc4661f0d617a90fd9098df76 Mon Sep 17 00:00:00 2001 From: MateusStano Date: Tue, 22 Apr 2025 12:21:42 +0200 Subject: [PATCH 5/8] MNT: lint flight.py --- rocketpy/simulation/flight.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 6bd6043f3..94e97fee4 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -1279,7 +1279,7 @@ def __set_ode_solver(self, solver): f"Invalid ``ode_solver`` input: {solver}. " f"Available options are: {', '.join(ODE_SOLVER_MAP.keys())}" ) from e - + self.__is_lsoda = issubclass(self._solver, LSODA) @cached_property From 4c945e678c567849d82c7a9734922fe3d2b6a5a7 Mon Sep 17 00:00:00 2001 From: MateusStano Date: Tue, 22 Apr 2025 13:03:48 +0200 Subject: [PATCH 6/8] TST: increase atol for MAC --- tests/integration/test_flight.py | 52 ++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/tests/integration/test_flight.py b/tests/integration/test_flight.py index afa9d586c..7dd5f650d 100644 --- a/tests/integration/test_flight.py +++ b/tests/integration/test_flight.py @@ -537,41 +537,67 @@ def test_rocket_csys_equivalence( Flight object to be tested. See the conftest.py file for more info. """ assert np.allclose( - flight_calisto_robust.x[:, 0], flight_calisto_nose_to_tail_robust.x[:, 0] + flight_calisto_robust.x[:, 0], + flight_calisto_nose_to_tail_robust.x[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.y[:, 0], flight_calisto_nose_to_tail_robust.y[:, 0] + flight_calisto_robust.y[:, 0], + flight_calisto_nose_to_tail_robust.y[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.z[:, 0], flight_calisto_nose_to_tail_robust.z[:, 0] + flight_calisto_robust.z[:, 0], + flight_calisto_nose_to_tail_robust.z[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.vx[:, 0], flight_calisto_nose_to_tail_robust.vx[:, 0] + flight_calisto_robust.vx[:, 0], + flight_calisto_nose_to_tail_robust.vx[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.vy[:, 0], flight_calisto_nose_to_tail_robust.vy[:, 0] + flight_calisto_robust.vy[:, 0], + flight_calisto_nose_to_tail_robust.vy[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.vz[:, 0], flight_calisto_nose_to_tail_robust.vz[:, 0] + flight_calisto_robust.vz[:, 0], + flight_calisto_nose_to_tail_robust.vz[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.e0[:, 0], flight_calisto_nose_to_tail_robust.e0[:, 0] + flight_calisto_robust.e0[:, 0], + flight_calisto_nose_to_tail_robust.e0[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.e1[:, 0], flight_calisto_nose_to_tail_robust.e1[:, 0] + flight_calisto_robust.e1[:, 0], + flight_calisto_nose_to_tail_robust.e1[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.e2[:, 0], flight_calisto_nose_to_tail_robust.e2[:, 0] + flight_calisto_robust.e2[:, 0], + flight_calisto_nose_to_tail_robust.e2[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.e3[:, 0], flight_calisto_nose_to_tail_robust.e3[:, 0] + flight_calisto_robust.e3[:, 0], + flight_calisto_nose_to_tail_robust.e3[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.w1[:, 0], flight_calisto_nose_to_tail_robust.w1[:, 0] + flight_calisto_robust.w1[:, 0], + flight_calisto_nose_to_tail_robust.w1[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.w2[:, 0], flight_calisto_nose_to_tail_robust.w2[:, 0] + flight_calisto_robust.w2[:, 0], + flight_calisto_nose_to_tail_robust.w2[:, 0], + atol=1e-5, ) assert np.allclose( - flight_calisto_robust.w3[:, 0], flight_calisto_nose_to_tail_robust.w3[:, 0] + flight_calisto_robust.w3[:, 0], + flight_calisto_nose_to_tail_robust.w3[:, 0], + atol=1e-5, ) From 951b4a79edb5260270b58bfb3441f0135484c171 Mon Sep 17 00:00:00 2001 From: MateusStano Date: Tue, 22 Apr 2025 13:07:44 +0200 Subject: [PATCH 7/8] TST: increase atol for MAC --- tests/integration/test_flight.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/integration/test_flight.py b/tests/integration/test_flight.py index 7dd5f650d..9852c9b5a 100644 --- a/tests/integration/test_flight.py +++ b/tests/integration/test_flight.py @@ -539,65 +539,65 @@ def test_rocket_csys_equivalence( assert np.allclose( flight_calisto_robust.x[:, 0], flight_calisto_nose_to_tail_robust.x[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.y[:, 0], flight_calisto_nose_to_tail_robust.y[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.z[:, 0], flight_calisto_nose_to_tail_robust.z[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.vx[:, 0], flight_calisto_nose_to_tail_robust.vx[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.vy[:, 0], flight_calisto_nose_to_tail_robust.vy[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.vz[:, 0], flight_calisto_nose_to_tail_robust.vz[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.e0[:, 0], flight_calisto_nose_to_tail_robust.e0[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.e1[:, 0], flight_calisto_nose_to_tail_robust.e1[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.e2[:, 0], flight_calisto_nose_to_tail_robust.e2[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.e3[:, 0], flight_calisto_nose_to_tail_robust.e3[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.w1[:, 0], flight_calisto_nose_to_tail_robust.w1[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.w2[:, 0], flight_calisto_nose_to_tail_robust.w2[:, 0], - atol=1e-5, + atol=1e-3, ) assert np.allclose( flight_calisto_robust.w3[:, 0], flight_calisto_nose_to_tail_robust.w3[:, 0], - atol=1e-5, + atol=1e-3, ) From 4450829631ce5b2a9aec089d96dc1cc3f121179f Mon Sep 17 00:00:00 2001 From: MateusStano Date: Tue, 22 Apr 2025 14:40:07 +0200 Subject: [PATCH 8/8] TST: simplify test --- tests/integration/test_flight.py | 72 ++++++-------------------------- 1 file changed, 13 insertions(+), 59 deletions(-) diff --git a/tests/integration/test_flight.py b/tests/integration/test_flight.py index 9852c9b5a..8fddb6486 100644 --- a/tests/integration/test_flight.py +++ b/tests/integration/test_flight.py @@ -536,68 +536,22 @@ def test_rocket_csys_equivalence( flight_calisto_nose_to_tail_robust : rocketpy.Flight Flight object to be tested. See the conftest.py file for more info. """ - assert np.allclose( - flight_calisto_robust.x[:, 0], - flight_calisto_nose_to_tail_robust.x[:, 0], - atol=1e-3, - ) - assert np.allclose( - flight_calisto_robust.y[:, 0], - flight_calisto_nose_to_tail_robust.y[:, 0], - atol=1e-3, - ) - assert np.allclose( - flight_calisto_robust.z[:, 0], - flight_calisto_nose_to_tail_robust.z[:, 0], - atol=1e-3, - ) - assert np.allclose( - flight_calisto_robust.vx[:, 0], - flight_calisto_nose_to_tail_robust.vx[:, 0], - atol=1e-3, - ) - assert np.allclose( - flight_calisto_robust.vy[:, 0], - flight_calisto_nose_to_tail_robust.vy[:, 0], - atol=1e-3, - ) - assert np.allclose( - flight_calisto_robust.vz[:, 0], - flight_calisto_nose_to_tail_robust.vz[:, 0], - atol=1e-3, - ) - assert np.allclose( - flight_calisto_robust.e0[:, 0], - flight_calisto_nose_to_tail_robust.e0[:, 0], - atol=1e-3, - ) - assert np.allclose( - flight_calisto_robust.e1[:, 0], - flight_calisto_nose_to_tail_robust.e1[:, 0], - atol=1e-3, - ) - assert np.allclose( - flight_calisto_robust.e2[:, 0], - flight_calisto_nose_to_tail_robust.e2[:, 0], - atol=1e-3, + assert np.isclose( + flight_calisto_robust.apogee, flight_calisto_nose_to_tail_robust.apogee ) - assert np.allclose( - flight_calisto_robust.e3[:, 0], - flight_calisto_nose_to_tail_robust.e3[:, 0], - atol=1e-3, + assert np.isclose( + flight_calisto_robust.apogee_time, + flight_calisto_nose_to_tail_robust.apogee_time, ) - assert np.allclose( - flight_calisto_robust.w1[:, 0], - flight_calisto_nose_to_tail_robust.w1[:, 0], - atol=1e-3, + assert np.isclose( + flight_calisto_robust.x_impact, + flight_calisto_nose_to_tail_robust.x_impact, ) - assert np.allclose( - flight_calisto_robust.w2[:, 0], - flight_calisto_nose_to_tail_robust.w2[:, 0], - atol=1e-3, + assert np.isclose( + flight_calisto_robust.y_impact, + flight_calisto_nose_to_tail_robust.y_impact, ) assert np.allclose( - flight_calisto_robust.w3[:, 0], - flight_calisto_nose_to_tail_robust.w3[:, 0], - atol=1e-3, + flight_calisto_robust.initial_solution, + flight_calisto_nose_to_tail_robust.initial_solution, )