Skip to content

Commit

Permalink
ENH: Rail buttons added to nbbuilder. Other small changes made.
Browse files Browse the repository at this point in the history
  • Loading branch information
juliomachad0 committed Jun 15, 2024
1 parent fca09d2 commit c93e62c
Show file tree
Hide file tree
Showing 4 changed files with 1,087 additions and 161 deletions.
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,184 changes: 1,048 additions & 136 deletions examples/ProjetoJupiter--Valetudo--2019/simulation.ipynb

Large diffs are not rendered by default.

32 changes: 29 additions & 3 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 @@ -434,7 +434,21 @@ 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))
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 +549,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 +565,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 +581,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 +597,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 +617,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 +633,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 +647,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 +663,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 +677,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 +693,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 +709,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 +725,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

0 comments on commit c93e62c

Please sign in to comment.