Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Rail buttons added to nbbuilder. Other small changes made. #26

Merged
merged 3 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions examples/ProjetoJupiter--Valetudo--2019/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"nozzle_radius": 0.01605,
"position": 2.052896709219859,
"throat_radius": 0.0107,
"thrust_source": "examples\\ProjetoJupiter--Valetudo--2019\\thrust_source.csv"
"thrust_source": "examples/ProjetoJupiter--Valetudo--2019/thrust_source.csv"
},
"nosecones": {
"base_radius": 0.04045000000000001,
Expand Down Expand Up @@ -72,7 +72,7 @@
"rocket": {
"center_of_mass_without_propellant": 1.4023,
"coordinate_system_orientation": "nose_to_tail",
"drag_curve": "examples\\ProjetoJupiter--Valetudo--2019\\drag_curve.csv",
"drag_curve": "examples/ProjetoJupiter--Valetudo--2019/drag_curve.csv",
"inertia": [
0.01467,
0.01467,
Expand Down
1,063 changes: 999 additions & 64 deletions examples/ProjetoJupiter--Valetudo--2019/simulation.ipynb

Large diffs are not rendered by default.

49 changes: 40 additions & 9 deletions rocketserializer/nb_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def build_rocket(self, nb: nbf.v4.new_notebook):
nb["cells"].append(nbf.v4.new_code_cell(text))

nb = self.add_parachutes_to_rocket(nb)
nb = self.build_rail_buttons(nb)

text = "### Rocket Info\n"
text += "rocket.all_info()\n"
Expand All @@ -243,7 +244,6 @@ def build_all_aerodynamic_surfaces(
self.build_nosecones(nb)
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 @@ -389,16 +389,14 @@ def build_fins(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
pass
# free form fins
# checking if fins were added
try:
assert fin_counter > 0
if fin_counter > 0:
logger.info(
"[NOTEBOOK BUILDER] %s fins were added to the rocket.", fin_counter
)
except AssertionError:
text = "No fins were added to the rocket. Please add at least one."
else:
text = "# No fins were added to the rocket. Check parameters.json."
nb["cells"].append(nbf.v4.new_code_cell(text))
logger.warning("No fins were added to the rocket. Please add at least one.")
raise Warning("No fins were added to the rocket. Please add at least one.")
logger.warning("No fins were added to the rocket. Check parameters.json")
return nb

def build_tails(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
Expand Down Expand Up @@ -434,7 +432,28 @@ def build_tails(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
return nb

def build_rail_buttons(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
logger.info("rail buttons not implemented yet")
# add a markdown cell
text = "### Rail Buttons\n"
nb["cells"].append(nbf.v4.new_markdown_cell(text))

if not self.parameters["rail_buttons"]:
text = "# No rail buttons were added to the rocket."
nb["cells"].append(nbf.v4.new_code_cell(text))
logger.warning("No rail buttons were added to the rocket.")
return nb

rail_button_i = self.parameters["rail_buttons"]
upper_position = rail_button_i["upper_position"]
lower_position = rail_button_i["lower_position"]
ang_position = rail_button_i["angular_position"]
text = "rail_buttons = rocket.set_rail_buttons(\n"
text += f" upper_button_position={upper_position:.3f},\n"
text += f" lower_button_position={lower_position:.3f},\n"
text += f" angular_position={ang_position:.3f},\n"
text += ")\n"
nb["cells"].append(nbf.v4.new_code_cell(text))

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

def build_parachute(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
Expand Down Expand Up @@ -535,6 +554,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
text += "error = abs((apogee_difference)/time_to_apogee_rpy)*100"
text += "\n"
text += r'print(f"Time to apogee difference: {error:.3f} %")'
text += "\nprint()"
text += "\n\n"

# Flight time
Expand All @@ -550,10 +570,11 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
"error_flight_time = abs((flight_time_difference)/flight_time_rpy)*100\n"
)
text += r'print(f"Flight time difference: {error_flight_time:.3f} %")'
text += "\nprint()"
text += "\n\n"

# Ground hit velocity
ground_hit_velocity_ork = self.parameters["stored_results"][
ground_hit_velocity_ork = -self.parameters["stored_results"][
"ground_hit_velocity"
]
text += f"ground_hit_velocity_ork = {ground_hit_velocity_ork}\n"
Expand All @@ -565,6 +586,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
text += "ground_hit_velocity_difference = ground_hit_velocity_rpy - ground_hit_velocity_ork\n"
text += "error_ground_hit_velocity = abs((ground_hit_velocity_difference)/ground_hit_velocity_rpy)*100\n"
text += r'print(f"Ground hit velocity difference: {error_ground_hit_velocity:.3f} %")'
text += "\nprint()"
text += "\n\n"

# Launch rod velocity
Expand All @@ -580,6 +602,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
text += "launch_rod_velocity_difference = launch_rod_velocity_rpy - launch_rod_velocity_ork\n"
text += "error_launch_rod_velocity = abs((launch_rod_velocity_difference)/launch_rod_velocity_rpy)*100\n"
text += r'print(f"Launch rod velocity difference: {error_launch_rod_velocity:.3f} %")'
text += "\nprint()"
text += "\n\n"

# Max acceleration
Expand All @@ -599,6 +622,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
text += (
r'print(f"Max acceleration difference: {error_max_acceleration:.3f} %")'
)
text += "\nprint()"
text += "\n\n"

# Max altitude
Expand All @@ -614,6 +638,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
"error_max_altitude = abs((max_altitude_difference)/max_altitude_rpy)*100\n"
)
text += r'print(f"Max altitude difference: {error_max_altitude:.3f} %")'
text += "\nprint()"
text += "\n\n"

# Max Mach
Expand All @@ -627,6 +652,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
text += "max_mach_difference = max_mach_rpy - max_mach_ork\n"
text += "error_max_mach = abs((max_mach_difference)/max_mach_rpy)*100\n"
text += r'print(f"Max Mach difference: {error_max_mach:.3f} %")'
text += "\nprint()"
text += "\n\n"

# Max velocity
Expand All @@ -642,6 +668,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
"error_max_velocity = abs((max_velocity_difference)/max_velocity_rpy)*100\n"
)
text += r'print(f"Max velocity difference: {error_max_velocity:.3f} %")'
text += "\nprint()"
text += "\n\n"

# Max thrust
Expand All @@ -655,6 +682,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
text += "max_thrust_difference = max_thrust_rpy - max_thrust_ork\n"
text += "error_max_thrust = abs((max_thrust_difference)/max_thrust_rpy)*100\n"
text += r'print(f"Max thrust difference: {error_max_thrust:.3f} %")'
text += "\nprint()"
text += "\n\n"

# # Burnout stability margin
Expand All @@ -670,6 +698,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
text += "burnout_stability_margin_difference = burnout_stability_margin_rpy - burnout_stability_margin_ork\n"
text += "error_burnout_stability_margin = abs((burnout_stability_margin_difference)/burnout_stability_margin_rpy)*100\n"
text += r'print(f"Burnout stability margin difference: {error_burnout_stability_margin:.3f} %")'
text += "\nprint()"
text += "\n\n"

# # Max stability margin
Expand All @@ -685,6 +714,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
text += "max_stability_margin_difference = max_stability_margin_rpy - max_stability_margin_ork\n"
text += "error_max_stability_margin = abs((max_stability_margin_difference)/max_stability_margin_rpy)*100\n"
text += r'print(f"Max stability margin difference: {error_max_stability_margin:.3f} %")'
text += "\nprint()"
text += "\n\n"

# Min stability margin
Expand All @@ -700,6 +730,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
text += "min_stability_margin_difference = min_stability_margin_rpy - min_stability_margin_ork\n"
text += "error_min_stability_margin = abs((min_stability_margin_difference)/min_stability_margin_rpy)*100\n"
text += r'print(f"Min stability margin difference: {error_min_stability_margin:.3f} %")'
text += "\nprint()"
text += "\n\n"

nb["cells"].append(nbf.v4.new_code_cell(text))
Expand Down
28 changes: 8 additions & 20 deletions testnbbuilder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -21,21 +21,21 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Converted examples/EPFL--BellaLui--2020/rocket.ork to JSON successfully.\n"
"Converted examples/ProjetoJupiter--Valetudo--2019/rocket.ork to JSON successfully.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"reformatted examples/EPFL--BellaLui--2020/simulation.ipynb\n",
"reformatted examples/ProjetoJupiter--Valetudo--2019/simulation.ipynb\n",
"\n",
"All done! ✨ 🍰 ✨\n",
"1 file reformatted.\n"
Expand All @@ -45,19 +45,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Notebook for examples/EPFL--BellaLui--2020/rocket.ork built!\n",
"Converted examples/rocket_with_elliptical_fins/rocket.ork to JSON successfully.\n",
"Notebook for examples/rocket_with_elliptical_fins/rocket.ork built!\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"reformatted examples/rocket_with_elliptical_fins/simulation.ipynb\n",
"\n",
"All done! ✨ 🍰 ✨\n",
"1 file reformatted.\n"
"Notebook for examples/ProjetoJupiter--Valetudo--2019/rocket.ork built!\n"
]
}
],
Expand All @@ -68,10 +56,10 @@
"from rocketserializer.nb_builder import NotebookBuilder\n",
"\n",
"files = [\n",
" \"examples/EPFL--BellaLui--2020/rocket.ork\",\n",
" # \"examples/EPFL--BellaLui--2020/rocket.ork\",\n",
" # \"examples/NDRT--Rocket--2020/rocket.ork\",\n",
" # \"examples/ProjetoJupiter--Valetudo--2019/rocket.ork\",\n",
" \"examples/rocket_with_elliptical_fins/rocket.ork\",\n",
" \"examples/ProjetoJupiter--Valetudo--2019/rocket.ork\",\n",
" # \"examples/rocket_with_elliptical_fins/rocket.ork\",\n",
" # \"examples/databank/Team01/rocket.ork\",\n",
" # \"examples/databank/Team06/rocket.ork\",\n",
" # \"examples/databank/Team07/rocket.ork\",\n",
Expand Down
Loading