Skip to content

Commit 5e75f46

Browse files
Fix incorrect indexing in max_acceleration_power_off_time
Co-authored-by: Gui-FernandesBR <[email protected]>
1 parent 45a891e commit 5e75f46

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

rocketpy/simulation/flight.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3159,7 +3159,7 @@ def max_acceleration_power_off_time(self):
31593159
max_acceleration_time_index = np.argmax(
31603160
self.acceleration[burn_out_time_index:, 1]
31613161
)
3162-
return self.acceleration[max_acceleration_time_index, 0]
3162+
return self.acceleration[burn_out_time_index + max_acceleration_time_index, 0]
31633163

31643164
@cached_property
31653165
def max_acceleration_power_off(self):

tests/unit/simulation/test_flight.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,35 @@ def test_stability_static_margins(
659659
assert np.all(moments / wind_sign <= 0)
660660
else: # static_margin == 0
661661
assert np.all(np.abs(moments) <= 1e-10)
662+
663+
664+
def test_max_acceleration_power_off_time_with_controllers(
665+
flight_calisto_air_brakes,
666+
):
667+
"""Test that max_acceleration_power_off_time returns a valid time when
668+
controllers are present (e.g., air brakes). This is a regression test for
669+
a bug where the time was always returned as 0.0.
670+
671+
Parameters
672+
----------
673+
flight_calisto_air_brakes : rocketpy.Flight
674+
Flight object with air brakes. See the conftest.py file for more info
675+
regarding this pytest fixture.
676+
"""
677+
test = flight_calisto_air_brakes
678+
burn_out_time = test.rocket.motor.burn_out_time
679+
680+
# The max_acceleration_power_off_time should be at or after motor burn out
681+
# It should NOT be 0.0, which was the bug behavior
682+
assert test.max_acceleration_power_off_time > 0, (
683+
"max_acceleration_power_off_time should not be zero"
684+
)
685+
assert test.max_acceleration_power_off_time >= burn_out_time - 0.01, (
686+
f"max_acceleration_power_off_time ({test.max_acceleration_power_off_time}) "
687+
f"should be at or after burn_out_time ({burn_out_time})"
688+
)
689+
690+
# Also verify max_acceleration_power_off is positive
691+
assert test.max_acceleration_power_off > 0, (
692+
"max_acceleration_power_off should be greater than zero"
693+
)

0 commit comments

Comments
 (0)