pySimBlocks.blocks.controllers.pid

class pySimBlocks.blocks.controllers.pid.Pid(name: str, controller: str = 'PID', Kp: ArrayLike = 0.0, Ki: ArrayLike = 0.0, Kd: ArrayLike = 0.0, u_min: TypeAliasForwardRef('ArrayLike') | None = None, u_max: TypeAliasForwardRef('ArrayLike') | None = None, integration_method: str = 'euler forward', sample_time: float | None = None)[source]

Bases: Block

Discrete-time PID controller block.

Implements a single-input single-output discrete PID controller, similar to the Simulink PID block. The controller computes a control command from an error signal e using proportional, integral, and/or derivative actions depending on the selected control mode.

Output saturation is applied only if u_min and/or u_max are set. Anti-windup clamps the integrator state to the saturation bounds.

controller

Active control mode ("P", "I", "PI", "PD", or "PID").

integration_method

Integration scheme for the I term ("euler forward" or "euler backward").

Kp

Proportional gain as a (1,1) array.

Ki

Integral gain as a (1,1) array.

Kd

Derivative gain as a (1,1) array.

u_min

Lower saturation bound as a (1,1) array, or None.

u_max

Upper saturation bound as a (1,1) array, or None.

initialize(t0: float) None[source]

Set the output to zero and keep internal states at zero.

Parameters:

t0 – Initial simulation time in seconds.

output_update(t: float, dt: float) None[source]

Compute the PID control command from the current error input.

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.

Raises:

RuntimeError – If input e is not connected.

state_update(t: float, dt: float) None[source]

Update the integrator state and store the previous error.

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.

Raises:

RuntimeError – If input e is not connected.