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

BUG: Rail Buttons Not Accepted in Add Surfaces #701

Merged
merged 10 commits into from
Oct 9, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Attention: The newest changes should be on top -->

### Fixed

- BUG: Rail Buttons Not Accepted in Add Surfaces [#701](https://github.com/RocketPy-Team/RocketPy/pull/701)
- BUG: Vector encoding breaks MonteCarlo export. [#704](https://github.com/RocketPy-Team/RocketPy/pull/704)

## [v1.6.0] - 2024-09-29
Expand Down
33 changes: 19 additions & 14 deletions rocketpy/rocket/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,14 +966,30 @@ def add_motor(self, motor, position): # pylint: disable=too-many-statements
self.evaluate_com_to_cdm_function()
self.evaluate_nozzle_gyration_tensor()

def __add_single_surface(self, surface, position):
"""Adds a single aerodynamic surface to the rocket. Makes checks for
rail buttons case, and position type.
"""
position = (
Vector([0, 0, position])
if not isinstance(position, (Vector, tuple, list))
else Vector(position)
)
if isinstance(surface, RailButtons):
self.rail_buttons = Components()
self.rail_buttons.add(surface, position)
else:
self.aerodynamic_surfaces.add(surface, position)
self.__evaluate_single_surface_cp_to_cdm(surface, position)

def add_surfaces(self, surfaces, positions):
"""Adds one or more aerodynamic surfaces to the rocket. The aerodynamic
surface must be an instance of a class that inherits from the
AeroSurface (e.g. NoseCone, TrapezoidalFins, etc.)

Parameters
----------
surfaces : list, AeroSurface, NoseCone, TrapezoidalFins, EllipticalFins, Tail
surfaces : list, AeroSurface, NoseCone, TrapezoidalFins, EllipticalFins, Tail, RailButtons
Aerodynamic surface to be added to the rocket. Can be a list of
AeroSurface if more than one surface is to be added.
positions : int, float, list, tuple, Vector
Expand All @@ -996,22 +1012,11 @@ def add_surfaces(self, surfaces, positions):
-------
None
"""
# TODO: separate this method into smaller methods: https://github.com/RocketPy-Team/RocketPy/pull/696#discussion_r1771978422
try:
for surface, position in zip(surfaces, positions):
if not isinstance(position, (Vector, tuple, list)):
position = Vector([0, 0, position])
else:
position = Vector(position)
self.aerodynamic_surfaces.add(surface, position)
self.__evaluate_single_surface_cp_to_cdm(surface, position)
self.__add_single_surface(surface, position)
except TypeError:
if not isinstance(positions, (Vector, tuple, list)):
positions = Vector([0, 0, positions])
else:
positions = Vector(positions)
self.aerodynamic_surfaces.add(surfaces, positions)
self.__evaluate_single_surface_cp_to_cdm(surfaces, positions)
self.__add_single_surface(surfaces, positions)

self.evaluate_center_of_pressure()
self.evaluate_stability_margin()
Expand Down
Loading