-
-
Notifications
You must be signed in to change notification settings - Fork 208
ENH: unstable rocket error #764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d64217b to
37c5505
Compare
2931c30 to
7864590
Compare
37c5505 to
e48a442
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #764 +/- ##
===========================================
+ Coverage 76.42% 80.11% +3.69%
===========================================
Files 95 96 +1
Lines 11090 11359 +269
===========================================
+ Hits 8475 9100 +625
+ Misses 2615 2259 -356 ☔ View full report in Codecov by Sentry. |
|
|
||
|
|
||
| class UnstableRocketError(RocketPyException): | ||
| """Raised when the rocket jas negative static margin.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has*
| def __validate_rocket_static_margin(self): | ||
| """ | ||
| Avoids running a flight simulation if the rocket stability margin is | ||
| negative. This is a common mistake that can lead to unstable flights, | ||
| which usually runs indefinitely. | ||
| """ | ||
| if (s := self.rocket.static_margin(0)) < 0: | ||
| raise UnstableRocketError(s) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this error check might not be suitable right now. I see a few points as to why:
-
If a user wants to simulate an unstable rocket, for any reason, we should not make that impossible. There could always be a rocket that has a negative static margin, but the stability margin could quickly become positive with fuel burn or other effects
-
When in monte carlo simulations, what would happen if one of the iterations has an unstable rocket? Will all the simulations break because of it?
-
The generic aerodynamic coefficients don't calculate static margin correctly. This essentially means that all rockets with custom coefficients will have a negative static margin.
Maybe raising a warning is the best we can do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the first point you raised: not all rockets that are instantaneously unstable are necessarily unsimulatable.
A possible compromise would be either a warning or letting the user set a variable, such as ALLOW_UNSTABLE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the Idea of having a flag with default to false (so current API is respected).
Then we can simply turn It on for infinity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would ALLOW_UNSTABLE be by default True or False?
And if the default is False would that be a breaking change? Since someone who has a sim with an unstable rocket might start getting an error with this SM check
And if the default is True is it really helping the user that does not know about the negative static margin problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant default true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting from an error to a warning is the easiest option right now.
However, I think we should better understand the cases where an unstable rocket can fly.
Perhaps the problem/bug happens inside the u_dot function (after rail exit) ?
If setting ALLOW_UNSTABLE to false, we should describe this behavior in the error message.
Setting ALLOW_UNSTABLE to true would not make much help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think setting It to true by default mantains current behavior while allowing clients to deliberatively switch.
IMHO a simple warning would not be easy to consume for safe guarding purposes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand.
My point is that maybe we should not keep the current behavior at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will think more about this during the week
05ba950 to
2793a62
Compare
…ons in Flight class
2793a62 to
04d2354
Compare
|
Gotta think a better way of solving this problem. |
Pull request type
Checklist
black rocketpy/ tests/) has passed locallypytest tests -m slow --runslow) have passed locallyCHANGELOG.mdhas been updated (if relevant)Current behavior
A common mistake on rocketpy is to try running a flight simulation when the rocket is unstable.
The simulation will likely fail or never stops.
It is true that not always it will fail, but I believe we should be more restricted in order to avoid these case scenarios;
New behavior
UnstableRocketExceptioneverytime a flight is instantiated using a rocket with static margin lower than 0.Breaking change
Additional information
Future PRs should add more custom exceptions if needed.
In this PR: