Skip to content

Commit c2b963f

Browse files
committed
ENH: merged dis+con and added None for sampling rate of cont
1 parent ccce75d commit c2b963f

3 files changed

Lines changed: 7 additions & 50 deletions

File tree

rocketpy/control/controller.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import math
21
from inspect import signature
32
from typing import Iterable
43

@@ -18,7 +17,7 @@ def __init__(
1817
self,
1918
interactive_objects,
2019
controller_function,
21-
sampling_rate=math.inf,
20+
sampling_rate=None,
2221
initial_observed_variables=None,
2322
name="Controller",
2423
):
@@ -73,8 +72,8 @@ def __init__(
7372
relevant information in the `observed_variables` list.
7473
7574
.. note:: The function will be called according to the sampling rate
76-
specified. If unspecified, the default sampling rate is set to infinity, meaning that the
77-
controller function will be called at every step of the simulation.
75+
specified. If unspecified, the default sampling rate is set to None, meaning that the
76+
controller function will be called at every solver step of the simulation.
7877
sampling_rate : float
7978
The sampling rate of the controller function in Hertz (Hz). This
8079
means that the controller function will be called every

rocketpy/rocket/rocket.py

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,8 @@ def _add_controllers(self, controllers):
11691169
except TypeError:
11701170
self._controllers.append(controllers)
11711171

1172+
return controllers
1173+
11721174
def add_tail(
11731175
self, top_radius, bottom_radius, length, position, radius=None, name="Tail"
11741176
):
@@ -2002,50 +2004,6 @@ def add_thrust_eccentricity(self, x, y):
20022004
self.thrust_eccentricity_y = y
20032005
return self
20042006

2005-
def add_discrete_controller(
2006-
self,
2007-
controller_function,
2008-
refresh_rate,
2009-
interactive_objects=None,
2010-
initial_observed_variables=None,
2011-
name="Controller",
2012-
):
2013-
"""Creates a new discrete controller, storing its parameters such as
2014-
controller function, refresh rate, and interactive objects. The controller
2015-
will be called at the specified refresh rate during the simulation."""
2016-
2017-
controller = _Controller(
2018-
controller_function=controller_function,
2019-
sampling_rate=refresh_rate,
2020-
interactive_objects=interactive_objects,
2021-
initial_observed_variables=initial_observed_variables,
2022-
name=name,
2023-
)
2024-
2025-
self._add_controllers(controller)
2026-
2027-
def add_continuous_controller(
2028-
self,
2029-
controller_function,
2030-
interactive_objects=None,
2031-
initial_observed_variables=None,
2032-
name="Controller",
2033-
):
2034-
"""Creates a new continuous controller, storing its parameters such as
2035-
controller function and interactive objects. The controller will
2036-
be called at every time step of the simulation."""
2037-
2038-
controller = _Controller(
2039-
controller_function=controller_function,
2040-
sampling_rate=math.inf,
2041-
interactive_objects=interactive_objects,
2042-
initial_observed_variables=initial_observed_variables,
2043-
name=name,
2044-
)
2045-
2046-
self._add_controllers(controller)
2047-
return controller
2048-
20492007
def draw(self, vis_args=None, plane="xz", *, filename=None):
20502008
"""Draws the rocket in a matplotlib figure.
20512009

rocketpy/simulation/flight.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ def __init_controllers(self):
15841584
"""Initialize controllers and sensors"""
15851585
self._controllers = self.rocket._controllers[:]
15861586
self._continuous_controllers = [
1587-
c for c in self._controllers if math.isinf(c.sampling_rate)
1587+
c for c in self._controllers if c.sampling_rate is None
15881588
]
15891589
self.sensors = self.rocket.sensors.get_components()
15901590

@@ -4499,7 +4499,7 @@ def add_parachutes(self, parachutes, t_init, t_end):
44994499
def add_controllers(self, controllers, t_init, t_end):
45004500
for controller in controllers:
45014501
# Skip node creation for continuous controllers
4502-
if math.isinf(controller.sampling_rate):
4502+
if controller.sampling_rate is None:
45034503
continue
45044504
# Calculate start of sampling time nodes
45054505
controller_time_step = 1 / controller.sampling_rate

0 commit comments

Comments
 (0)