Skip to content

Commit 724f9dd

Browse files
committed
MNT: flight class fix on simulation mode detection
- MNT: implemented identification of simulation mode based on check if point mass objects are used
1 parent c8096c5 commit 724f9dd

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

rocketpy/simulation/flight.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import warnings
55
from copy import deepcopy
66
from functools import cached_property
7-
7+
from ..motors.pointmassmotor import PointMassMotor
8+
from ..rocket import PointMassRocket
89
import numpy as np
910
import simplekml
1011
from scipy.integrate import BDF, DOP853, LSODA, RK23, RK45, OdeSolver, Radau
@@ -1193,16 +1194,33 @@ def __init_solver_monitors(self):
11931194

11941195
def __init_equations_of_motion(self):
11951196
"""Initialize equations of motion."""
1196-
if self.equations_of_motion == "solid_propulsion" and self.simulation_mode == '6 DOF':
1197-
# NOTE: The u_dot is faster, but only works for solid propulsion
1198-
self.u_dot_generalized = self.u_dot
1199-
elif self.equations_of_motion == "solid_propulsion" and self.simulation_mode == '3 DOF':
1200-
# NOTE: The u_dot is faster, but only works for solid propulsion
1201-
self.u_dot_generalized = self.u_dot_3dof
1202-
elif self.simulation_mode == '3 DOF':
1203-
# NOTE: The u_dot is faster, but only works for solid propulsion
1204-
self.u_dot_generalized = self.u_dot_generalized_3dof
1197+
# Determine if a point-mass model is used.
1198+
is_point_mass = (
1199+
isinstance(self.rocket, PointMassRocket)
1200+
or (self.rocket._motors and isinstance(self.rocket._motors[0], PointMassMotor))
1201+
)
1202+
# Set simulation mode based on model type.
1203+
if is_point_mass:
1204+
if self.simulation_mode != "3 DOF":
1205+
warnings.warn("A point-mass model was detected. Simulation mode should be '3 DOF'.", UserWarning)
1206+
self.simulation_mode = "3 DOF"
1207+
else:
1208+
self.simulation_mode = self.simulation_mode
12051209

1210+
# Set the equations of motion based on the final simulation mode.
1211+
if self.simulation_mode == "3 DOF":
1212+
self.equations_of_motion = self.equations_of_motion
1213+
self.u_dot_generalized = self.u_dot_generalized_3dof
1214+
elif self.simulation_mode == "6 DOF":
1215+
if self.equations_of_motion == "solid_propulsion":
1216+
self.u_dot_generalized = self.u_dot_6dof
1217+
else:
1218+
self.u_dot_generalized = self.u_dot_generalized_6dof
1219+
else:
1220+
raise ValueError(
1221+
f"Invalid simulation_mode: {self.simulation_mode}. "
1222+
"Must be '3 DOF' or '6 DOF'."
1223+
)
12061224
def __init_controllers(self):
12071225
"""Initialize controllers and sensors"""
12081226
self._controllers = self.rocket._controllers[:]

0 commit comments

Comments
 (0)