Skip to content

PID controller

A typical proportional/integral/derivative controller that supports feedforward and rate limiting.


JCS Network Configuration

structure.yaml Configuration

type proc_pid

Signals - From Process

Signal name Type Required Description
u float32 required Controller output
Signal name can be renamed by the user

Signals - To Process

Signal name Type Required Description
setpoint float32 required Setpoint / command input
measurement float32 required Process / feedback input
feed_forward float32 optional Feed forward input
kp float32 optional Proportional term gain
If not connected, then must be set by parameter proc_pid_kp
ki float32 optional Integral term gain
If not connected, then must be set by parameter proc_pid_kd
kd float32 optional Derivative term gain
If not connected, then must be set by parameter proc_pid_kd
output_limit float32 optional Output and integrator limit
Defines both output limit high and low

Note: The PID controller breaks out the gains as optional signals. If they are not connected as signals the gains can be set via parameter.


Configuration Parameters

Parameter name Type Required Description
proc_pid_kp float32 optional Proportional gain term
Ignored if signal kp is connected
proc_pid_ki float32 optional Integral gain term
Ignored if signal ki is connected
proc_pid_kd float32 optional Derivative gain term
Ignored if signal kd is connected
proc_pid_kff float32 optional Feedforward gain term
proc_pid_limit_out_h float32 optional Controller output limit - high (output_units)
proc_pid_limit_out_l float32 optional Controller output limit - low (output_units)
proc_pid_rate_limit_rising float32 optional Controller output rising rate limiter (output_units/s)
proc_pid_rate_limit_falling float32 optional Controller output falling rate limiter (output_units/s)
proc_pid_startup_rate_limit float32 optional Startup output limits rate limiter (output_units/s/s)
proc_pid_derivative_tau float32 optional Derivative filter time constant (s)
proc_pid_use_derivative_on_measurement boolean optional False: uses derivative on setpoint error computation
True: uses derivative on measurement computation
Default value: false
proc_pid_is_rotational_error boolean optional True: wraps the computed error term \(e[k]\) to the interval \([-\pi, \pi]\)
Default value: false

Normal Operation

The PID controller is implemented via backward Euler transform in parallel form as the following difference equations:

If the parameter option proc_pid_is_rotational_error is set to false, then the error term is computed as:

\[ e[k] = r[k] - y[k] \]

If the parameter option proc_pid_is_rotational_error is set to true, then the error term is computed as:

\[ e[k] = wrap(r[k] - y[k], -\pi, \pi) \]

The proportional term is computed as:

\[ p[k] = k_p e[k] \]

The integral term is computed as:

\[ i[k] = i[k-1] + k_i dt(e[k] - e[k-1]) \]

If the parameter option proc_pid_use_derivative_on_measurement is set to false, then the derivative term is computed based on the error:

\[ d[k] = {k_{d}\over(\tau + dt)}(e[k] - e[k-1]) + {\tau\over(\tau + dt)}d[k-1] \]

If the parameter option proc_pid_use_derivative_on_measurement is set to true, then the derivative term is computed based on the measurement:

\[ d[k] = {k_{d}\over(\tau + dt)}(y[k-1] - y[k]) + {\tau\over(\tau + dt)}d[k-1] \]

The derivative filter time constant \(\tau\) is set by parameter option proc_pid_derivative_tau.

The final PID is computed with the added feedforward term \(k_{ff} * ff[k]\):

\[ y[k] = p[k] + i[k] + d[k] + k_{ff} * ff[k] \]

Limits configured in proc_pid_limit_out_h and proc_pid_limit_out_l are applied to the output and the integrator:

\[ y[k] = \begin{cases} limit_h,& \text{if } y[k]\geq limit_h\\ y[k], & limit_l \lt y[k] \lt limit_h \\ limit_l,& \text{if } y[k]\leq limit_l\\ \end{cases} \]

Following the limits, a rate limit may be applied to the output by parameters proc_pid_rate_limit_rising and proc_pid_rate_limit_falling. If these parameters are set as \(0\) or left unconfigured the rate limiter is disabled.

\[ y[k] = y[k-1] + \begin{cases} dt \times rate_{rising} ,& \text{if } y[k] - y[k-1] \geq dt \times rate_{rising}\\ 0, & dt \times rate_{falling} \lt y[k] - y[k-1] \lt dt \times rate_{rising} \\ dt \times rate_{falling} ,& \text{if } y[k] - y[k-1] \leq dt \times rate_{falling}\\ \end{cases} \]

Startup

During controller startup an aggressive rate limit may be applied via parameter proc_pid_startup_rate_limit. This parameter rate limits the controller limits (and in turn the controller integrator), starting from \(0\) until the limits reach the value defined by parameters proc_pid_limit_out_h and proc_pid_limit_out_l or the value defined by signal output_limit (whichever is configured). Once the rate limited limits equal the pre-defined limits, the startup rate limiter is disabled.

The effect of this limiter is to provide a 'soft' startup, in case of any large controller error present as the system starts.

Set parameter proc_pid_startup_rate_limit to \(0\), or leave unconfigured to disable the startup rate limiter.