diff --git a/CHANGELOG.md b/CHANGELOG.md index e6d5fcf72..ee3c84968 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Attention: The newest changes should be on top --> - BUG: Fix the handling of reference pressure for older rpy files. [#808](https://github.com/RocketPy-Team/RocketPy/pull/808) - 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 diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 733835904..94e97fee4 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 @@ -1277,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 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..8fddb6486 100644 --- a/tests/integration/test_flight.py +++ b/tests/integration/test_flight.py @@ -521,3 +521,37 @@ 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.isclose( + flight_calisto_robust.apogee, flight_calisto_nose_to_tail_robust.apogee + ) + assert np.isclose( + flight_calisto_robust.apogee_time, + flight_calisto_nose_to_tail_robust.apogee_time, + ) + assert np.isclose( + flight_calisto_robust.x_impact, + flight_calisto_nose_to_tail_robust.x_impact, + ) + assert np.isclose( + flight_calisto_robust.y_impact, + flight_calisto_nose_to_tail_robust.y_impact, + ) + assert np.allclose( + flight_calisto_robust.initial_solution, + flight_calisto_nose_to_tail_robust.initial_solution, + )