Skip to content

Commit 8005408

Browse files
committed
Add control functions as individual pipeline stages
1 parent ed1a4e6 commit 8005408

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

crazyflow/sim/sim.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def __init__(
109109
# The ``select_xxx_fn`` methods return functions, not the results of calling those
110110
# functions. They act as factories that produce building blocks for the construction of our
111111
# simulation pipeline.
112-
self.step_pipeline += (build_control_fn(self.control, self.physics),)
112+
self.step_pipeline += build_control_fns(self.control, self.physics)
113113
physics_fn = select_physics_fn(self.physics)
114114
self.step_pipeline += (select_integrate_fn(self.integrator, physics_fn),)
115115
self.step_pipeline += (increment_steps,)
@@ -397,8 +397,15 @@ def _step(data: SimData, n_steps: int) -> SimData:
397397
raise NotInitializedError("_step call before building the simulation pipeline.")
398398

399399

400-
def build_control_fn(control: Control, physics: Physics) -> Callable[[SimData], SimData]:
401-
"""Select the control function for the given control mode."""
400+
def build_control_fns(
401+
control: Control, physics: Physics
402+
) -> tuple[Callable[[SimData], SimData], ...]:
403+
"""Select the control functions for the given control mode.
404+
405+
Note:
406+
This function returns a tuple of functions, not a single function. The returned functions
407+
are called in succession in the simulation pipeline.
408+
"""
402409
match control:
403410
case Control.state:
404411
control_pipeline = (step_state_controller, step_attitude_controller)
@@ -416,12 +423,7 @@ def build_control_fn(control: Control, physics: Physics) -> Callable[[SimData],
416423
case _:
417424
raise NotImplementedError(f"Control mode {control} not implemented")
418425

419-
def control(data: SimData) -> SimData:
420-
for fn in control_pipeline:
421-
data = fn(data)
422-
return data
423-
424-
return control
426+
return control_pipeline
425427

426428

427429
def select_physics_fn(physics: Physics) -> Callable[[SimData], SimData]:

0 commit comments

Comments
 (0)