Skip to content

Conversation

Copy link

Copilot AI commented Dec 2, 2025

Pull request type

  • Code changes (bugfix, features)

Checklist

  • Tests for the changes have been added (if needed)
  • Docs have been reviewed and added / updated
  • Lint (black rocketpy/ tests/) has passed locally
  • All tests (pytest tests -m slow --runslow) have passed locally
  • CHANGELOG.md has been updated (if relevant)

Current behavior

When a Flight has controllers (e.g., AirBrakes), max_acceleration_power_off_time always returns 0.0 and max_acceleration_power_off returns 0.0 m/s².

flight.max_acceleration_power_off_time  # Returns 0.0 (wrong)
flight.max_acceleration_power_off       # Returns 0.0 (wrong)

Root cause: np.argmax() on sliced array self.acceleration[burn_out_time_index:, 1] returns index relative to the slice, but the code uses this index directly on the full array.

New behavior

Returns correct time and acceleration values after motor burnout:

flight.max_acceleration_power_off_time  # Returns actual time (e.g., 3.9s)
flight.max_acceleration_power_off       # Returns actual acceleration

Fix in max_acceleration_power_off_time:

# Before
return self.acceleration[max_acceleration_time_index, 0]

# After  
return self.acceleration[burn_out_time_index + max_acceleration_time_index, 0]

Breaking change

  • No

Additional information

Fixes #803

Original prompt

This section details on the original issue you should resolve

<issue_title>BUG: Maximum acceleration values broken when airbrake is used</issue_title>
<issue_description>Describe the bug

When running any Flight with a Rocket containing an Airbrake, the maximum acceleration and G values are broken as follows:

  • "Maximum Acceleration During Motor Burn" is absurdly high (e.g. ~4000m/s²)
  • "Maximum Gs During Motor Burn" is absurdly high (e.g. ~400g)
  • "Maximum Acceleration After Motor Burn" is zero
  • "Maximum Gs After Motor Burn" is zero

To Reproduce

