diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index a139a84ee..722cff9ec 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -3159,7 +3159,7 @@ def max_acceleration_power_off_time(self): max_acceleration_time_index = np.argmax( self.acceleration[burn_out_time_index:, 1] ) - return self.acceleration[max_acceleration_time_index, 0] + return self.acceleration[burn_out_time_index + max_acceleration_time_index, 0] @cached_property def max_acceleration_power_off(self): diff --git a/tests/unit/simulation/test_flight.py b/tests/unit/simulation/test_flight.py index a54c5afdb..9af1c5fd5 100644 --- a/tests/unit/simulation/test_flight.py +++ b/tests/unit/simulation/test_flight.py @@ -659,3 +659,35 @@ def test_stability_static_margins( assert np.all(moments / wind_sign <= 0) else: # static_margin == 0 assert np.all(np.abs(moments) <= 1e-10) + + +def test_max_acceleration_power_off_time_with_controllers( + flight_calisto_air_brakes, +): + """Test that max_acceleration_power_off_time returns a valid time when + controllers are present (e.g., air brakes). This is a regression test for + a bug where the time was always returned as 0.0. + + Parameters + ---------- + flight_calisto_air_brakes : rocketpy.Flight + Flight object with air brakes. See the conftest.py file for more info + regarding this pytest fixture. + """ + test = flight_calisto_air_brakes + burn_out_time = test.rocket.motor.burn_out_time + + # The max_acceleration_power_off_time should be at or after motor burn out + # It should NOT be 0.0, which was the bug behavior + assert test.max_acceleration_power_off_time > 0, ( + "max_acceleration_power_off_time should not be zero" + ) + assert test.max_acceleration_power_off_time >= burn_out_time - 0.01, ( + f"max_acceleration_power_off_time ({test.max_acceleration_power_off_time}) " + f"should be at or after burn_out_time ({burn_out_time})" + ) + + # Also verify max_acceleration_power_off is positive + assert test.max_acceleration_power_off > 0, ( + "max_acceleration_power_off should be greater than zero" + )