Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Air Brakes #426

Merged
merged 81 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
05fbc54
ENH: create controller class
MateusStano Sep 29, 2023
fd2a095
ENH: create Airbreaks class
MateusStano Sep 29, 2023
528eea2
ENH: create add_controllers and add_airbreaks
MateusStano Sep 29, 2023
89e5ed2
BUG: typos and imports
MateusStano Oct 2, 2023
cb6dbb0
ENH: add controllers to TimeNodes and add airbrakes drag calculation
MateusStano Oct 2, 2023
5c1dbb1
Merge branch 'develop' into enh/air-brakes
MateusStano Oct 8, 2023
47e4342
DOC: improve controller docs
MateusStano Oct 9, 2023
dea58ae
ENH: add airbrakes plots, prints, docs and `reference_area`
MateusStano Oct 9, 2023
37baaea
ENH: adjust flight for saving airbrakes data and variable reference area
MateusStano Oct 9, 2023
7a971ae
DOC: add airbrakes example notebook
MateusStano Oct 9, 2023
f2979aa
DOC: save airbrakes notebook outputs
MateusStano Oct 9, 2023
5da6e91
MNT: clear out unecessary comments
giovaniceotto Oct 11, 2023
83d28dd
MNT: clear out unecessary comments
giovaniceotto Oct 11, 2023
04e02c8
MNT: fix and improve airbrakes info and all_info
giovaniceotto Oct 11, 2023
5075a82
MNT: quick polish of airbrakes example notebook and add it to docs
giovaniceotto Oct 11, 2023
9a31ef6
Fix code style issues with Black
lint-action Oct 11, 2023
46974de
Merge remote-tracking branch 'origin/develop' into enh/air-brakes
MateusStano Oct 11, 2023
b22f4e7
MNT:
Gui-FernandesBR Oct 15, 2023
480258f
Merge branch 'develop' into enh/air-brakes
MateusStano Nov 21, 2023
00a4687
MNT: change Airbrakes to AirBrakes
MateusStano Nov 21, 2023
4209367
DOC: improve doc to clearify deployed level 0 and add reference docs
MateusStano Nov 21, 2023
59362ae
MNT: rename airbrakes to air_brakes
MateusStano Nov 21, 2023
89a7231
MNT: rename files for name consistency
MateusStano Nov 21, 2023
22bf47d
Update rocketpy/simulation/flight.py
MateusStano Nov 21, 2023
6813573
BUG: fix 2d csv Function definition and missing set_get_value_opt
MateusStano Nov 21, 2023
692de64
TST: add tests with 2d csv Funciton
MateusStano Nov 21, 2023
8163102
Merge branch 'hotfix/2d-csv-functions' into enh/air-brakes
MateusStano Nov 21, 2023
e0a7aca
ENH: add state_list, state_list_history update and finalize state met…
MateusStano Nov 22, 2023
4840bf3
Fix code style issues with Black
lint-action Nov 22, 2023
e123897
ENH: add samplinga_rate and state_history to controller_function
MateusStano Nov 22, 2023
bc84343
Merge branch 'enh/air-brakes' of https://github.com/RocketPy-Team/Roc…
MateusStano Nov 22, 2023
2bb2d2b
ENH: add clamp argument
MateusStano Nov 26, 2023
085ad11
Merge branch 'develop' into enh/air-brakes
MateusStano Nov 28, 2023
7906efa
ENH: improve clamp
MateusStano Nov 28, 2023
4a363ae
DOC: create air brakes .rst
MateusStano Nov 28, 2023
1e8a0cb
ENH: change cd to drag_coefficient
MateusStano Nov 28, 2023
7ff9c06
BUG: fix initial previous_state
MateusStano Nov 28, 2023
1f787b9
TST: add air brakes tests
MateusStano Nov 28, 2023
ef93760
MNT: Fix typos in airbrakes documentation
Gui-FernandesBR Dec 2, 2023
8b6609a
Update rocketpy/control/controller.py
MateusStano Dec 7, 2023
5c33807
Update rocketpy/plots/aero_surface_plots.py
MateusStano Dec 7, 2023
c4677e4
Update rocketpy/plots/aero_surface_plots.py
MateusStano Dec 7, 2023
89ed9fa
MNT: remove return None from aero plots
MateusStano Dec 7, 2023
6c3a668
MNT: controller docs and air brakes prints
MateusStano Dec 7, 2023
8ba8202
ENH: remove state list and add saved returns for controller_function
MateusStano Dec 8, 2023
34622e8
MNT: controllable_objects to interactable_objects
MateusStano Dec 8, 2023
bf0fb81
ENH: fix initial_observed_values
MateusStano Dec 8, 2023
ff2e143
Update rocketpy/control/controller.py
MateusStano Dec 15, 2023
260e8d8
DOC: update docs
MateusStano Dec 18, 2023
a631b6f
TST: update tests
MateusStano Dec 18, 2023
995b97a
Merge pull request #507 from RocketPy-Team/enh/new-controller-structure
MateusStano Dec 18, 2023
127b93d
Merge branch 'develop' into enh/air-brakes
MateusStano Dec 18, 2023
db9abb7
Fix code style issues with Black
lint-action Dec 18, 2023
2a3dda4
Update docs/user/airbrakes.rst
MateusStano Jan 21, 2024
2ce1192
Update docs/user/airbrakes.rst
MateusStano Jan 21, 2024
7ad0311
Update docs/user/airbrakes.rst
MateusStano Jan 21, 2024
7c752fe
Update docs/user/airbrakes.rst
MateusStano Jan 21, 2024
271e7d7
Update rocketpy/control/controller.py
MateusStano Jan 21, 2024
a0bc59d
Update rocketpy/control/controller.py
MateusStano Jan 21, 2024
347f4b8
Update rocketpy/control/controller.py
MateusStano Jan 21, 2024
7594cb9
Update rocketpy/prints/control_prints.py
MateusStano Jan 21, 2024
dc3262b
Update rocketpy/prints/control_prints.py
MateusStano Jan 21, 2024
a8076be
Update rocketpy/prints/control_prints.py
MateusStano Jan 21, 2024
905fd87
Update rocketpy/rocket/aero_surface.py
MateusStano Jan 21, 2024
fa81545
ENH: minor fixes
MateusStano Jan 21, 2024
c0408ce
ENH: add `substitute_rocket_drag_coefficient`
MateusStano Jan 22, 2024
b11b21d
ENH: private controller class and related attributes
MateusStano Jan 24, 2024
11df71f
ENH: add get_controller_observed_variables
MateusStano Jan 24, 2024
711a7dc
Merge branch 'develop' into enh/air-brakes
MateusStano Jan 25, 2024
aad48bd
Fix code style issues with Black
lint-action Jan 25, 2024
2a1ab07
MNT: Remove duplicated altitude method from Flight class
Gui-FernandesBR Jan 26, 2024
dd44384
MNT: apply isort and simplify statements
Gui-FernandesBR Jan 26, 2024
862bfa9
DOC: update air brakes notebook
Gui-FernandesBR Jan 26, 2024
43632dc
Fix code style issues with Black
lint-action Jan 26, 2024
bf07e2e
MNT: change `interactable` to `interactive`
MateusStano Jan 27, 2024
465c74a
MNT: minor improvements to variable names and controller function
MateusStano Jan 27, 2024
24b9b09
MNT: init deployment_level with settet and add_airbrakes maint
MateusStano Jan 31, 2024
85f3a47
Fix code style issues with Black
lint-action Jan 31, 2024
4ee4c7d
ENH: remove set_deployment_level and cached_property
MateusStano Feb 1, 2024
ce6d2ab
Merge branch 'develop' into enh/air-brakes
MateusStano Feb 5, 2024
e73aee1
MNT: update changelog
MateusStano Feb 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions data/calisto/airbrakes_cd.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
0.0, 0.0, 0.000
0.0, 0.1, 0.000
0.0, 0.2, 0.000
0.0, 0.3, 0.000
0.0, 0.4, 0.000
0.0, 0.5, 0.000
0.0, 0.6, 0.000
0.0, 0.7, 0.000
0.0, 0.8, 0.000
0.0, 0.9, 0.000
0.0, 1.0, 0.000
0.0, 1.1, 0.000
0.1, 0.0, 0.000
0.2, 0.0, 0.000
0.3, 0.0, 0.000
0.4, 0.0, 0.000
0.5, 0.0, 0.000
0.6, 0.0, 0.000
0.7, 0.0, 0.000
0.8, 0.0, 0.000
0.9, 0.0, 0.000
1.0, 0.0, 0.000
1.1, 0.0, 0.000
0.1, 0.1, 0.000
0.1, 0.2, 0.000
0.1, 0.3, 0.045
0.1, 0.4, 0.022
0.1, 0.5, 0.026
0.1, 0.6, 0.076
0.1, 0.7, 0.051
0.1, 0.8, 0.058
0.1, 0.9, 0.022
0.1, 1.0, 0.000
0.1, 1.1, 0.000
0.2, 0.1, 0.022
0.2, 0.2, 0.062
0.2, 0.3, 0.093
0.2, 0.4, 0.076
0.2, 0.5, 0.070
0.2, 0.6, 0.129
0.2, 0.7, 0.102
0.2, 0.8, 0.115
0.2, 0.9, 0.084
0.2, 1.0, 0.018
0.2, 1.1, 0.000
0.3, 0.1, 0.056
0.3, 0.2, 0.106
0.3, 0.3, 0.147
0.3, 0.4, 0.139
0.3, 0.5, 0.139
0.3, 0.6, 0.183
0.3, 0.7, 0.169
0.3, 0.8, 0.183
0.3, 0.9, 0.149
0.3, 1.0, 0.093
0.3, 1.1, 0.070
0.4, 0.1, 0.120
0.4, 0.2, 0.169
0.4, 0.3, 0.214
0.4, 0.4, 0.195
0.4, 0.5, 0.214
0.4, 0.6, 0.262
0.4, 0.7, 0.253
0.4, 0.8, 0.271
0.4, 0.9, 0.253
0.4, 1.0, 0.192
0.4, 1.1, 0.164
0.5, 0.1, 0.217
0.5, 0.2, 0.217
0.5, 0.3, 0.275
0.5, 0.4, 0.257
0.5, 0.5, 0.284
0.5, 0.6, 0.349
0.5, 0.7, 0.340
0.5, 0.8, 0.360
0.5, 0.9, 0.340
0.5, 1.0, 0.288
0.5, 1.1, 0.253
0.6, 0.1, 0.245
0.6, 0.2, 0.288
0.6, 0.3, 0.382
0.6, 0.4, 0.360
0.6, 0.5, 0.382
0.6, 0.6, 0.457
0.6, 0.7, 0.445
0.6, 0.8, 0.447
0.6, 0.9, 0.434
0.6, 1.0, 0.403
0.6, 1.1, 0.360
0.7, 0.1, 0.320
0.7, 0.2, 0.392
0.7, 0.3, 0.487
0.7, 0.4, 0.476
0.7, 0.5, 0.476
0.7, 0.6, 0.564
0.7, 0.7, 0.527
0.7, 0.8, 0.531
0.7, 0.9, 0.527
0.7, 1.0, 0.520
0.7, 1.1, 0.487
0.8, 0.1, 0.426
0.8, 0.2, 0.507
0.8, 0.3, 0.568
0.8, 0.4, 0.538
0.8, 0.5, 0.538
0.8, 0.6, 0.617
0.8, 0.7, 0.613
0.8, 0.8, 0.624
0.8, 0.9, 0.613
0.8, 1.0, 0.520
0.8, 1.1, 0.591
0.9, 0.1, 0.507
0.9, 0.2, 0.568
0.9, 0.3, 0.613
0.9, 0.4, 0.600
0.9, 0.5, 0.609
0.9, 0.6, 0.684
0.9, 0.7, 0.684
0.9, 0.8, 0.702
0.9, 0.9, 0.708
0.9, 1.0, 0.624
0.9, 1.1, 0.674
1.0, 0.1, 0.937
1.0, 0.2, 0.937
1.0, 0.3, 0.937
1.0, 0.4, 0.887
1.0, 0.5, 0.803
1.0, 0.6, 0.930
1.0, 0.7, 0.887
1.0, 0.8, 0.921
1.0, 0.9, 0.815
1.0, 1.0, 0.844
1.0, 1.1, 0.803
1,114 changes: 1,114 additions & 0 deletions docs/notebooks/airbrakes_example.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions rocketpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
TankGeometry,
UllageBasedTank,
)
from .control import Controller
from .rocket import (
AeroSurface,
Components,
Expand Down
1 change: 1 addition & 0 deletions rocketpy/control/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .controller import Controller
87 changes: 87 additions & 0 deletions rocketpy/control/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from ..prints.control_prints import _ControllerPrints


class Controller:
"""A class for storing and running controllers on a rocket."""

def __init__(
self,
observed_objects,
controller_function,
Gui-FernandesBR marked this conversation as resolved.
Show resolved Hide resolved
sampling_rate,
name="Controller",
):
"""Initialize the class with the controller function and the objects to
be observed.

Parameters
----------
observed_objects : list
A list of objects to be observed by the controller. It can be any
python object. This list will be passed to the controller function
as positional arguments, meaning that the order of the objects in
this list matters. These objects will then be able to be accessed
and modified by the controller function.
controller_function : function, callable
A function that takes the following arguments, in this order:

1. Time of the simulation at the current step in seconds.
2. The state vector of the simulation, which is defined as:

MateusStano marked this conversation as resolved.
Show resolved Hide resolved
`[x, y, z, vx, vy, vz, e0, e1, e2, e3, wx, wy, wz]`.
3. A list containing the objects to be acted upon by the controller.
The objects in this list are the same as the objects in the
observed_objects list, but they can be modified by the controller.

This function will be called during the simulation at the specified
sampling rate. The function should evaluate and change the observed
objects as needed. The function should return None.

Note: The function will be called according to the sampling rate
specified.

sampling_rate : float
The sampling rate of the controller function in Hertz (Hz). This
means that the controller function will be called every
`1/sampling_rate` seconds.
name : str
The name of the controller. This will be used for printing and
plotting.

Returns
-------
None
"""

self.observed_objects = observed_objects
self.controller_function = controller_function
self.sampling_rate = sampling_rate
self.name = name
self.print = _ControllerPrints

def __call__(self, time, state_vector):
"""Call the controller function. This is used by the simulation class.

Parameters
----------
time : float
The time of the simulation in seconds.
state_vector : list
The state vector of the simulation, which is defined as:

`[x, y, z, vx, vy, vz, e0, e1, e2, e3, wx, wy, wz]`.

Returns
-------
None
"""
self.controller_function(time, state_vector, self.observed_objects)

def __str__(self):
return self.name

MateusStano marked this conversation as resolved.
Show resolved Hide resolved
def info(self):
self.prints.all()

def all_info(self):
self.info()
81 changes: 81 additions & 0 deletions rocketpy/plots/aero_surface_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,84 @@ def __init__(self, tail):
def draw(self):
# This will de done in the future
return None


class _AirbrakesPlots(_AeroSurfacePlots):
"""Class that contains all airbrakes plots."""

def __init__(self, airbrakes):
"""Initialize the class

Parameters
----------
airbrakes : rocketpy.AeroSurface.airbrakes
Airbrakes object to be plotted

Returns
-------
None
"""
super().__init__(airbrakes)
return None
MateusStano marked this conversation as resolved.
Show resolved Hide resolved

def cd_curve(self):
return self.aero_surface.cd.plot(0, 1)

def deployed_level(self):
"""Plots the deployed level of the airbrakes as a function of time.

Returns
-------
None
"""
# Extract the first and second columns as x and y
x = [row[0] for row in self.aero_surface.state_history]
y = [row[1] for row in self.aero_surface.state_history]

# Create the plot
plt.figure(figsize=(10, 6))
plt.scatter(x, y, marker="o", linestyle="-", color="b", s=0.5)
plt.xlabel("Time (s)")
plt.ylabel("Deployed Level")
plt.title("Deployed Level X Time (s)")
plt.grid(True)
plt.show()

return None
MateusStano marked this conversation as resolved.
Show resolved Hide resolved

def cd(self):
MateusStano marked this conversation as resolved.
Show resolved Hide resolved
"""Plots the drag coefficient of the airbrakes as a function of time.

Returns
-------
None
"""
# Extract the first and second columns as x and y
x = [row[0] for row in self.aero_surface.state_history]
y = [row[2] for row in self.aero_surface.state_history]

# Create the plot
plt.figure(figsize=(10, 6))
plt.scatter(x, y, marker="o", linestyle="-", color="b", s=0.5)
plt.xlabel("Time (s)")
plt.ylabel("Drag Coefficient")
plt.title("Drag Coefficient X Time (s)")
plt.grid(True)
plt.show()

return None
MateusStano marked this conversation as resolved.
Show resolved Hide resolved

def draw(self):
raise NotImplementedError
MateusStano marked this conversation as resolved.
Show resolved Hide resolved

def all(self):
"""Plots all available airbrakes plots.

Returns
-------
None
"""
self.deployed_level()
self.cd()
self.cd_curve()
return None
MateusStano marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions rocketpy/prints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
_RailButtonsPrints,
_TailPrints,
_TrapezoidalFinsPrints,
_AirbrakesPrints,
)
from .compare_prints import _ComparePrints
from .environment_analysis_prints import _EnvironmentAnalysisPrints
Expand Down
38 changes: 38 additions & 0 deletions rocketpy/prints/aero_surface_prints.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,41 @@ def geometry(self):
f"Angular position of the buttons: {self.aero_surface.angular_position:.3f} deg\n"
)
return None


class _AirbrakesPrints(_AeroSurfacePrints):
"""Class that contains all tail prints."""

def __init__(self, Airbrakes):
"""Initialize the class

Parameters
----------
Airbrakes : rocketpy.AeroSurface.Airbrakes
Air break object to be printed.

Returns
-------
None
"""
super().__init__(Airbrakes)
return None

def geometry(self):
"""Prints the geometric information of the air break.

Returns
-------
None
"""
print(f"Geometric information of the Air Break:")
print(f"----------------------------------")
print(
f"Current deployed level: {self.aero_surface.deployed_level:.2f} = {100*self.aero_surface.deployed_level:.0f} %"
MateusStano marked this conversation as resolved.
Show resolved Hide resolved
)
print(
f"Current Cd: {self.aero_surface.cd_curve(self.aero_surface.deployed_level)} m²"
)
print(f"Maximum Cd: {self.aero_surface.cd.max:.3f} m²")
print(f"Minimum Cd: {self.aero_surface.cd.min:.3f} m²")
return None
Loading
Loading