Skip to content

Commit b494f7f

Browse files
initiates controllers.motor refactoring
1 parent 996c89b commit b494f7f

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

lib/controllers/motor.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,34 @@ class MotorController:
2828
- Create a rocketpy.Motor object from a Motor model object.
2929
"""
3030

31-
def __init__(self, motor: Motor, motor_kind):
31+
def __init__(self, motor: Motor, motor_kind: MotorKinds):
3232
self.guard(motor, motor_kind)
33+
self._motor = motor
34+
self._motor_kind = motor_kind
35+
36+
@property
37+
def motor(self) -> Motor:
38+
return self._motor
39+
40+
@motor.setter
41+
def motor(self, motor: Motor):
42+
self._motor = motor
43+
44+
@property
45+
def motor_kind(self) -> MotorKinds:
46+
return self._motor_kind
47+
48+
@staticmethod
49+
def get_rocketpy_motor(
50+
motor: Motor,
51+
) -> Union[LiquidMotor, HybridMotor, SolidMotor]:
52+
"""
53+
Get the rocketpy motor object.
54+
55+
Returns:
56+
Union[LiquidMotor, HybridMotor, SolidMotor]
57+
"""
58+
3359
motor_core = {
3460
"thrust_source": f"lib/data/engines/{motor.thrust_source.value}.eng",
3561
"burn_time": motor.burn_time,
@@ -39,7 +65,7 @@ def __init__(self, motor: Motor, motor_kind):
3965
"center_of_dry_mass_position": motor.center_of_dry_mass_position,
4066
}
4167

42-
match motor_kind:
68+
match motor.motor_kind:
4369
case MotorKinds.liquid:
4470
rocketpy_motor = LiquidMotor(**motor_core)
4571
case MotorKinds.hybrid:
@@ -68,13 +94,11 @@ def __init__(self, motor: Motor, motor_kind):
6894
interpolation_method=motor.interpolation_method,
6995
)
7096

71-
if motor_kind != MotorKinds.solid:
97+
if motor.motor_kind != MotorKinds.solid:
7298
for tank in motor.tanks:
7399
rocketpy_motor.add_tank(tank.tank, tank.position)
74100

75-
self.motor_kind = motor_kind # tracks motor kind state
76-
self.rocketpy_motor = rocketpy_motor
77-
self.motor = motor
101+
return rocketpy_motor
78102

79103
def guard(self, motor: Motor, motor_kind):
80104
if motor_kind != MotorKinds.solid and motor.tanks is None:

0 commit comments

Comments
 (0)