Given an existing RocketPy simulation (such as given in https://docs.rocketpy.org/en/latest/user/first_simulation.html), add an airbrake to the rocket with an "empty" airbrake controller function:

# The following code assumes env is the Environment used by the simulation

def airbrake_controller_function(
    time: float,
    sampling_rate: float,
    state_raw: list,
    state_history_raw: list,
    observed_variables: list,
    air_brakes: AirBrakes,
):
    air_brakes.deployment_level = 0.0
    wind_x: float = env.wind_velocity_x(state_raw[2])
    wind_y: float = env.wind_velocity_y(state_raw[2])
    free_stream_speed = (
        (wind_x - state_raw[3]) ** 2 + (wind_y - state_raw[4] ** 2 + (state_raw[5]) ** 2
    ) ** 0.5
    mach_number = free_stream_speed / env.speed_of_sound(state_raw[2])
    return (
        time,
        air_brakes.deployment_level,
        air_brakes.drag_coefficient(air_brakes.deployment_level, mach_number),
    )
    
rocket.add_air_brakes(
    drag_coefficient_curve="airbrake_drag_curve.csv", # Note that you need to provide that file in the same folder
    controller_function=airbrake_controller_function,
    sampling_rate=10,
    clamp=True,
)

Here is an example drag curve file in .csv format (store it as "airbrake_drag_curve.csv"):

0.0, 0.1, 0.0
0.0, 0.95, 0.0
1.0, 0.1728, 0.37
1.0, 0.5, 0.37
1.0, 0.6, 0.39
1.0, 0.7, 0.53
1.0, 0.8, 0.7
1.0, 0.9, 1.08
1.0, 0.95, 1.1

After running the simulation, call flight.prints.all() and observe the output.

Expected behavior

(tested with a sounding rocket in development by BEARS e.V.) / without Airbrake added

Maximum Values

Maximum Speed: 311.570 m/s at 1.82 s
Maximum Mach Number: 0.920 Mach at 1.82 s
Maximum Reynolds Number: 2.556e+06 at 1.79 s
Maximum Dynamic Pressure: 5.721e+04 Pa at 1.79 s
Maximum Acceleration During Motor Burn: 191.146 m/s² at 0.73 s
Maximum Gs During Motor Burn: 19.491 g at 0.73 s
Maximum Acceleration After Motor Burn: 11.323 m/s² at 14.41 s
Maximum Gs After Motor Burn: 1.155 Gs at 14.41 s
Maximum Stability Margin: 3.157 c at 1.85 s
Maximum Upper Rail Button Normal Force: 0.000 N
Maximum Upper Rail Button Shear Force: 0.000 N
Maximum Lower Rail Button Normal Force: 0.000 N
Maximum Lower Rail Button Shear Force: 0.000 N

Observed behavior

(tested with a sounding rocket in development by BEARS e.V.) / with Airbrake added but zero deployment

Maximum Values

Maximum Speed: 311.663 m/s at 1.81 s
Maximum Mach Number: 0.920 Mach at 1.81 s
Maximum Reynolds Number: 2.556e+06 at 1.80 s
Maximum Dynamic Pressure: 5.723e+04 Pa at 1.80 s
Maximum Acceleration During Motor Burn: 3893.683 m/s² at 1.83 s
Maximum Gs During Motor Burn: 397.045 g at 1.83 s
Maximum Acceleration After Motor Burn: 0.000 m/s² at 0.00 s
Maximum Gs After Motor Burn: 0.000 Gs at 0.00 s
Maximum Stability Margin: 3.157 c at 1.83 s
Maximum Upper Rail Button Normal Force: 0.000 N
Maximum Upper Rail Button Shear Force: 0.000 N
Maximum Lower Rail Button Normal Force: 0.000 N
Maximum Lower Rail Button Shear Force: 0.000 N

Notice how the output maximum acceleration is absurdly high during motor burn and is zero after motor burn (despite parachutes deploying at some point etc.). The flight otherwise performs the same (apogee and everything else is identical).

Additional context

Tested in RocketPy 1.10.0.

The issue does not appear when no Airbrake is configured.
</issue_description>

<agent_instructions>Please investigate, make a plan, and try to find where the BUG is</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@Gui-FernandesBR @MateusStano

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix maximum acceleration values when airbrake is used Fix max_acceleration_power_off_time returning 0 when controllers are present Dec 2, 2025
Copilot AI requested a review from Gui-FernandesBR December 2, 2025 13:52
@Gui-FernandesBR Gui-FernandesBR force-pushed the copilot/fix-maximum-acceleration-values branch from 043ad9c to 5b348c0 Compare December 2, 2025 13:55
@codecov
Copy link

codecov bot commented Dec 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.08%. Comparing base (9cf3dd4) to head (5e75f46).
⚠️ Report is 24 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #898      +/-   ##
===========================================
+ Coverage    80.27%   81.08%   +0.80%     
===========================================
  Files          104      107       +3     
  Lines        12769    13812    +1043     
===========================================
+ Hits         10250    11199     +949     
- Misses        2519     2613      +94     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Gui-FernandesBR Gui-FernandesBR force-pushed the copilot/fix-maximum-acceleration-values branch 2 times, most recently from 7b69d46 to 5d8e855 Compare December 8, 2025 12:38
@Gui-FernandesBR Gui-FernandesBR marked this pull request as ready for review December 8, 2025 12:39
@Gui-FernandesBR Gui-FernandesBR requested a review from a team as a code owner December 8, 2025 12:39
@Gui-FernandesBR Gui-FernandesBR force-pushed the copilot/fix-maximum-acceleration-values branch from 5d8e855 to 5e75f46 Compare December 9, 2025 00:25
@Gui-FernandesBR Gui-FernandesBR linked an issue Dec 9, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Backlog

Development

Successfully merging this pull request may close these issues.

BUG: Maximum acceleration values broken when airbrake is used

2 participants