Skip to content

Commit a901b45

Browse files
ENH: adding rocket radius to RailButtons class (#643)
* ENH: Enabling the creation of Rail Buttons separately (adding the rocket_radius attribute to the RailButtons class). Improvement of the Railbuttons class. * ENH: removing unnecessary try except * ENH: improve try/except block * DEV: adds 643 to changelog * ENH: improves add_surfaces for rail buttons --------- Co-authored-by: Gui-FernandesBR <[email protected]>
1 parent cbd6a1d commit a901b45

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Attention: The newest changes should be on top -->
3535
-
3636

3737
### Changed
38-
39-
-
38+
39+
- ENH: Adding rocket radius to RailButtons class [#643](https://github.com/RocketPy-Team/RocketPy/pull/643)
4040

4141
### Fixed
4242

@@ -50,10 +50,10 @@ You can install this version by running `pip install rocketpy==1.4.1`
5050

5151
- Bumps rocketpy version to 1.4.1 [#646](https://github.com/RocketPy-Team/RocketPy/pull/646)
5252
- ENH: Insert apogee state into solution list during flight simulation [#638](https://github.com/RocketPy-Team/RocketPy/pull/638)
53+
- MNT: Refactor AeroSurfaces [#634](https://github.com/RocketPy-Team/RocketPy/pull/634)
5354
- ENH: Environment class major refactor may 2024 [#605](https://github.com/RocketPy-Team/RocketPy/pull/605)
5455
- MNT: Refactors the code to adopt flake8 [#631](https://github.com/RocketPy-Team/RocketPy/pull/631)
5556
- MNT: Refactors the code to adopt pylint [#621](https://github.com/RocketPy-Team/RocketPy/pull/621)
56-
- MNT: Refactor AeroSurfaces [#634](https://github.com/RocketPy-Team/RocketPy/pull/634)
5757

5858
## [1.4.0] - 2024-07-06
5959

rocketpy/rocket/aero_surface/rail_buttons.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ class RailButtons(AeroSurface):
1717
relative to one of the other principal axis.
1818
"""
1919

20-
def __init__(self, buttons_distance, angular_position=45, name="Rail Buttons"):
20+
def __init__(
21+
self,
22+
buttons_distance,
23+
angular_position=45,
24+
name="Rail Buttons",
25+
rocket_radius=None,
26+
):
2127
"""Initializes RailButtons Class.
2228
2329
Parameters
@@ -30,6 +36,10 @@ def __init__(self, buttons_distance, angular_position=45, name="Rail Buttons"):
3036
relative to one of the other principal axis.
3137
name : string, optional
3238
Name of the rail buttons. Default is "Rail Buttons".
39+
rocket_radius : int, float, optional
40+
Radius of the rocket at the location of the rail buttons in meters.
41+
If not provided, it will be calculated when the RailButtons object
42+
is added to a Rocket object.
3343
3444
Returns
3545
-------
@@ -40,7 +50,7 @@ def __init__(self, buttons_distance, angular_position=45, name="Rail Buttons"):
4050
self.buttons_distance = buttons_distance
4151
self.angular_position = angular_position
4252
self.name = name
43-
53+
self.rocket_radius = rocket_radius
4454
self.evaluate_lift_coefficient()
4555
self.evaluate_center_of_pressure()
4656

rocketpy/rocket/rocket.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ def add_surfaces(self, surfaces, positions):
947947
the root chord which is highest in the rocket coordinate system.
948948
For Tail type, position is relative to the point belonging to the
949949
tail which is highest in the rocket coordinate system.
950+
For RailButtons type, position is relative to the lower rail button.
950951
951952
See Also
952953
--------
@@ -956,11 +957,16 @@ def add_surfaces(self, surfaces, positions):
956957
-------
957958
None
958959
"""
959-
try:
960-
for surface, position in zip(surfaces, positions):
960+
if not isinstance(surfaces, list):
961+
surfaces = [surfaces]
962+
positions = [positions]
963+
964+
for surface, position in zip(surfaces, positions):
965+
if isinstance(surface, RailButtons):
966+
surface.rocket_radius = surface.rocket_radius or self.radius
967+
self.rail_buttons.add(surface, position)
968+
else:
961969
self.aerodynamic_surfaces.add(surface, position)
962-
except TypeError:
963-
self.aerodynamic_surfaces.add(surfaces, positions)
964970

965971
self.evaluate_center_of_pressure()
966972
self.evaluate_stability_margin()
@@ -1512,6 +1518,7 @@ def set_rail_buttons(
15121518
rail_buttons = RailButtons(
15131519
buttons_distance=buttons_distance, angular_position=angular_position
15141520
)
1521+
rail_buttons.rocket_radius = rail_buttons.rocket_radius or self.radius
15151522
self.rail_buttons.add(rail_buttons, lower_button_position)
15161523
return rail_buttons
15171524

tests/unit/test_rocket.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,15 @@ def test_set_rail_button(calisto):
392392
].position == pytest.approx(0.2, 1e-12)
393393

394394

395+
def test_add_rail_button(calisto, calisto_rail_buttons):
396+
calisto.add_surfaces(calisto_rail_buttons, -0.5)
397+
assert calisto.rail_buttons[0].position == -0.5
398+
upper_position = (
399+
calisto_rail_buttons.buttons_distance + calisto.rail_buttons[0].position
400+
)
401+
assert upper_position == pytest.approx(0.2, 1e-12)
402+
403+
395404
def test_evaluate_total_mass(calisto_motorless):
396405
"""Tests the evaluate_total_mass method of the Rocket class.
397406
Both with respect to return instances and expected behaviour.

0 commit comments

Comments
 (0)