Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions rocketserializer/nb_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def build_imports(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
# import classes
text = (
"from rocketpy import Environment, SolidMotor, Rocket, Flight, "
+ "TrapezoidalFins, EllipticalFins, RailButtons, NoseCone, Tail\n"
+ "TrapezoidalFins, EllipticalFins, RailButtons, NoseCone, Tail, "
+ "Parachute\n"
)
text += "import datetime\n"
nb["cells"].append(nbf.v4.new_code_cell(text))
Expand Down Expand Up @@ -225,7 +226,8 @@ def build_rocket(self, nb: nbf.v4.new_notebook):
)
nb["cells"].append(nbf.v4.new_code_cell(text))

# add a code cell
nb = self.add_parachutes_to_rocket(nb)

text = "### Rocket Info\n"
text += "rocket.all_info()\n"
nb["cells"].append(nbf.v4.new_code_cell(text))
Expand All @@ -242,6 +244,7 @@ def build_all_aerodynamic_surfaces(
self.build_fins(nb)
self.build_tails(nb)
self.build_rail_buttons(nb)
self.build_parachute(nb)
logger.info("[NOTEBOOK BUILDER] All aerodynamic surfaces created.")
return nb

Expand Down Expand Up @@ -434,6 +437,55 @@ def build_rail_buttons(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
logger.info("rail buttons not implemented yet")
return nb

def build_parachute(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
# add a markdown cell
text = "### Parachutes\n"
text += "As rocketpy allows for multiple parachutes, we will create a "
text += "dictionary with all the parachutes and then add them to the rocket\n"
nb["cells"].append(nbf.v4.new_markdown_cell(text))

# add a code cell
text = "parachutes = {}\n"
nb["cells"].append(nbf.v4.new_code_cell(text))
for i in range(len(self.parameters["parachutes"])):

parachute_i = self.parameters["parachutes"][str(i)]
cd_s = parachute_i["cd"] * parachute_i["area"]
deploy_event = parachute_i["deploy_event"]

# evaluating trigger
if deploy_event == "apogee":
trigger = "apogee"
elif deploy_event == "altitude":
trigger = float(parachute_i["deploy_altitude"])
else:
logger.warning("Invalid deploy event for parachute %d", i)
raise ValueError(f"Invalid deploy event for parachute {i}")
# adding parameters
name = parachute_i["name"]
text = f"parachutes[{i}] = Parachute(\n"
text += f" name='{name}',\n"
text += f" cd_s={cd_s:.3f},\n"
# adding trigger
if isinstance(trigger, str):
text += f" trigger='{trigger}',\n"
else:
text += f" trigger={trigger:.3f},\n"

text += " sampling_rate=100, \n"
text += ")\n"
nb["cells"].append(nbf.v4.new_code_cell(text))

def add_parachutes_to_rocket(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:

text = "Adding parachutes to the rocket\n"
nb["cells"].append(nbf.v4.new_markdown_cell(text))
text = "rocket.parachutes = list(parachutes.values())\n"
nb["cells"].append(nbf.v4.new_code_cell(text))

logger.info("[NOTEBOOK BUILDER] Parachutes created.")
return nb

def build_flight(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
"""Generates a section defining the flight and returns the notebook."""
# add a markdown cell
Expand Down