LimPID

P, PI, PD, and PID controller with limited output, anti-windup compensation, setpoint weighting and optional feed-forward

    LimPID

Library

Modelica/Blocks/Continuous

Description

Via parameter controllerType either P, PI, PD,or PID can be selected. If, e.g., PI is selected, all components belonging to theD-part are removed from the block (via conditional declarations).The example modelModelica.Blocks.Examples.PID_Controllerdemonstrates the usage of this controller.Several practical aspects of PID controller design are incorporatedaccording to chapter 3 of the book:

Åström K.J., and Hägglund T.:
PID Controllers: Theory, Design, and Tuning. Instrument Society of America, 2nd edition, 1995.

Besides the additive proportional, integral and derivativepart of this controller, the following features are present:

  • The output of this controller is limited. If the controller is in its limits, anti-windup compensation is activated to drive the integrator state to zero.
  • The high-frequency gain of the derivative part is limited to avoid excessive amplification of measurement noise.
  • Setpoint weighting is present, which allows to weight the setpoint in the proportional and the derivative part independently from the measurement. The controller will respond to load disturbances and measurement noise independently of this setting (parameters wp, wd). However, setpoint changes will depend on this setting. For example, it is useful to set the setpoint weight wd for the derivative part to zero, if steps may occur in the setpoint signal.
  • Optional feed-forward. It is possible to add a feed-forward signal. The feed-forward signal is added before limitation.

The parameters of the controller can be manually adjusted by performingsimulations of the closed loop system (= controller + plant connectedtogether) and using the following strategy:

  1. Set very large limits, e.g., yMax = Modelica.Constants.inf
  2. Select a P-controller and manually enlarge parameter k (the total gain of the controller) until the closed-loop response cannot be improved any more.
  3. Select a PI-controller and manually adjust parameters k and Ti (the time constant of the integrator). The first value of Ti can be selected, such that it is in the order of the time constant of the oscillations occurring with the P-controller. If, e.g., vibrations in the order of T=10 ms occur in the previous step, start with Ti=0.01 s.
  4. If you want to make the reaction of the control loop faster (but probably less robust against disturbances and measurement noise) select a PID-Controller and manually adjust parameters k, Ti, Td (time constant of derivative block).
  5. Set the limits yMax and yMin according to your specification.
  6. Perform simulations such that the output of the PID controller goes in its limits. Tune Ni (Ni*Ti is the time constant of the anti-windup compensation) such that the input to the limiter block (= limiter.u) goes quickly enough back to its limits. If Ni is decreased, this happens faster. If Ni=infinity, the anti-windup compensation is switched off and the controller works bad.

Initialization

This block can be initialized in differentways controlled by parameter initType. The possiblevalues of initType are defined inModelica.Blocks.Types.InitPID.This type is identical toTypes.Init,with the only exception that the additional optionDoNotUse_InitialIntegratorState is added forbackward compatibility reasons (= integrator is initialized withInitialState whereas differential part is initialized withNoInit which was the initialization in version 2.2 of the Modelicastandard library).

Based on the setting of initType, the integrator (I) and derivative (D)blocks inside the PID controller are initialized according to the following table:

initType I.initType D.initType
NoInit NoInit NoInit
SteadyState SteadyState SteadyState
InitialState InitialState InitialState
InitialOutput
and initial equation: y = y_start
NoInit SteadyState
DoNotUse_InitialIntegratorState InitialState NoInit

In many cases, the most useful initial condition isSteadyState because initial transients are then no longerpresent. If initType = InitPID.SteadyState, then in somecases difficulties might occur. The reason is theequation of the integrator:

   der(y) = k*u;

The steady state equation "der(x)=0" leads to the condition that the input u to theintegrator is zero. If the input u is already (directly or indirectly) definedby another initial condition, then the initialization problem is singular(has none or infinitely many solutions). This situation occurs oftenfor mechanical systems, where, e.g., u = desiredSpeed - measuredSpeed andsince speed is both a state and a derivative, it is natural toinitialize it with zero. As sketched this is, however, not possible.The solution is to not initialize u_m or the variable that is usedto compute u_m by an algebraic equation.

