pathsim.blocks.ctrl module

class pathsim.blocks.ctrl.PID(Kp=0, Ki=0, Kd=0, f_max=100)[source]

Bases: Block

Proportional-Integral-Differntiation (PID) controller.

The transfer function is defined as

\[H_\mathrm{diff}(s) = K_p + K_i \frac{1}{s} + K_d \frac{s}{1 + s / f_\mathrm{max}}\]

where the differentiation is approximated by a high pass filter that holds for signals up to a frequency of approximately f_max.

Note

Depending on ‘f_max’, the resulting system might become stiff or ill conditioned! As a practical choice set f_max to 3x the highest expected signal frequency.

Example

The block is initialized like this:

#cutoff at 1kHz
pid = PID(Kp=2, Ki=0.5, Kd=0.1, f_max=1e3)
Parameters:
  • Kp (float) – poroportional controller coefficient

  • Ki (float) – integral controller coefficient

  • Kd (float) – differentiator controller coefficient

  • f_max (float) – highest expected signal frequency

op_dyn

internal dynamic operator for ODE component

Type:

DynamicOperator

op_alg

internal algebraic operator

Type:

DynamicOperator

set_solver(Solver, **solver_args)[source]

set the internal numerical integrator

Parameters:
  • Solver (Solver) – numerical integration solver class

  • solver_args (dict) – parameters for solver initialization

update(t)[source]

update system equation fixed point loop

Parameters:

t (float) – evaluation time

Returns:

error – absolute error to previous iteration for convergence control

Return type:

float

solve(t, dt)[source]

advance solution of implicit update equation

Parameters:
  • t (float) – evaluation time

  • dt (float) – integration timestep

Returns:

error – solver residual norm

Return type:

float

step(t, dt)[source]

compute update step with integration engine

Parameters:
  • t (float) – evaluation time

  • dt (float) – integration timestep

Returns:

  • success (bool) – step was successful

  • error (float) – local truncation error from adaptive integrators

  • scale (float) – timestep rescale from adaptive integrators