From f06c4c2b7b7ceba5a2ed8eb56900e4864dad8352 Mon Sep 17 00:00:00 2001 From: MateusStano Date: Thu, 3 Oct 2024 13:39:12 +0200 Subject: [PATCH 1/5] BUG: add rail buttons checks in add_surfaces --- rocketpy/rocket/rocket.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index fe0c803b5..fc5aba482 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -966,6 +966,21 @@ 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.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 @@ -973,7 +988,7 @@ def add_surfaces(self, surfaces, positions): 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 @@ -996,22 +1011,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() From 973eda1d0f654e938ff873ea6626acdaf21555f3 Mon Sep 17 00:00:00 2001 From: MateusStano Date: Thu, 3 Oct 2024 13:52:43 +0200 Subject: [PATCH 2/5] BUG: restart rail buttons components --- rocketpy/rocket/rocket.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index fc5aba482..61de81f27 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -976,6 +976,7 @@ def __add_single_surface(self, surface, position): else Vector(position) ) if isinstance(surface, RailButtons): + self.rail_buttons = Components() self.rail_buttons.add(surface, position) else: self.aerodynamic_surfaces.add(surface, position) From 0777612daeeeedb13acc10be2a19d64230c20e4a Mon Sep 17 00:00:00 2001 From: MateusStano Date: Sun, 6 Oct 2024 14:39:34 +0200 Subject: [PATCH 3/5] BUG: save initial_observed_variables on self --- rocketpy/control/controller.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rocketpy/control/controller.py b/rocketpy/control/controller.py index 93a13ecfd..d67ef5282 100644 --- a/rocketpy/control/controller.py +++ b/rocketpy/control/controller.py @@ -86,6 +86,7 @@ def __init__( self.interactive_objects = interactive_objects self.controller_function = self.__init_controller_function(controller_function) self.sampling_rate = sampling_rate + self.initial_observed_variables = initial_observed_variables self.name = name self.prints = _ControllerPrints(self) From ddbccb36356b99cb627e039c11b19cb34954d1b5 Mon Sep 17 00:00:00 2001 From: MateusStano Date: Sun, 6 Oct 2024 15:52:20 +0200 Subject: [PATCH 4/5] ENH: create self.base_controller_function --- rocketpy/control/controller.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rocketpy/control/controller.py b/rocketpy/control/controller.py index d67ef5282..a68de1a28 100644 --- a/rocketpy/control/controller.py +++ b/rocketpy/control/controller.py @@ -84,6 +84,7 @@ def __init__( None """ self.interactive_objects = interactive_objects + self.base_controller_function = controller_function self.controller_function = self.__init_controller_function(controller_function) self.sampling_rate = sampling_rate self.initial_observed_variables = initial_observed_variables From 5aee235d1c30c87805bf96dea800a0881aaaa9b6 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Wed, 9 Oct 2024 02:17:31 -0300 Subject: [PATCH 5/5] DEV: updates changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a7090983..dae262128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Attention: The newest changes should be on top --> ### Fixed +- BUG: Initialize _Controller Init Parameters [#703](https://github.com/RocketPy-Team/RocketPy/pull/703) - 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) - BUG: Single Point Functions Can Not Be Defined [#700](https://github.com/RocketPy-Team/RocketPy/pull/700)