99import simplekml
1010from scipy .integrate import BDF , DOP853 , LSODA , RK23 , RK45 , OdeSolver , Radau
1111
12+ from ..exceptions import UnstableRocketError
1213from ..mathutils .function import Function , funcify_method
1314from ..mathutils .vector_matrix import Matrix , Vector
1415from ..plots .flight_plots import _FlightPlots
@@ -639,6 +640,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-statements
639640 self .__init_solution_monitors ()
640641 self .__init_equations_of_motion ()
641642 self .__init_solver_monitors ()
643+ self .__validate_rocket_static_margin ()
642644
643645 # Create known flight phases
644646 self .flight_phases = self .FlightPhases ()
@@ -664,6 +666,15 @@ def __repr__(self):
664666 f"name= { self .name } )>"
665667 )
666668
669+ def __validate_rocket_static_margin (self ):
670+ """
671+ Avoids running a flight simulation if the rocket stability margin is
672+ negative. This is a common mistake that can lead to unstable flights,
673+ which usually runs indefinitely.
674+ """
675+ if (s := self .rocket .static_margin (0 )) < 0 :
676+ raise UnstableRocketError (s )
677+
667678 # pylint: disable=too-many-nested-blocks, too-many-branches, too-many-locals,too-many-statements
668679 def __simulate (self , verbose ):
669680 """Simulate the flight trajectory."""
0 commit comments