Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rocketpy/simulation/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/simulation/test_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)