When initializing in steady-state, homotopy-based initialization can help the convergence of the solver,by using a simplified model a the beginning of the solution process. Different options are available.

  • homotopyType=Linear (default): the limitations are removed from the simplified model,making it linear. Use this if you know that the controller will not be saturated at steady state.
  • homotopyType=UpperLimit: if it is known a priori the controller will be stuck at the upperlimit yMax, this option assumes y = yMax as a simplified model.
  • homotopyType=LowerLimit: if it is known a priori the controller will be stuck at the lowerlimit yMin, this option assumes y = yMin as a simplified model.
  • homotopyType=NoHomotopy: this option does not apply any simplification and keeps thelimiter active throughout the homotopy transformation. Use this if it is unknown whether the controlleris saturated or not at initialization and if the limitations on the output must be enforced throughoutthe entire homotopy transformation.

The parameter limitAtInit is obsolete since MSL 3.2.2 and only kept for backwards compatibility.

Parameters

LimPID_0

NameLabelDescriptionData TypeValid Values

mo_initType

initType

Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)

Structure

mo_initType/choice1

No initialization (start values are used as guess values with fixed=false)

Number

0
1

mo_initType/choice2

Steady state initialization (derivatives of states are zero)

Number

0
1

mo_initType/choice3

Initialization with initial states

Number

0
1

mo_initType/choice4

Initialization with initial outputs (and steady state of the states if possible)

Number

0
1

mo_initType/choice5

Do not use, only for backward compatibility (initialize only integrator state)

Number

0
1

mo_xi_start

xi_start

Initial or guess value for integrator output (= integrator state)

Scalar

mo_xd_start

xd_start

Initial or guess value for state of derivative block

Scalar

mo_y_start

y_start

Initial value of output

Scalar

mo_homotopyType

homotopyType

Simplified model for homotopy-based initialization

Structure

mo_homotopyType/choice1

Homotopy is not used

Number

0
1

mo_homotopyType/choice2

Simplified model without limits

Number

0
1

mo_homotopyType/choice3

Simplified model fixed at upper limit

Number

0
1

mo_homotopyType/choice4

Simplified model fixed at lower limit

Number

0
1

mo_controllerType

controllerType

Type of controller

Structure

mo_controllerType/choice1

P controller

Number

0
1

mo_controllerType/choice2

PI controller

Number

0
1

mo_controllerType/choice3

PD controller

Number

0
1

mo_controllerType/choice4

PID controller

Number

0
1

mo_k

k

Gain of controller

Scalar

mo_Ti

Ti

Time constant of Integrator block

Scalar

mo_Td

Td

Time constant of Derivative block

Scalar

mo_yMax

yMax

Upper limit of output

Scalar

mo_yMin

yMin

Lower limit of output

Scalar

mo_wp

wp

Set-point weight for Proportional block (0..1)

Scalar

mo_wd

wd

Set-point weight for Derivative block (0..1)

Scalar

mo_Ni

Ni

Ni*Ti is time constant of anti-windup compensation

Scalar

mo_Nd

Nd

The higher Nd, the more ideal the derivative block

Scalar

mo_withFeedForward

withFeedForward

Use feed-forward input?

Number

0
1

mo_kFF

kFF

Gain of feed-forward input

Scalar

mo_with_I

with_I

Scalar

true
false

mo_with_D

with_D

Scalar

true
false

LimPID_1

NameLabelDescriptionData TypeValid Values

mo_strict

strict

= true, if strict limits with noEvent(..)

Scalar

true
false

LimPID_2

NameLabelDescriptionData TypeValid Values

mo_limitsAtInit

limitsAtInit

Has no longer an effect and is only kept for backwards compatibility (the implementation uses now the homotopy operator)

Scalar

true
false

LimPID_3

NameLabelDescriptionData TypeValid Values

mo__nmodifiers

Number of Modifiers

Specifies the number of modifiers

Number

mo__modifiers

Modifiers

Add new modifier

Structure

mo__modifiers/varname

Variable name

Cell of strings

'controlError'

mo__modifiers/attribute

Attribute

Cell of strings

'start'
'fixed'

mo__modifiers/value

Value

Ports

NameTypeDescriptionIO TypeNumber

u_s

implicit

Connector of setpoint input signal

input

1

u_m

implicit

Connector of measurement input signal

input

2

y

implicit

Connector of actuator output signal

output

1

Port 4

implicit

Optional connector of feed-forward input signal

input

mo_withFeedForward