Skip to content

Commit 2aabe20

Browse files
committed
DOC: improve docstrings
1 parent 4241ff5 commit 2aabe20

19 files changed

Lines changed: 2016 additions & 1142 deletions

File tree

docs/development/testing.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,6 @@ Consider the following integration test:
255255
example_plain_env : rocketpy.Environment
256256
Example environment object to be tested.
257257
"""
258-
# TODO:: this should be added to the set_atmospheric_model() method as a
259-
# "file" option, instead of receiving the URL as a string.
260258
URL = "http://weather.uwyo.edu/cgi-bin/sounding?region=samer&TYPE=TEXT%3ALIST&YEAR=2019&MONTH=02&FROM=0500&TO=0512&STNM=83779"
261259
# give it at least 5 times to try to download the file
262260
example_plain_env.set_atmospheric_model(type="wyoming_sounding", file=URL)

docs/examples/camoes_flight_sim.ipynb

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,13 @@
299299
},
300300
{
301301
"cell_type": "code",
302-
"execution_count": 85,
302+
"execution_count": null,
303303
"metadata": {},
304304
"outputs": [],
305305
"source": [
306-
"def drogue_trigger(p, h, y):\n",
307-
" return True if y[5] < 5 and y[2] > 300 else False\n",
306+
"def drogue_trigger(**kwargs):\n",
307+
" state = kwargs[\"state\"]\n",
308+
" return True if state[5] < 5 and state[2] > 300 else False\n",
308309
"\n",
309310
"\n",
310311
"Drogue = CAMOES.add_parachute(\n",
@@ -353,35 +354,7 @@
353354
"execution_count": null,
354355
"metadata": {},
355356
"outputs": [],
356-
"source": [
357-
"import numpy as np\n",
358-
"\n",
359-
"\n",
360-
"def controller_function(\n",
361-
" time, sampling_rate, state, state_history, observed_variables, air_brakes\n",
362-
"):\n",
363-
" new_deployment_level = 0\n",
364-
"\n",
365-
" if time <= 11.4:\n",
366-
" new_deployment_level = 1\n",
367-
" else:\n",
368-
" new_deployment_level = (\n",
369-
" -0.002906 * np.power(time, 3)\n",
370-
" + 0.1497 * np.power(time, 2)\n",
371-
" + -2.563 * time\n",
372-
" + 14.96\n",
373-
" )\n",
374-
"\n",
375-
" if time > 19.6:\n",
376-
" new_deployment_level = 0\n",
377-
"\n",
378-
" if time < 3.8:\n",
379-
" new_deployment_level = 0\n",
380-
"\n",
381-
" air_brakes.deployment_level = new_deployment_level\n",
382-
"\n",
383-
" return time, air_brakes.deployment_level"
384-
]
357+
"source": "import numpy as np\n\n\ndef controller_function(**kwargs):\n time = kwargs[\"time\"]\n air_brakes = kwargs[\"air_brakes\"]\n\n new_deployment_level = 0\n\n if time <= 11.4:\n new_deployment_level = 1\n else:\n new_deployment_level = (\n -0.002906 * np.power(time, 3)\n + 0.1497 * np.power(time, 2)\n + -2.563 * time\n + 14.96\n )\n\n if time > 19.6:\n new_deployment_level = 0\n\n if time < 3.8:\n new_deployment_level = 0\n\n air_brakes.deployment_level = new_deployment_level\n\n return time, air_brakes.deployment_level\n"
385358
},
386359
{
387360
"cell_type": "code",
@@ -835,4 +808,4 @@
835808
},
836809
"nbformat": 4,
837810
"nbformat_minor": 2
838-
}
811+
}

docs/notebooks/getting_started.ipynb

Lines changed: 207 additions & 564 deletions
Large diffs are not rendered by default.

docs/notebooks/monte_carlo_analysis/monte_carlo_analysis.ipynb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@
369369
},
370370
{
371371
"cell_type": "code",
372-
"execution_count": 6,
372+
"execution_count": null,
373373
"metadata": {
374374
"colab": {
375375
"base_uri": "https://localhost:8080/",
@@ -416,14 +416,6 @@
416416
")\n",
417417
"\n",
418418
"\n",
419-
"# Set up parachutes. This rocket, named Valetudo, only has a drogue chute.\n",
420-
"def drogue_trigger(p, h, y):\n",
421-
" # Check if rocket is going down, i.e. if it has passed the apogee\n",
422-
" vertical_velocity = y[5]\n",
423-
" # Return true to activate parachute once the vertical velocity is negative\n",
424-
" return True if vertical_velocity < 0 else False\n",
425-
"\n",
426-
"\n",
427419
"# Iterate over flight settings\n",
428420
"out = display(\"Starting\", display_id=True)\n",
429421
"for setting in flight_settings(analysis_parameters, number_of_simulations):\n",
@@ -498,7 +490,7 @@
498490
" Drogue = Valetudo.add_parachute(\n",
499491
" \"Drogue\",\n",
500492
" cd_s=setting[\"cd_s_drogue\"],\n",
501-
" trigger=drogue_trigger,\n",
493+
" trigger=\"apogee\",\n",
502494
" sampling_rate=105,\n",
503495
" lag=setting[\"lag_rec\"] + setting[\"lag_se\"],\n",
504496
" noise=(0, 8.3, 0.5),\n",

docs/notebooks/monte_carlo_analysis/parachute_drop_from_helicopter.ipynb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,14 +423,6 @@
423423
")\n",
424424
"\n",
425425
"\n",
426-
"# Set up parachutes. This rocket, named Valetudo, only has a drogue chute.\n",
427-
"def drogueTrigger(p, h, y):\n",
428-
" # Check if rocket is going down, i.e. if it has passed the apogee\n",
429-
" vertical_velocity = y[5]\n",
430-
" # Return true to activate parachute once the vertical velocity is negative\n",
431-
" return True if vertical_velocity < 0 else False\n",
432-
"\n",
433-
"\n",
434426
"# Iterate over flight settings\n",
435427
"out = display(\"Starting\", display_id=True)\n",
436428
"for setting in flight_settings(analysis_parameters, number_of_simulations):\n",
@@ -496,7 +488,7 @@
496488
" Drogue = Valetudo.addParachute(\n",
497489
" \"Drogue\",\n",
498490
" CdS=setting[\"CdSDrogue\"],\n",
499-
" trigger=drogueTrigger,\n",
491+
" trigger=\"apogee\",\n",
500492
" samplingRate=105,\n",
501493
" lag=setting[\"lag_rec\"] + setting[\"lag_se\"],\n",
502494
" noise=(0, 8.3, 0.5),\n",

docs/notebooks/sensors.ipynb

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -459,65 +459,7 @@
459459
"execution_count": 19,
460460
"metadata": {},
461461
"outputs": [],
462-
"source": [
463-
"def controller_function(\n",
464-
" time, sampling_rate, state, state_history, observed_variables, air_brakes, sensors\n",
465-
"):\n",
466-
" # state = [x, y, z, vx, vy, vz, e0, e1, e2, e3, wx, wy, wz]\n",
467-
" altitude_ASL = state[2]\n",
468-
" altitude_AGL = altitude_ASL - env.elevation\n",
469-
" vx, vy, vz = state[3], state[4], state[5]\n",
470-
"\n",
471-
" # Get winds in x and y directions\n",
472-
" wind_x, wind_y = (\n",
473-
" env.wind_velocity_x(altitude_ASL),\n",
474-
" env.wind_velocity_y(altitude_ASL),\n",
475-
" )\n",
476-
"\n",
477-
" # Calculate Mach number\n",
478-
" free_stream_speed = ((wind_x - vx) ** 2 + (wind_y - vy) ** 2 + (vz) ** 2) ** 0.5\n",
479-
" mach_number = free_stream_speed / env.speed_of_sound(altitude_ASL)\n",
480-
"\n",
481-
" # Get previous state from state_history\n",
482-
" previous_state = state_history[-1]\n",
483-
" previous_vz = previous_state[5]\n",
484-
"\n",
485-
" # If we wanted to we could get the returned values from observed_variables:\n",
486-
" # returned_time, deployment_level, drag_coefficient = observed_variables[-1]\n",
487-
"\n",
488-
" # Check if the rocket has reached burnout\n",
489-
" accelerometer = sensors[0]\n",
490-
" if accelerometer.measurement[2] > 0:\n",
491-
" return None\n",
492-
"\n",
493-
" # If below 1500 meters above ground level, air_brakes are not deployed\n",
494-
" if altitude_AGL < 1500:\n",
495-
" air_brakes.deployment_level = 0\n",
496-
"\n",
497-
" # Else calculate the deployment level\n",
498-
" else:\n",
499-
" # Controller logic\n",
500-
" new_deployment_level = (\n",
501-
" air_brakes.deployment_level + 0.1 * vz + 0.01 * previous_vz**2\n",
502-
" )\n",
503-
"\n",
504-
" # Limiting the speed of the air_brakes to 0.2 per second\n",
505-
" # Since this function is called every 1/sampling_rate seconds\n",
506-
" # the max change in deployment level per call is 0.2/sampling_rate\n",
507-
" max_change = 0.2 / sampling_rate\n",
508-
" lower_bound = air_brakes.deployment_level - max_change\n",
509-
" upper_bound = air_brakes.deployment_level + max_change\n",
510-
" new_deployment_level = min(max(new_deployment_level, lower_bound), upper_bound)\n",
511-
"\n",
512-
" air_brakes.deployment_level = new_deployment_level\n",
513-
"\n",
514-
" # Return variables of interest to be saved in the observed_variables list\n",
515-
" return (\n",
516-
" time,\n",
517-
" air_brakes.deployment_level,\n",
518-
" air_brakes.drag_coefficient(air_brakes.deployment_level, mach_number),\n",
519-
" )"
520-
]
462+
"source": "def controller_function(**kwargs):\n # state = [x, y, z, vx, vy, vz, e0, e1, e2, e3, wx, wy, wz]\n time = kwargs[\"time\"]\n sampling_rate = kwargs[\"sampling_rate\"]\n state = kwargs[\"state\"]\n state_history = kwargs[\"state_history\"]\n air_brakes = kwargs[\"air_brakes\"]\n sensors = kwargs[\"sensors\"]\n environment = kwargs[\"environment\"]\n\n altitude_ASL = state[2]\n altitude_AGL = kwargs[\"height_above_ground_level\"]\n vx, vy, vz = state[3], state[4], state[5]\n\n # Get winds in x and y directions\n wind_x, wind_y = (\n environment.wind_velocity_x(altitude_ASL),\n environment.wind_velocity_y(altitude_ASL),\n )\n\n # Calculate Mach number\n free_stream_speed = ((wind_x - vx) ** 2 + (wind_y - vy) ** 2 + (vz) ** 2) ** 0.5\n mach_number = free_stream_speed / environment.speed_of_sound(altitude_ASL)\n\n # Get previous state from state_history\n previous_state = state_history[-1]\n previous_vz = previous_state[5]\n\n # Check if the rocket has reached burnout\n accelerometer = sensors[0]\n if accelerometer.measurement[2] > 0:\n return None\n\n # If below 1500 meters above ground level, air_brakes are not deployed\n if altitude_AGL < 1500:\n air_brakes.deployment_level = 0\n\n # Else calculate the deployment level\n else:\n # Controller logic\n new_deployment_level = (\n air_brakes.deployment_level + 0.1 * vz + 0.01 * previous_vz**2\n )\n\n # Limiting the speed of the air_brakes to 0.2 per second\n # Since this function is called every 1/sampling_rate seconds\n # the max change in deployment level per call is 0.2/sampling_rate\n max_change = 0.2 / sampling_rate\n lower_bound = air_brakes.deployment_level - max_change\n upper_bound = air_brakes.deployment_level + max_change\n new_deployment_level = min(max(new_deployment_level, lower_bound), upper_bound)\n\n air_brakes.deployment_level = new_deployment_level\n\n # Return variables of interest to be saved in the observed_variables list\n return (\n time,\n air_brakes.deployment_level,\n air_brakes.drag_coefficient(air_brakes.deployment_level, mach_number),\n )\n"
521463
},
522464
{
523465
"cell_type": "code",
@@ -901,4 +843,4 @@
901843
},
902844
"nbformat": 4,
903845
"nbformat_minor": 2
904-
}
846+
}

docs/user/airbrakes.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,16 @@ Lets define the controller function:
166166

167167
.. jupyter-execute::
168168

169-
def controller_function(
170-
time, sampling_rate, state, state_history, observed_variables, air_brakes, sensors, environment
171-
):
169+
def controller_function(**kwargs):
172170
# state = [x, y, z, vx, vy, vz, e0, e1, e2, e3, wx, wy, wz]
171+
time = kwargs["time"]
172+
state = kwargs["state"]
173+
sampling_rate = kwargs["sampling_rate"]
174+
motor = kwargs["rocket"].motor
175+
environment = kwargs["environment"]
176+
air_brakes = kwargs["air_brakes"]
173177
altitude_ASL = state[2]
174-
altitude_AGL = altitude_ASL - environment.elevation
178+
altitude_AGL = kwargs["height_above_ground_level"]
175179
vx, vy, vz = state[3], state[4], state[5]
176180
177181
# Get winds in x and y directions
@@ -184,15 +188,15 @@ Lets define the controller function:
184188
mach_number = free_stream_speed / environment.speed_of_sound(altitude_ASL)
185189

186190
# Get previous state from state_history
187-
previous_state = state_history[-1]
191+
previous_state = kwargs["state_history"][-1]
188192
previous_vz = previous_state[5]
189193

190194
# If we wanted to we could get the returned values from observed_variables:
191195
# returned_time, deployment_level, drag_coefficient = observed_variables[-1]
192196

193197
# Check if the rocket has reached burnout
194-
if time < Pro75M1670.burn_out_time:
195-
return None
198+
if time < motor.burn_out_time:
199+
air_brakes.deployment_level = 0
196200

197201
# If below 1500 meters above ground level, air_brakes are not deployed
198202
if altitude_AGL < 1500:
@@ -417,7 +421,7 @@ Then we can plot the data we want.
417421

418422
time_list, deployment_level_list, drag_coefficient_list = [], [], []
419423

420-
obs_vars = test_flight.get_controller_observed_variables()
424+
obs_vars = test_flight._controllers[0].log
421425

422426
for time, deployment_level, drag_coefficient in obs_vars:
423427
time_list.append(time)

0 commit comments

Comments
 (0)