blockLimPID

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

Extends from Modelica.Blocks.Interfaces.SVcontrol (Single-Variable continuous controller).

Information

This model duplicates the LimPID in the Modelica Standard Library but modifies it to enable a feed forward control option.

Via parameter controllerType either P, PI, PD, or PID can be selected. If, e.g., PI is selected, all components belonging to the D-part are removed from the block (via conditional declarations). The example model Modelica.Blocks.Examples.PID_Controller demonstrates the usage of this controller. Several practical aspects of PID controller design are incorporated according 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 derivative part of this controller, the following features are present:

  1. 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.
  2. The high-frequency gain of the derivative part is limited to avoid excessive amplification of measurement noise.
  3. 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.
  4. Feed forward option is available on any controllerType
  5. derMeas = true uses the derivative on measurement value only to avoid the derivative kick of setpoint changes. = false will take the derivative w.r.t. error
  6. It can be configured to enable an input port that allows resetting the controller output. The controller output can be reset as follows:
    • If reset = TRANSFORM.Types.Reset.Disabled, which is the default, then the controller output is never reset.
    • If reset = TRANSFORM.Types.Reset.Parameter, then a boolean input signal trigger is enabled. Whenever the value of this input changes from false to true, the controller output is reset by setting y to the value of the parameter y_reset.
    • If reset = TRANSFORM.Types.Reset.Input, then a boolean input signal trigger is enabled. Whenever the value of this input changes from false to true, the controller output is reset by setting y to the value of the input signal y_reset_in.

Note that this controller implements an integrator anti-windup. Therefore, for most applications, keeping the default setting of reset = TRANSFORM.Types.Reset.Disabled is sufficient. Examples where it may be beneficial to reset the controller output are situations where the equipment control input should continuously increase as the equipment is switched on, such as as a light dimmer that may slowly increase the luminance, or a variable speed drive of a motor that should continuously increase the speed.

The parameters of the controller can be manually adjusted by performing simulations of the closed loop system (= controller + plant connected together) 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 different ways controlled by parameter initType. The possible values of initType are defined in Modelica.Blocks.Types.InitPID. This type is identical to Types.Init, with the only exception that the additional option DoNotUse_InitialIntegratorState is added for backward compatibility reasons (= integrator is initialized with InitialState whereas differential part is initialized with NoInit which was the initialization in version 2.2 of the Modelica standard 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 is SteadyState because initial transients are then no longer present. If initType = InitPID.SteadyState, then in some cases difficulties might occur. The reason is the equation of the integrator:

der(y) = k*u;

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

If parameter limitAtInit = false, the limits at the output of this controller block are removed from the initialization problem which leads to a much simpler equation system. After initialization has been performed, it is checked via an assert whether the output is in the defined limits. For backward compatibility reasons limitAtInit = true. In most cases it is best to use limitAtInit = false.

Parameters

TypeNameDefaultDescription
SimpleControllercontrollerTypeSimpleController.PIDType of controller
Booleanwith_FFfalseenable feed-forward input signal
BooleanderMeastrue=true avoid derivative kick
Realyb0Output bias. May improve simulation
Realk_s1Setpoint input scaling: k_s*u_s. May improve simulation
Realk_m1Measurement input scaling: k_m*u_m. May improve simulation
Realk_ff1Measurement input scaling: k_ff*u_ff. May improve simulation
RealyMaxModelica.Constants.infUpper limit of output
RealyMin-yMaxLower limit of output
Parameters: Tuning Controls
Realk1Controller gain: +/- for direct/reverse acting
SI.TimeTi0.5Time constant of Integrator block
SI.TimeTd0.1Time constant of Derivative block
Realwp1Set-point weight for Proportional block (0..1)
Realwd0Set-point weight for Derivative block (0..1)
RealNi0.9Ni*Ti is time constant of anti-windup compensation
RealNd10The higher Nd, the more ideal the derivative block
Initialization
.Modelica.Blocks.Types.InitPIDinitType.Modelica.Blocks.Types.InitPID.NoInitType of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)
Realxi_start0Initial or guess value value for integrator output (= integrator state)
Realxd_start0Initial or guess value for state of derivative block
Realy_start0Initial value of output
Advanced
Booleanstrictfalse= true, if strict limits with noEvent(..)
Integrator reset
TRANSFORM.Types.ResetresetTRANSFORM.Types.Reset.DisabledType of controller output reset
Realy_resetxi_startValue to which the controller output is reset if the boolean trigger has a rising edge, used if reset == TRANSFORM.Types.Reset.Parameter

Connectors

TypeNameDefaultDescription
RealInputu_s (from SVcontrol)Connector of setpoint input signal
RealInputu_m (from SVcontrol)Connector of measurement input signal
RealOutputy (from SVcontrol)Connector of actuator output signal
Modelica.Blocks.Interfaces.BooleanInputtriggerResets the controller output when trigger becomes true
Modelica.Blocks.Interfaces.RealInputy_reset_inInput signal for state to which integrator is reset, enabled if reset = TRANSFORM.Types.Reset.Input
Modelica.Blocks.Interfaces.RealInputu_ffConnector of feed-forward signal

Components

TypeNameDefaultDescription
RealcontrolErroru_s - u_mControl error (set point - measurement)
Modelica.Blocks.Math.AddaddP
Modelica.Blocks.Math.AddaddD
Modelica.Blocks.Math.GainP
Blocks.IntegratorWithResetI
Modelica.Blocks.Continuous.DerivativeD
Modelica.Blocks.Math.GaingainPID
Modelica.Blocks.Math.Add3addPID
Modelica.Blocks.Math.Add3addI
Modelica.Blocks.Math.AddaddSat
Modelica.Blocks.Math.GaingainTrack
Modelica.Blocks.Nonlinear.Limiterlimiter
Modelica.Blocks.Sources.ConstantFzero
Modelica.Blocks.Sources.ConstantDzero
Modelica.Blocks.Sources.ConstantIzero
Modelica.Blocks.Math.Add3addFF
Modelica.Blocks.Math.Gaingain_u_s
Modelica.Blocks.Math.Gaingain_u_m
Modelica.Blocks.Logical.Switchswitch_derKick
Modelica.Blocks.Sources.BooleanConstantderKick
Modelica.Blocks.Sources.Constantnull_bias
Modelica.Blocks.Math.Gaingain_u_ff