Skip to content

Commit

Permalink
ENH: remove set_deployment_level and cached_property
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusStano committed Feb 1, 2024
1 parent 85f3a47 commit 4ee4c7d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 36 deletions.
4 changes: 2 additions & 2 deletions docs/notebooks/air_brakes_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"\n",
" # If below 1500 meters above ground level, air_brakes are not deployed\n",
" if altitude_AGL < 1500:\n",
" air_brakes.set_deployment_level(0)\n",
" air_brakes.deployment_level = 0\n",
"\n",
" # Else calculate the deployment level\n",
" else:\n",
Expand All @@ -244,7 +244,7 @@
" 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.set_deployment_level(new_deployment_level)\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",
Expand Down
11 changes: 5 additions & 6 deletions docs/user/airbrakes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ To create an air brakes model, we essentially need to define the following:
- The **controller function**, which takes in as argument information about the
simulation up to the current time step, and the ``AirBrakes`` instance being
defined, and sets the desired air brakes' deployment level. The air brakes'
deployment level must be between 0 and 1, and must be set using the
``set_deployment_level`` method of the ``AirBrakes`` instance being controlled.
Inside this function, any controller logic, filters, and apogee prediction
can be implemented.
deployment level must be between 0 and 1, and is set using the
``deployment_level`` attribute. Inside this function, any controller logic,
filters, and apogee prediction can be implemented.

- The **sampling rate** of the controller function, in seconds. This is the time
between each call of the controller function, in simulation time. Must be
Expand Down Expand Up @@ -197,7 +196,7 @@ Lets define the controller function:

# If below 1500 meters above ground level, air_brakes are not deployed
if altitude_AGL < 1500:
air_brakes.set_deployment_level(0)
air_brakes.deployment_level = 0

# Else calculate the deployment level
else:
Expand All @@ -214,7 +213,7 @@ Lets define the controller function:
upper_bound = air_brakes.deployment_level + max_change
new_deployment_level = min(max(new_deployment_level, lower_bound), upper_bound)

air_brakes.set_deployment_level(new_deployment_level)
air_brakes.deployment_level = new_deployment_level

# Return variables of interest to be saved in the observed_variables list
return (
Expand Down
15 changes: 0 additions & 15 deletions rocketpy/rocket/aero_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,21 +2015,6 @@ def deployment_level(self, value):
)
self._deployment_level = value

def set_deployment_level(self, deployment_level):
"""Set airbrake deployment level.
Parameters
----------
deployment_level : float
Current deployment level, ranging from 0 to 1. Deployment level is the
fraction of the total airbrake area that is deployment.
Returns
-------
None
"""
self.deployment_level = deployment_level

def evaluate_center_of_pressure(self):
"""Evaluates the center of pressure of the aerodynamic surface in local
coordinates.
Expand Down
1 change: 0 additions & 1 deletion rocketpy/simulation/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -2912,7 +2912,6 @@ def retrieve_temporary_values_arrays(self):

return temporary_values

@cached_property
def get_controller_observed_variables(self):
"""Retrieve the observed variables related to air brakes from the
controllers. If there is only one set of observed variables, it is
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ def controller_function(
if time < 3.9:
return None
if z < 1500:
air_brakes.set_deployment_level(0)
air_brakes.deployment_level = 0
else:
new_deployment_level = (
air_brakes.deployment_level + 0.1 * vz + 0.01 * previous_vz**2
Expand All @@ -1295,7 +1295,7 @@ def controller_function(
new_deployment_level = air_brakes.deployment_level - 0.2 / sampling_rate
else:
new_deployment_level = air_brakes.deployment_level
air_brakes.set_deployment_level(new_deployment_level)
air_brakes.deployment_level = new_deployment_level

return controller_function

Expand Down
20 changes: 10 additions & 10 deletions tests/test_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_airfoil(
@patch("matplotlib.pyplot.show")
def test_air_brakes_clamp_on(mock_show, calisto_air_brakes_clamp_on):
"""Test the air brakes class with clamp on configuration. This test checks
the basic attributes and the set_deployment_level method. It also checks the
the basic attributes and the deployment_level setter. It also checks the
all_info method.
Parameters
Expand All @@ -160,13 +160,13 @@ def test_air_brakes_clamp_on(mock_show, calisto_air_brakes_clamp_on):
air_brakes_clamp_on.reference_area
== calisto_air_brakes_clamp_on.radius**2 * np.pi
)
air_brakes_clamp_on.set_deployment_level(0.5)
air_brakes_clamp_on.deployment_level = 0.5
assert air_brakes_clamp_on.deployment_level == 0.5
air_brakes_clamp_on.set_deployment_level(1.5)
air_brakes_clamp_on.deployment_level = 1.5
assert air_brakes_clamp_on.deployment_level == 1
air_brakes_clamp_on.set_deployment_level(-1)
air_brakes_clamp_on.deployment_level = -1
assert air_brakes_clamp_on.deployment_level == 0
air_brakes_clamp_on.set_deployment_level(0)
air_brakes_clamp_on.deployment_level = 0
assert air_brakes_clamp_on.deployment_level == 0

assert air_brakes_clamp_on.all_info() == None
Expand All @@ -175,7 +175,7 @@ def test_air_brakes_clamp_on(mock_show, calisto_air_brakes_clamp_on):
@patch("matplotlib.pyplot.show")
def test_air_brakes_clamp_off(mock_show, calisto_air_brakes_clamp_off):
"""Test the air brakes class with clamp off configuration. This test checks
the basic attributes and the set_deployment_level method. It also checks the
the basic attributes and the deployment_level setter. It also checks the
all_info method.
Parameters
Expand All @@ -195,13 +195,13 @@ def test_air_brakes_clamp_off(mock_show, calisto_air_brakes_clamp_off):
== calisto_air_brakes_clamp_off.radius**2 * np.pi
)

air_brakes_clamp_off.set_deployment_level(0.5)
air_brakes_clamp_off.deployment_level = 0.5
assert air_brakes_clamp_off.deployment_level == 0.5
air_brakes_clamp_off.set_deployment_level(1.5)
air_brakes_clamp_off.deployment_level = 1.5
assert air_brakes_clamp_off.deployment_level == 1.5
air_brakes_clamp_off.set_deployment_level(-1)
air_brakes_clamp_off.deployment_level = -1
assert air_brakes_clamp_off.deployment_level == -1
air_brakes_clamp_off.set_deployment_level(0)
air_brakes_clamp_off.deployment_level = 0
assert air_brakes_clamp_off.deployment_level == 0

assert air_brakes_clamp_off.all_info() == None

0 comments on commit 4ee4c7d

Please sign in to comment.