Skip to content

Commit

Permalink
initiate motor/rocket modulization
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBarberini committed Oct 8, 2023
1 parent bd59b9f commit b66b2f2
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
16 changes: 8 additions & 8 deletions lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from lib.views.motor import MotorSummary, MotorCreated, MotorUpdated, MotorDeleted, MotorPickle
from lib.models.environment import Env
from lib.models.flight import Flight
from lib.models.rocket import Rocket
from lib.models.motor import Motor
from lib.models.rocket import Rocket, RocketOptions
from lib.models.motor import Motor, MotorKinds, MotorOptions
from lib.controllers.flight import FlightController
from lib.controllers.environment import EnvController
from lib.controllers.rocket import RocketController
Expand Down Expand Up @@ -70,7 +70,7 @@ async def main_page():

# Flight routes
@app.post("/flights/", tags=["FLIGHT"])
async def create_flight(flight: Flight) -> "FlightCreated":
async def create_flight(flight: Flight, rocket_option: RocketOptions, motor_kind: MotorKinds, motor_options: MotorOptions) -> "FlightCreated":
"""
Creates a new flight.
Expand All @@ -84,7 +84,7 @@ async def create_flight(flight: Flight) -> "FlightCreated":
HTTP 422 Unprocessable Entity: If API is unable to parse flight data, usually happens when some parameter is invalid, please attend to API docs request specifications.
HTTP 500 Internal Server Error: If API is either unable to create flight in mongoDB or valid parameter type/structure provided but content is breaking the API.
"""
return await FlightController(flight).create_flight()
return await FlightController(flight).create_flight(rocket_option, motor_kind, motor_option)

@app.get("/flights/{flight_id}", tags=["FLIGHT"])
async def read_flight(flight_id: int) -> "Flight":
Expand Down Expand Up @@ -310,7 +310,7 @@ async def simulate_env(env_id: int) -> "EnvSummary":

# Motor routes
@app.post("/motors/", tags=["MOTOR"])
async def create_motor(motor: Motor) -> "MotorCreated":
async def create_motor(motor: Motor, motor_kind: MotorKinds, motor_option: MotorOptions) -> "MotorCreated":
"""
Creates a new motor.
Expand All @@ -324,7 +324,7 @@ async def create_motor(motor: Motor) -> "MotorCreated":
HTTP 422 Unprocessable Entity: If API is unable to parse motor data, usually happens when some parameter is invalid, please attend to API docs request specifications.
HTTP 500 Internal Server Error: If API is either unable to create motor in mongoDB or valid parameter type/structure provided but content is breaking the API.
"""
return await MotorController(motor).create_motor()
return await MotorController(motor).create_motor(motor_kind, motor_option)

@app.get("/motors/{motor_id}", tags=["MOTOR"])
async def read_motor(motor_id: int) -> "Motor":
Expand Down Expand Up @@ -411,7 +411,7 @@ async def simulate_motor(motor_id: int) -> "MotorSummary":

# Rocket routes
@app.post("/rockets/", tags=["ROCKET"])
async def create_rocket(rocket: Rocket) -> "RocketCreated":
async def create_rocket(rocket: Rocket, rocket_option: RocketOptions, motor_kind: MotorKinds, motor_option: MotorOptions) -> "RocketCreated":
"""
Creates a new rocket.
Expand All @@ -425,7 +425,7 @@ async def create_rocket(rocket: Rocket) -> "RocketCreated":
HTTP 422 Unprocessable Entity: If API is unable to parse rocket data, usually happens when some parameter is invalid, please attend to API docs request specifications.
HTTP 500 Internal Server Error: If API is either unable to create rocket in mongoDB or valid parameter type/structure provided but content is breaking the API.
"""
return await RocketController(rocket).create_rocket()
return await RocketController(rocket).create_rocket(rocket_option, motor_kind, motor_option)

@app.get("/rockets/{rocket_id}", tags=["ROCKET"])
async def read_rocket(rocket_id: int) -> Rocket:
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FlightController():
- Read a RocketpyFlight object from the database.
"""
def __init__(self, flight: Flight):
def __init__(self, flight: Flight, rocket_option, motor_kind, motor_option):
rocketpy_rocket = RocketController(flight.rocket).rocketpy_rocket
rocketpy_env = EnvController(flight.environment).rocketpy_env

Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MotorController():
Enables:
- Create a rocketpy.Motor object from a Motor model object.
"""
def __init__(self, motor: Motor):
def __init__(self, motor: Motor, motor_kind, motor_option):
rocketpy_motor = SolidMotor(
burn_time=motor.burn_time,
grain_number=motor.grain_number,
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RocketController():
Enables:
create a RocketpyRocket object from a Rocket model object.
"""
def __init__(self, rocket: Rocket):
def __init__(self, rocket: Rocket, rocket_option, motor_kind, motor_option):
rocketpy_rocket = RocketpyRocket(
radius=rocket.radius,
mass=rocket.mass,
Expand Down
12 changes: 10 additions & 2 deletions lib/models/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

class MotorOptions(str, Enum):
cesaroni: str = "Cesaroni_M1670"
custom: str = "Custom (Coming soon)"
custom: str = "Custom"

class MotorKinds(str, Enum):
hybrid: str = "Hybrid"
solid: str = "Solid"
liquid: str = "Liquid"

class MotorEngine(BaseModel, frozen=True):
pass

class Motor(BaseModel, frozen=True):
burn_time: float = 3.9
Expand All @@ -18,7 +26,7 @@ class Motor(BaseModel, frozen=True):
grain_initial_height: float = 0.12
grains_center_of_mass_position: float = -0.85704
#TBD: thrust_source must be the id of a previously uploaded .eng file and a list of "default" files must be provided in the api docs
thrust_source: MotorOptions = "Cesaroni_M1670"
thrust_source: MotorEngine = MotorEngine()
grain_separation: float = 0.005
nozzle_radius: float = 0.033
throat_radius: float = 0.011
Expand Down
28 changes: 24 additions & 4 deletions lib/models/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,36 @@
from lib.models.parachute import Parachute

class RocketOptions(str, Enum):
calisto: str = "calisto"
custom: str = "Custom (Coming soon)"
calisto: str = "Calisto"
custom: str = "Custom"

class Rocket(BaseModel, frozen=True):
radius: float = 0.0632
mass: float = 16.235
inertia: "Tuple[float, float, float]" = (6.321, 6.321, 0.0346)
#TBD: powerOffDrag an powerOnDrag need to be the id of previously uploaded .csv files and a list of "default" files must be provided in the api docs
power_off_drag: RocketOptions = "calisto"
power_on_drag: RocketOptions = "calisto"
power_off_drag: "Tuple[Tuple[float, float]]" = (
(0.01,0.333865758),
(0.02,0.394981721),
(0.03,0.407756063),
(0.04,0.410692705),
(0.05,0.410540353),
(0.06,0.409240293),
(0.07,0.407500874),
(0.08,0.405617853),
(0.09,0.403724114)
)
power_on_drag: "Tuple[Tuple[float, float]]" = (
(0.01,0.333865758),
(0.02,0.394981721),
(0.03,0.407756063),
(0.04,0.410692705),
(0.05,0.410540353),
(0.06,0.409240293),
(0.07,0.407500874),
(0.08,0.405617853),
(0.09,0.403724114)
)
center_of_mass_without_motor: int = 0
#TBD: a list of possible tailToNose values must be provided in the api docs
coordinate_system_orientation: Optional[str] = "tail_to_nose"
Expand Down

0 comments on commit b66b2f2

Please sign in to comment.