From be42228c8d55f38b38a11900f068e2ff5590780b Mon Sep 17 00:00:00 2001 From: Malmahrouqi3 Date: Mon, 30 Mar 2026 09:56:42 -0400 Subject: [PATCH 1/3] ENH: added discrte and continuous controller functions --- rocketpy/rocket/rocket.py | 36 +++++++++++++++++++++++++++++++++++ rocketpy/simulation/flight.py | 3 +++ 2 files changed, 39 insertions(+) diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index e3692d2e8..2fa204fd7 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -1952,6 +1952,42 @@ def add_thrust_eccentricity(self, x, y): self.thrust_eccentricity_y = y return self + def add_discrete_controller(self, + controller_function, + refresh_rate, + interactive_objects=None, + initial_observed_variables=None, + name=None + ): + + controller = _Controller( + controller_function=controller_function, + sampling_rate=refresh_rate, + interactive_objects=interactive_objects, + initial_observed_variables=initial_observed_variables, + name=name) + + self._add_controllers(controller) + + return None + + def add_continuous_controller(self, + controller_function, + interactive_objects=None, + initial_observed_variables=None, + name=None + ): + + controller = _Controller( + controller_function=controller_function, + sampling_rate=np.inf, + interactive_objects=interactive_objects, + initial_observed_variables=initial_observed_variables, + name=name) + + self._add_controllers(controller) + return controller + def draw(self, vis_args=None, plane="xz", *, filename=None): """Draws the rocket in a matplotlib figure. diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 1443d1d80..1104769af 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -4497,6 +4497,9 @@ def add_parachutes(self, parachutes, t_init, t_end): def add_controllers(self, controllers, t_init, t_end): for controller in controllers: + # Skip node creation for continuous controllers + if math.isinf(controller.sampling_rate): + continue # Calculate start of sampling time nodes controller_time_step = 1 / controller.sampling_rate controller_node_list = [ From 6f11c5ed5296f72f15c1b81117f4e9a7f5f8d8df Mon Sep 17 00:00:00 2001 From: Malmahrouqi3 Date: Mon, 30 Mar 2026 10:19:35 -0400 Subject: [PATCH 2/3] linted rocketpy/rocket/rocket.py --- rocketpy/rocket/rocket.py | 42 +++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index 2fa204fd7..ec5772ec4 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -1952,38 +1952,42 @@ def add_thrust_eccentricity(self, x, y): self.thrust_eccentricity_y = y return self - def add_discrete_controller(self, - controller_function, - refresh_rate, - interactive_objects=None, - initial_observed_variables=None, - name=None - ): + def add_discrete_controller( + self, + controller_function, + refresh_rate, + interactive_objects=None, + initial_observed_variables=None, + name=None, + ): controller = _Controller( - controller_function=controller_function, - sampling_rate=refresh_rate, - interactive_objects=interactive_objects, - initial_observed_variables=initial_observed_variables, - name=name) + controller_function=controller_function, + sampling_rate=refresh_rate, + interactive_objects=interactive_objects, + initial_observed_variables=initial_observed_variables, + name=name, + ) self._add_controllers(controller) return None - def add_continuous_controller(self, - controller_function, - interactive_objects=None, - initial_observed_variables=None, - name=None - ): + def add_continuous_controller( + self, + controller_function, + interactive_objects=None, + initial_observed_variables=None, + name=None, + ): controller = _Controller( controller_function=controller_function, sampling_rate=np.inf, interactive_objects=interactive_objects, initial_observed_variables=initial_observed_variables, - name=name) + name=name, + ) self._add_controllers(controller) return controller From 31d80b9e25a1e1d99935e5287e8dbbe48ee972c0 Mon Sep 17 00:00:00 2001 From: Malmahrouqi3 Date: Mon, 30 Mar 2026 10:23:51 -0400 Subject: [PATCH 3/3] lint fix return None to return self in discrete controller function --- rocketpy/rocket/rocket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rocketpy/rocket/rocket.py b/rocketpy/rocket/rocket.py index ec5772ec4..9800d9e46 100644 --- a/rocketpy/rocket/rocket.py +++ b/rocketpy/rocket/rocket.py @@ -1971,7 +1971,7 @@ def add_discrete_controller( self._add_controllers(controller) - return None + return self def add_continuous_controller( self,