Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions rocketpy/rocket/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,46 @@ 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 self

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.

Expand Down
3 changes: 3 additions & 0 deletions rocketpy/simulation/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down