Skip to content

Commit d43a06b

Browse files
authored
BUG: Wrong Phi Initialization For nose_to_tail Rockets (#809)
* BUG: fix wrong phi initialization for nose_to_tail rockets * TST: add equivalence test for csys inversion * DEV: changelog * DEV: changelog * MNT: lint flight.py * TST: increase atol for MAC * TST: increase atol for MAC * TST: simplify test
1 parent ee23bc5 commit d43a06b

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Attention: The newest changes should be on top -->
4545

4646
- BUG: Fix the handling of reference pressure for older rpy files. [#808](https://github.com/RocketPy-Team/RocketPy/pull/808)
4747
- BUG: Non-overshootable simulations error on time parsing. [#807](https://github.com/RocketPy-Team/RocketPy/pull/807)
48+
- BUG: Wrong Phi Initialization For nose_to_tail Rockets [#809](https://github.com/RocketPy-Team/RocketPy/pull/809)
4849

4950
## v1.9.0 - 2025-03-24
5051

rocketpy/simulation/flight.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,9 @@ def __init_flight_state(self):
11561156
try:
11571157
self.phi_init += (
11581158
self.rocket.rail_buttons[0].component.angular_position_rad
1159-
* self.rocket._csys
1159+
if self.rocket._csys == 1
1160+
else 2 * np.pi
1161+
- self.rocket.rail_buttons[0].component.angular_position_rad
11601162
)
11611163
except IndexError:
11621164
pass
@@ -1277,7 +1279,7 @@ def __set_ode_solver(self, solver):
12771279
f"Invalid ``ode_solver`` input: {solver}. "
12781280
f"Available options are: {', '.join(ODE_SOLVER_MAP.keys())}"
12791281
) from e
1280-
1282+
12811283
self.__is_lsoda = issubclass(self._solver, LSODA)
12821284

12831285
@cached_property

tests/fixtures/flight/flight_fixtures.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ def flight_calisto_robust(calisto_robust, example_spaceport_env):
9393
)
9494

9595

96+
@pytest.fixture
97+
def flight_calisto_nose_to_tail_robust(
98+
calisto_nose_to_tail_robust, example_spaceport_env
99+
):
100+
return Flight(
101+
environment=example_spaceport_env,
102+
rocket=calisto_nose_to_tail_robust,
103+
rail_length=5.2,
104+
inclination=85,
105+
heading=0,
106+
terminate_on_apogee=False,
107+
)
108+
109+
96110
@pytest.fixture
97111
def flight_calisto_robust_solid_eom(calisto_robust, example_spaceport_env):
98112
"""Similar to flight_calisto_robust, but with the equations of motion set to

tests/fixtures/rockets/rocket_fixtures.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,33 @@ def calisto_robust(
184184
return calisto
185185

186186

187+
@pytest.fixture
188+
def calisto_nose_to_tail_robust(
189+
calisto_nose_to_tail,
190+
calisto_nose_cone,
191+
calisto_tail,
192+
calisto_trapezoidal_fins,
193+
calisto_main_chute,
194+
calisto_drogue_chute,
195+
):
196+
"""Calisto with nose to tail coordinate system orientation. This is the same
197+
as calisto_robust, but with the coordinate system orientation set to
198+
"nose_to_tail"."""
199+
csys = -1
200+
# we follow this format: calisto.add_surfaces(surface, position)
201+
calisto_nose_to_tail.add_surfaces(calisto_nose_cone, 1.160 * csys)
202+
calisto_nose_to_tail.add_surfaces(calisto_tail, -1.313 * csys)
203+
calisto_nose_to_tail.add_surfaces(calisto_trapezoidal_fins, -1.168 * csys)
204+
calisto_nose_to_tail.set_rail_buttons(
205+
upper_button_position=0.082 * csys,
206+
lower_button_position=-0.618 * csys,
207+
angular_position=360 - 0,
208+
)
209+
calisto_nose_to_tail.parachutes.append(calisto_main_chute)
210+
calisto_nose_to_tail.parachutes.append(calisto_drogue_chute)
211+
return calisto_nose_to_tail
212+
213+
187214
@pytest.fixture
188215
def calisto_air_brakes_clamp_on(calisto_robust, controller_function):
189216
"""Create an object class of the Rocket class to be used in the tests. This

tests/integration/test_flight.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,37 @@ def test_freestream_speed_at_apogee(example_plain_env, calisto):
521521
test_flight.free_stream_speed(test_flight.apogee_time), 0.0, atol=soft_atol
522522
)
523523
assert np.isclose(test_flight.apogee_freestream_speed, 0.0, atol=soft_atol)
524+
525+
526+
def test_rocket_csys_equivalence(
527+
flight_calisto_robust, flight_calisto_nose_to_tail_robust
528+
):
529+
"""Test the equivalence of the rocket coordinate systems between two
530+
different flight simulations.
531+
532+
Parameters
533+
----------
534+
flight_calisto_robust : rocketpy.Flight
535+
Flight object to be tested. See the conftest.py file for more info.
536+
flight_calisto_nose_to_tail_robust : rocketpy.Flight
537+
Flight object to be tested. See the conftest.py file for more info.
538+
"""
539+
assert np.isclose(
540+
flight_calisto_robust.apogee, flight_calisto_nose_to_tail_robust.apogee
541+
)
542+
assert np.isclose(
543+
flight_calisto_robust.apogee_time,
544+
flight_calisto_nose_to_tail_robust.apogee_time,
545+
)
546+
assert np.isclose(
547+
flight_calisto_robust.x_impact,
548+
flight_calisto_nose_to_tail_robust.x_impact,
549+
)
550+
assert np.isclose(
551+
flight_calisto_robust.y_impact,
552+
flight_calisto_nose_to_tail_robust.y_impact,
553+
)
554+
assert np.allclose(
555+
flight_calisto_robust.initial_solution,
556+
flight_calisto_nose_to_tail_robust.initial_solution,
557+
)

0 commit comments

Comments
 (0)