RocketPy icon indicating copy to clipboard operation
RocketPy copied to clipboard

ENH: Improve Stability Margin with Angle of Attack Dependency

Open Copilot opened this issue 4 weeks ago • 1 comments

Pull request type

  • [x] Code changes (bugfix, features)

Checklist

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

Current behavior

Stability margin uses CN_α (lift coefficient derivative) to compute center of pressure:

CP = Σ(CN_α × X_cp) / Σ(CN_α)

This produces a CP independent of angle of attack, unlike OpenRocket's more dynamic behavior.

New behavior

Stability margin now uses CN(α) (actual lift coefficient) for CP calculation:

CP = Σ(CN(α) × X_cp) / Σ(CN(α))

New methods in Rocket class:

  • get_cp_position_from_alpha(alpha, mach) - computes CP as function of AoA and Mach
  • get_stability_margin_from_alpha(alpha, mach, time) - computes stability margin using AoA-dependent CP

Updated in Flight class:

  • stability_margin now uses simulation's angle of attack data
# New methods available
cp = rocket.get_cp_position_from_alpha(alpha=0.1, mach=0.5)
sm = rocket.get_stability_margin_from_alpha(alpha=0.1, mach=0.5, time=2.0)

# Flight.stability_margin now accounts for AoA automatically
flight.stability_margin  # Uses actual AoA from simulation

Note: With current linear lift models (cl = clalpha * α), the α cancels mathematically. This change establishes the correct framework for future non-linear aerodynamic models (custom airfoils, wind tunnel data).

Breaking change

  • [x] No

Additional information

References:

  • https://openrocket.info/documentation.html
  • https://github.com/openrocket/openrocket
Original prompt

This section details on the original issue you should resolve

<issue_title>ENH: Improve Stability Margin</issue_title> <issue_description>Currently we use the rocket's total center of pressure to compute the stability margin of the Flight class.

Since this center of pressure is defined based on the normal force coefficient derivative with respect to the angle of attack (cnalpha) we end up with a curve that does not change with the angle of attack, as reported by user Eli [ARIS] (dvoeli05_67950) in our discord.

On RocketPy: Image

On OpenRocket: Image

As you can see, in OpenRocket the stability margin is much more "dynamic" than ours.

Describe the solution you'd like

In the Flight class, instead of using the angle of attack independent center of pressure for the stability margin calculations :

CP = \frac{  \sum (C_{N})_{\alpha} \cdot (X_{cp})_{\text{surface}}} {\sum (C_{N})_{\alpha}}

We should use a calculation that is dependent on alpha:

CP = \frac{  \sum C_{N}(\alpha) \cdot (X_{cp})_{\text{surface}}} {\sum C_{N}(\alpha) }

References:

  • https://openrocket.info/documentation.html
  • https://github.com/openrocket/openrocket</issue_description>

<agent_instructions>Please solve the issue described here.

Make a plan, find where in the code you're going to implement new changes. Then implement it following project guidelines.</agent_instructions>

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

  • Fixes RocketPy-Team/RocketPy#823

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Dec 02 '25 13:12 Copilot

Codecov Report

:x: Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review. :white_check_mark: Project coverage is 81.11%. Comparing base (9cf3dd4) to head (581ad7a). :warning: Report is 24 commits behind head on develop.

Files with missing lines Patch % Lines
rocketpy/rocket/rocket.py 95.00% 1 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #899      +/-   ##
===========================================
+ Coverage    80.27%   81.11%   +0.84%     
===========================================
  Files          104      107       +3     
  Lines        12769    13841    +1072     
===========================================
+ Hits         10250    11227     +977     
- Misses        2519     2614      +95     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Dec 02 '25 17:12 codecov[bot]