herostools.actor.control_loop

Control loop implementations.

Classes

ControlLoop

Base class for (slow) control loops.

PIDControlLoop

PID (Proportional-Integral-Derivative) control loop.

Module Contents

class herostools.actor.control_loop.ControlLoop(sensor: object | heros.RemoteHERO, actor: object | heros.RemoteHERO, actor_parameter: str, initial_set_value: float, actor_min: float | None = None, actor_max: float | None = None, loop: asyncio.AbstractEventLoop | None = None, update_rate: float = 1.0, autostart: bool = True)[source]

Base class for (slow) control loops.

It measures the value of a sensor that implements the atomiq Measurable interface and and acts on an actor that implements the atomiq Parametrizable interface. This makes it a versatile tool that can be used for a large number of slow control tasks.

This class provides a basic structure for implementing control loops. Subclasses should implement the _next_control_value method to define the specific control logic. See PIDControlLoop for an example.

Parameters:
  • sensor – object that measures the value to be controlled. Must implement the Measurable interface

  • actor – object that can act on the value to be controlled. Must implement the Parametrizable interface

  • actor_parameter – name of the parameter to act on in the actor.

  • initial_set_value – set value when the control loop starts. Can be changed during operation.

  • actor_min – minimum value to set for the control parameter on the actor.

  • actor_max – maximum value to set for the control parameter on the actor.

  • loop – asyncio loop to be used for control loop

  • update_rate – rate at which values should be measured and the actor should be updated in Hz (default 1Hz).

  • autostart – whether to close the control loop upon startup.

set_value: float = 0.0
sensor
actor
actor_parameter
_loop
update_rate = 1.0
_running = False
actor_min = None
actor_max = None
_run_flag
_stop_flag
_loop_task
property running
start_loop() → None[source]

Close the control loop.

stop_loop() → None[source]

Open the control loop.

_destroy_hero()[source]
abstractmethod _next_control_value(input_value: float) → float[source]
_actor_value_bounded(value) → float[source]
async _mainloop()[source]
_emit_observable_data(input_value: float, output_value: float) → None[source]
class herostools.actor.control_loop.PIDControlLoop(sensor: object | heros.RemoteHERO, actor: object | heros.RemoteHERO, actor_parameter: str, initial_set_value: float, actor_min: float | None = None, actor_max: float | None = None, loop: asyncio.AbstractEventLoop | None = None, update_rate: float = 1.0, autostart: bool = True, default_p: float = 1.0, default_i: float = 0.0, default_d: float = 0.0, integral_limit: float | None = None)[source]

Bases: ControlLoop

PID (Proportional-Integral-Derivative) control loop.

This class implements a PID control loop, which is a common control loop feedback mechanism widely used in industrial control systems. The PID controller calculates an “error” value as the difference between a desired setpoint and a measured process variable and attempts to minimize the error by adjusting the process control inputs.

The PID formula is given by:

\[u(t) = K_p e(t) + K_i \int_{0}^{t} e( au) \, d au + K_d\]

rac{de(t)}{dt}

where: - ( u(t) ) is the control signal, - ( e(t) ) is the error (difference between the setpoint and the measured value), - ( K_p ) is the proportional gain, - ( K_i ) is the integral gain, - ( K_d ) is the derivative gain.

Args:

sensor: object that measures the value to be controlled. Must implement the Measurable interface actor: object that can act on the value to be controlled. Must implement the Parametrizable interface actor_parameter: name of the parameter to act on in the actor. initial_set_value: set value when the control loop starts. Can be changed during operation. actor_min: minimum value to set for the control parameter on the actor. actor_max: maximum value to set for the control parameter on the actor. loop: asyncio loop to be used for control loop update_rate: rate at which values should be measured and the actor should be updated in Hz (default 1Hz). autostart: whether to close the control loop upon startup. default_p: initial value to set for the proportional gain. Can be changed during operation. default_i: initial value to set for the integral gain. Can be changed during operation. default_d: initial value to set for the differential gain. Can be changed during operation.

p: float
i: float
d: float
integral: float
last_value = 0.0
integral_limit = None
reset_integral()[source]

Reset the time integral of the error to zero.

_next_control_value(input_value: float) → float[source]

Calculate the next value to set on the actor with the PID formula.

_emit_observable_data(input_value: float, output_value: float) → None[source]