@@ -80,7 +80,8 @@ def build_imports(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
80
80
# import classes
81
81
text = (
82
82
"from rocketpy import Environment, SolidMotor, Rocket, Flight, "
83
- + "TrapezoidalFins, EllipticalFins, RailButtons, NoseCone, Tail\n "
83
+ + "TrapezoidalFins, EllipticalFins, RailButtons, NoseCone, Tail, "
84
+ + "Parachute\n "
84
85
)
85
86
text += "import datetime\n "
86
87
nb ["cells" ].append (nbf .v4 .new_code_cell (text ))
@@ -225,7 +226,8 @@ def build_rocket(self, nb: nbf.v4.new_notebook):
225
226
)
226
227
nb ["cells" ].append (nbf .v4 .new_code_cell (text ))
227
228
228
- # add a code cell
229
+ nb = self .add_parachutes_to_rocket (nb )
230
+
229
231
text = "### Rocket Info\n "
230
232
text += "rocket.all_info()\n "
231
233
nb ["cells" ].append (nbf .v4 .new_code_cell (text ))
@@ -242,6 +244,7 @@ def build_all_aerodynamic_surfaces(
242
244
self .build_fins (nb )
243
245
self .build_tails (nb )
244
246
self .build_rail_buttons (nb )
247
+ self .build_parachute (nb )
245
248
logger .info ("[NOTEBOOK BUILDER] All aerodynamic surfaces created." )
246
249
return nb
247
250
@@ -434,6 +437,55 @@ def build_rail_buttons(self, nb: nbf.v4.new_notebook) -> nbf.v4.new_notebook:
434
437
logger .info ("rail buttons not implemented yet" )
435
438
return nb
436
439
440
+ def build_parachute (self , nb : nbf .v4 .new_notebook ) -> nbf .v4 .new_notebook :
441
+ # add a markdown cell
442
+ text = "### Parachutes\n "
443
+ text += "As rocketpy allows for multiple parachutes, we will create a "
444
+ text += "dictionary with all the parachutes and then add them to the rocket\n "
445
+ nb ["cells" ].append (nbf .v4 .new_markdown_cell (text ))
446
+
447
+ # add a code cell
448
+ text = "parachutes = {}\n "
449
+ nb ["cells" ].append (nbf .v4 .new_code_cell (text ))
450
+ for i in range (len (self .parameters ["parachutes" ])):
451
+
452
+ parachute_i = self .parameters ["parachutes" ][str (i )]
453
+ cd_s = parachute_i ["cd" ] * parachute_i ["area" ]
454
+ deploy_event = parachute_i ["deploy_event" ]
455
+
456
+ # evaluating trigger
457
+ if deploy_event == "apogee" :
458
+ trigger = "apogee"
459
+ elif deploy_event == "altitude" :
460
+ trigger = float (parachute_i ["deploy_altitude" ])
461
+ else :
462
+ logger .warning ("Invalid deploy event for parachute %d" , i )
463
+ raise ValueError (f"Invalid deploy event for parachute { i } " )
464
+ # adding parameters
465
+ name = parachute_i ["name" ]
466
+ text = f"parachutes[{ i } ] = Parachute(\n "
467
+ text += f" name='{ name } ',\n "
468
+ text += f" cd_s={ cd_s :.3f} ,\n "
469
+ # adding trigger
470
+ if isinstance (trigger , str ):
471
+ text += f" trigger='{ trigger } ',\n "
472
+ else :
473
+ text += f" trigger={ trigger :.3f} ,\n "
474
+
475
+ text += " sampling_rate=100, \n "
476
+ text += ")\n "
477
+ nb ["cells" ].append (nbf .v4 .new_code_cell (text ))
478
+
479
+ def add_parachutes_to_rocket (self , nb : nbf .v4 .new_notebook ) -> nbf .v4 .new_notebook :
480
+
481
+ text = "Adding parachutes to the rocket\n "
482
+ nb ["cells" ].append (nbf .v4 .new_markdown_cell (text ))
483
+ text = "rocket.parachutes = list(parachutes.values())\n "
484
+ nb ["cells" ].append (nbf .v4 .new_code_cell (text ))
485
+
486
+ logger .info ("[NOTEBOOK BUILDER] Parachutes created." )
487
+ return nb
488
+
437
489
def build_flight (self , nb : nbf .v4 .new_notebook ) -> nbf .v4 .new_notebook :
438
490
"""Generates a section defining the flight and returns the notebook."""
439
491
# add a markdown cell
0 commit comments