ENH: Improve Stability Margin with Angle of Attack Dependency#899
Draft
ENH: Improve Stability Margin with Angle of Attack Dependency#899
Conversation
Copilot
AI
changed the title
[WIP] Enhance stability margin calculation in Flight class
ENH: Improve Stability Margin with Angle of Attack Dependency
Dec 2, 2025
1898cb3 to
0dff1a7
Compare
Codecov Report❌ Patch coverage is
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 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Comment on lines
+3124
to
+3694
| aoa_values = self.angle_of_attack.y_array | ||
| mach_values = self.mach_number.y_array | ||
| time_values = self.time | ||
|
|
||
| results = [] | ||
| for i, t in enumerate(time_values): | ||
| # Convert angle of attack from degrees to radians | ||
| alpha_rad = np.deg2rad(aoa_values[i]) | ||
| mach = mach_values[i] | ||
| sm = self.rocket.get_stability_margin_from_alpha(alpha_rad, mach, t) | ||
| results.append((t, sm)) | ||
|
|
||
| return results |
0dff1a7 to
d1e1a42
Compare
Add new methods to compute center of pressure and stability margin as a function of angle of attack (α) instead of just using the lift coefficient derivative. This provides a more accurate stability margin that varies with angle of attack, similar to OpenRocket. - Add Rocket.get_cp_position_from_alpha(alpha, mach) method - Add Rocket.get_stability_margin_from_alpha(alpha, mach, time) method - Update Flight.stability_margin to use angle of attack from simulation - Add tests for new functionality Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com>
- Add comment explaining degrees to radians conversion in Flight.stability_margin - Replace magic number 1e-10 with named constant epsilon in get_cp_position_from_alpha Co-authored-by: Gui-FernandesBR <63590233+Gui-FernandesBR@users.noreply.github.com>
d1e1a42 to
581ad7a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request type
Checklist
black rocketpy/ tests/) has passed locallypytest tests -m slow --runslow) have passed locallyCHANGELOG.mdhas been updated (if relevant)Current behavior
Stability margin uses CN_α (lift coefficient derivative) to compute center of pressure:
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:
New methods in
Rocketclass:get_cp_position_from_alpha(alpha, mach)- computes CP as function of AoA and Machget_stability_margin_from_alpha(alpha, mach, time)- computes stability margin using AoA-dependent CPUpdated in
Flightclass:stability_marginnow uses simulation's angle of attack dataNote: 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
Additional information
References:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.