Skip to content

Commit 02b02ee

Browse files
Merge pull request #26 from RocketPy-Team/enh/add_rail_buttons
ENH: Rail buttons added to nbbuilder. Other small changes made.
2 parents 0db7761 + dca2328 commit 02b02ee

File tree

4 files changed

+1049
-95
lines changed

4 files changed

+1049
-95
lines changed

examples/ProjetoJupiter--Valetudo--2019/parameters.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"nozzle_radius": 0.01605,
4343
"position": 2.052896709219859,
4444
"throat_radius": 0.0107,
45-
"thrust_source": "examples\\ProjetoJupiter--Valetudo--2019\\thrust_source.csv"
45+
"thrust_source": "examples/ProjetoJupiter--Valetudo--2019/thrust_source.csv"
4646
},
4747
"nosecones": {
4848
"base_radius": 0.04045000000000001,
@@ -72,7 +72,7 @@
7272
"rocket": {
7373
"center_of_mass_without_propellant": 1.4023,
7474
"coordinate_system_orientation": "nose_to_tail",
75-
"drag_curve": "examples\\ProjetoJupiter--Valetudo--2019\\drag_curve.csv",
75+
"drag_curve": "examples/ProjetoJupiter--Valetudo--2019/drag_curve.csv",
7676
"inertia": [
7777
0.01467,
7878
0.01467,

examples/ProjetoJupiter--Valetudo--2019/simulation.ipynb

Lines changed: 999 additions & 64 deletions
Large diffs are not rendered by default.

rocketserializer/nb_builder.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def build_rocket(self, nb: nbf.v4.new_notebook):
227227
nb["cells"].append(nbf.v4.new_code_cell(text))
228228

229229
nb = self.add_parachutes_to_rocket(nb)
230+
nb = self.build_rail_buttons(nb)
230231

231232
text = "### Rocket Info\n"
232233
text += "rocket.all_info()\n"
@@ -243,7 +244,6 @@ def build_all_aerodynamic_surfaces(
243244
self.build_nosecones(nb)
244245
self.build_fins(nb)
245246
self.build_tails(nb)
246-
self.build_rail_buttons(nb)
247247
self.build_parachute(nb)
248248
logger.info("[NOTEBOOK BUILDER] All aerodynamic surfaces created.")
249249
return nb
@@ -389,16 +389,14 @@ def build_fins(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
389389
pass
390390
# free form fins
391391
# checking if fins were added
392-
try:
393-
assert fin_counter > 0
392+
if fin_counter > 0:
394393
logger.info(
395394
"[NOTEBOOK BUILDER] %s fins were added to the rocket.", fin_counter
396395
)
397-
except AssertionError:
398-
text = "No fins were added to the rocket. Please add at least one."
396+
else:
397+
text = "# No fins were added to the rocket. Check parameters.json."
399398
nb["cells"].append(nbf.v4.new_code_cell(text))
400-
logger.warning("No fins were added to the rocket. Please add at least one.")
401-
raise Warning("No fins were added to the rocket. Please add at least one.")
399+
logger.warning("No fins were added to the rocket. Check parameters.json")
402400
return nb
403401

404402
def build_tails(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
@@ -434,7 +432,28 @@ def build_tails(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
434432
return nb
435433

436434
def build_rail_buttons(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
437-
logger.info("rail buttons not implemented yet")
435+
# add a markdown cell
436+
text = "### Rail Buttons\n"
437+
nb["cells"].append(nbf.v4.new_markdown_cell(text))
438+
439+
if not self.parameters["rail_buttons"]:
440+
text = "# No rail buttons were added to the rocket."
441+
nb["cells"].append(nbf.v4.new_code_cell(text))
442+
logger.warning("No rail buttons were added to the rocket.")
443+
return nb
444+
445+
rail_button_i = self.parameters["rail_buttons"]
446+
upper_position = rail_button_i["upper_position"]
447+
lower_position = rail_button_i["lower_position"]
448+
ang_position = rail_button_i["angular_position"]
449+
text = "rail_buttons = rocket.set_rail_buttons(\n"
450+
text += f" upper_button_position={upper_position:.3f},\n"
451+
text += f" lower_button_position={lower_position:.3f},\n"
452+
text += f" angular_position={ang_position:.3f},\n"
453+
text += ")\n"
454+
nb["cells"].append(nbf.v4.new_code_cell(text))
455+
456+
logger.info("[NOTEBOOK BUILDER] Rail Buttons created.")
438457
return nb
439458

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

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

555576
# Ground hit velocity
556-
ground_hit_velocity_ork = self.parameters["stored_results"][
577+
ground_hit_velocity_ork = -self.parameters["stored_results"][
557578
"ground_hit_velocity"
558579
]
559580
text += f"ground_hit_velocity_ork = {ground_hit_velocity_ork}\n"
@@ -565,6 +586,7 @@ def build_compare_results(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
565586
text += "ground_hit_velocity_difference = ground_hit_velocity_rpy - ground_hit_velocity_ork\n"
566587
text += "error_ground_hit_velocity = abs((ground_hit_velocity_difference)/ground_hit_velocity_rpy)*100\n"
567588
text += r'print(f"Ground hit velocity difference: {error_ground_hit_velocity:.3f} %")'
589+
text += "\nprint()"
568590
text += "\n\n"
569591

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

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

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

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

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

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

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

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

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

705736
nb["cells"].append(nbf.v4.new_code_cell(text))

testnbbuilder.ipynb

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 27,
5+
"execution_count": 7,
66
"metadata": {},
77
"outputs": [
88
{
@@ -21,21 +21,21 @@
2121
},
2222
{
2323
"cell_type": "code",
24-
"execution_count": 28,
24+
"execution_count": 8,
2525
"metadata": {},
2626
"outputs": [
2727
{
2828
"name": "stdout",
2929
"output_type": "stream",
3030
"text": [
31-
"Converted examples/EPFL--BellaLui--2020/rocket.ork to JSON successfully.\n"
31+
"Converted examples/ProjetoJupiter--Valetudo--2019/rocket.ork to JSON successfully.\n"
3232
]
3333
},
3434
{
3535
"name": "stderr",
3636
"output_type": "stream",
3737
"text": [
38-
"reformatted examples/EPFL--BellaLui--2020/simulation.ipynb\n",
38+
"reformatted examples/ProjetoJupiter--Valetudo--2019/simulation.ipynb\n",
3939
"\n",
4040
"All done! ✨ 🍰 ✨\n",
4141
"1 file reformatted.\n"
@@ -45,19 +45,7 @@
4545
"name": "stdout",
4646
"output_type": "stream",
4747
"text": [
48-
"Notebook for examples/EPFL--BellaLui--2020/rocket.ork built!\n",
49-
"Converted examples/rocket_with_elliptical_fins/rocket.ork to JSON successfully.\n",
50-
"Notebook for examples/rocket_with_elliptical_fins/rocket.ork built!\n"
51-
]
52-
},
53-
{
54-
"name": "stderr",
55-
"output_type": "stream",
56-
"text": [
57-
"reformatted examples/rocket_with_elliptical_fins/simulation.ipynb\n",
58-
"\n",
59-
"All done! ✨ 🍰 ✨\n",
60-
"1 file reformatted.\n"
48+
"Notebook for examples/ProjetoJupiter--Valetudo--2019/rocket.ork built!\n"
6149
]
6250
}
6351
],
@@ -68,10 +56,10 @@
6856
"from rocketserializer.nb_builder import NotebookBuilder\n",
6957
"\n",
7058
"files = [\n",
71-
" \"examples/EPFL--BellaLui--2020/rocket.ork\",\n",
59+
" # \"examples/EPFL--BellaLui--2020/rocket.ork\",\n",
7260
" # \"examples/NDRT--Rocket--2020/rocket.ork\",\n",
73-
" # \"examples/ProjetoJupiter--Valetudo--2019/rocket.ork\",\n",
74-
" \"examples/rocket_with_elliptical_fins/rocket.ork\",\n",
61+
" \"examples/ProjetoJupiter--Valetudo--2019/rocket.ork\",\n",
62+
" # \"examples/rocket_with_elliptical_fins/rocket.ork\",\n",
7563
" # \"examples/databank/Team01/rocket.ork\",\n",
7664
" # \"examples/databank/Team06/rocket.ork\",\n",
7765
" # \"examples/databank/Team07/rocket.ork\",\n",

0 commit comments

Comments
 (0)