## Modelica_LinearSystems2.Controller

Continuous and discrete input/output blocks. Easy to switch from continuous to discrete representation.

### Information

This library provides input/output blocks where every block is available in a continuous and a discrete (sampled) representation. A block is defined via its continuous parameterization. By specifying a discretization method and a sample time, the discrete representation is automatically derived from the continuous form. The defaults of the most important options for all blocks are set in the global SampleClock component (via inner/outer). As a result, it is, e.g., easy to switch quickly between a continuous and a discrete representation of all blocks of a controller.

Examples to demonstrate the technique are given in sublibrary Examples. Especially, the continuous or discrete control of a simple flexible drive with a P-PI cascade controller is demonstrated in example SimpleControlledDrive.

Extends from Modelica.Icons.Package (Icon for standard packages), Modelica.Icons.Library (This icon will be removed in future Modelica versions, use Package instead).

### Package Content

Name | Description
--- | ---
UsersGuide | Users Guide
Examples | Demonstrate the usage of package Controller
SampleClock | Global options for blocks of Controller library (in particular sample clock)
Sampler | Sample the input signal if discrete block or y=u if continuous block
StateSpace | Continuous or discrete state space system block
TransferFunction | Continuous or discrete, single input single output transfer function
ZerosAndPoles | Continuous or discretized, single input single output block described by a ZerosAndPoles object
Filter | Continuous or discretized analog low or high pass IIR-filter (CriticalDamping/Bessel/Butterworth/Chebyshev)
FilterFIR | Discrete finite impulse response low or high pass filter
Integrator | Output the integral of the input signal (continuous or discrete block)
Derivative | Approximate derivative (continuous or discrete block)
FirstOrder | First order (continuous or discrete) transfer function block (= 1 pole)
SecondOrder | Second order (continuous or discrete) transfer function block (= 2 poles)
PI | Proportional-Integral controller (continuous or discrete block)
PID | PID-controller in additive description form
LimPID | P, PI, PD, and PID controller with limited output, anti-windup compensation and setpoint weighting
UnitDelay | Delay the input by a multiple of the base sample time if discrete block or y=u if continuous block
ADconverter | Analog to digital converter (including sampler)
DAconverter | Digital to analog converter (including zero order hold)
Interpolator | Increasing the sampling frequency with linear interpolation and optional mean value filtering
MatrixGain | Output the product of a gain matrix with the input signal vector. The matrix can be loaded from a file optionally
Noise | Block that generates a uniform distributed noise output signal at sample instants if discrete and y=0 if continuous
EKF | Extended Kalman filter
UKF | Unscented Kalman filter
UKF_SR | Unscented Kalman filter
Icons |
Interfaces | Interfaces (partial blocks) of Controller library
Templates | Templates of control structures
Types | Constants and types with choices, especially to build menus
DataDir=Modelica_LinearSystems2.DataDir | Absolute path to directory containing utilitiy files for this package, such as images

## Modelica_LinearSystems2.Controller.SampleClock

Global options for blocks of Controller library (in particular sample clock)

### Information

Global block that defines options for all components of the Controller library that are on the same or on a lower level as the sampleClock component. In particular it is defined whether the blocks shall be used by default in a continuous or a discrete representation. In the latter case, the default discretization method and the base sample time is defined. The sample time of a block is an integer multiple of the base sample time defined in the SampleClock component.

### Parameters

Name | Description
--- | ---
blockType | Type of Sampled blocks (Continuous or Discrete)
methodType | Discretization method for discrete blocks
sampleTime | Base sample time for discrete blocks [s]
initType | Type of initialization of Sampled blocks

## Modelica_LinearSystems2.Controller.Sampler

Sample the input signal if discrete block or y=u if continuous block

### Information

If discrete block, the output y is sampled according to sample time sampleClock.sampleTime * sampleFactor, where sampleClock.sampleTime is defined globally in the outer component sampleClock and sampleFactor is an Integer parameter of component Sampler.

If continuous block, the output y is identical to the input u.

Extends from Interfaces.PartialSISO_equality (Partial Single Input Single Output (continuous or discrete) control block of Controller library where usually y=u if continuous block).

### Parameters

Name | Description
--- | ---
blockType | Type of block (Continuous/Discrete)
sampleFactor | Sample time = sampleFactor * sampleClock.sampleTime

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block

## Modelica_LinearSystems2.Controller.StateSpace

Continuous or discrete state space system block

### Information

Extends from Interfaces.PartialSampledBlock (Partial block of Sampled library (icon + default parameters)).

### Parameters

Name | Description
--- | ---
system | Continuous linear time-invariant system
Advanced options
blockType | Type of block (Continuous/Discrete)
methodType | Type of discretization if discrete block
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor
initType | Type of initialization (no init/initial/steady state/output)
x_start[nx] | Initial or guess values of states
y_start[ny] | Initial values of outputs (remaining states are in steady state if possible)
withDelay |

### Connectors

Name | Description
--- | ---
u[size(system.B, 2)] | Continuous or discrete input signals of block
y[size(system.C, 1)] | Continuous or discrete output signals of block
x[nx] | State vector of continuous system

## Modelica_LinearSystems2.Controller.TransferFunction

Continuous or discrete, single input single output transfer function

### Information

Extends from Modelica_LinearSystems2.Controller.Interfaces.PartialSISO2 (Partial Single Input Single Output (continuous or discrete) control block of Controller library).

### Parameters

Name | Description
--- | ---
system | Transfer function
Advanced options
blockType | Type of block (Continuous/Discrete)
methodType | Type of discretization if discrete block
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor
initType | Type of initialization (no init/initial/steady state/output)
x_start[nx] | Initial or guess values of states
y_start | Initial value of output (derivatives of y are zero upto nx-1-th derivative)

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block
x[nx] | State of continuous transfer function

## Modelica_LinearSystems2.Controller.ZerosAndPoles

Continuous or discretized, single input single output block described by a ZerosAndPoles object

### Information

This function transforms a zeros-poles-gain system representation into state space representation. To achieve well numerical condition the ZerosAndPoles transfer function is transformed into state space form by creating first and second order blocks that are connected together in series. Every block is represented in controller canonical form and scaled such that the gain from the input of this block to its output is one (i.e. y(s=0) = u(s=0)), if this is possible. Details are given below.

#### Algorithmic details

The ZerosAndPoles transfer function is defined as:

             product(s + n1[i]) * product(s^2 + n2[i,1]*s + n2[i,2])
      y = k*--------------------------------------------------------- * u
             product(s + d1[i]) * product(s^2 + d2[i,1]*s + d2[i,2])

This is treated as a series connection of first and second order systems. If size(n1) == size(d1) and size(n2) == size(d2) this gives the following sequence of operations:

            s^2 + n2[1,1]*s + n2[1,2]
      y_1 = ------------------------- * u
            s^2 + d2[1,1]*s + d2[1,2]

            s^2 + n2[2,1]*s + n2[2,2]
      y_2 = ------------------------- * y_1
            s^2 + d2[2,1]*s + d2[2,2]

         ...

            s + n1[..]
      y_n = ---------- * y_(n-1)
            s + d1[..]

        y = k*y_n

Based on this representation, evrey block with transfer function G(s) could be transformed into

      G(s) = k * F(s)

with F(s) has unit gain. This leads to representations of the forms

               a2 + a1*s + s^2       a2      b2 + a1*b2/a2*s + b2/a2*s^2
      G(s) = -------------------- = ---- * ------------------------------ = k * F(s),  k = a2/b2  (1)
               b2 + b1*s + s^2       b2           b2 + b1*s + s^2

    for second order systems and

               a + s     a     b + b/a*s
      G(s) = -------- = --- * ---------- = k * F(s),   k = a/b
               b + s     b      b + s

for first order systems respectively.

The complete system is now considered as the series connections of all the single unit gain transfer functions and an overall gain k with

      k = product(ki).

In the general case, the following system structures and the corresponding state space systems can appear (note, 'c' is the reciprocal local gain 1/k):

    (1)
              a2 + a1*s + s^2           der(x1) = x2
        y = ---------------------  -->  der(x2) = -b2*x1 - b1*x2 + b2*u
              b2 + b1*s + s^2                 y = c*((a2-b2)*x1 + (a1-b1)*x2 + u),  c = b2/a2

    (2)
                 s + a                 der(x1) = x2
        y = ---------------- * u  -->  der(x2) = -b2*x1 - b1*x2 + b2*u
            b2 + b1*s + s^2                  y = k*(a1/b2*x1 +x2/b2),  c = b2/a

    (3)
                   1                  der(x1) = x2
        y = --------------- *u   -->  der(x2) = -b2*x1 - b1*x2 + b2*u
            b2 + b1*s + s^2                 y = c*x1/b2,  c = b2

    (4)
           a + s                       der(x) = -b*x + b*u
       y = ----- * u             -->        y = c*((a-b)/b*x + u),  c = b/a
           b + s

    (5)
             1
       y = ----- * u             -->   der(x) = -b*x + b*u
           b + s                            y = x,  c = b

If the sizes of the numerator and denominator polynomials do not match, the small systems are built in the following way:

    (1) Build systems of form (1) by combining
        - 1 d2 and 1 n2
          (= 1 second order denominator and 1 second order numerator) or
        - 1 d2 and 2 n1 or
        - 2 d1 and 1 n2
    (2) Build at most one system of form (2) by combining
        - 1 d2 and 1 n2
    (3) Build systems of form (3) by
        - 1 d2
    (4) Build systems of form (4) by combining
        - 1 d1 and 1 n1
    (5) Build systems of form (5) by
        - 1 d1

The numeric properties of the resulting state space system depends on which first and second order polynomials are combined and connected together. From a numerical point of view, it would therefore be useful to combine the polynomials based on the numeric values of the polynomial coefficients, (e.g., in a first step the polynomials could be sorted according to their cut-off frequency).

However, this has the disadvantage that the structure of the resulting state space system depends on the numeric values of the polynomial coefficients. Since Modelica environments perform symbolic pre-processing on equations, this would mean that a change of a polynomial coefficient requires to newly compile the state space system.

If, on the other hand, the structure of the state space system depends only on dimension information of the n1,n2,d1,d2 arrays, then the polynomial coefficients can be changed without a new translation of the model. This is the major reason why the structure of the state space system in the implementation of this block is based only on dimension information.

This is, e.g., not critical for the provided filters: The dimension of the n1,n2,d1,d2 arrays depend for filters only on the filter characteristics (Bessel, Butterworth etc.), the filter type (low pass, high pass etc.) and on the filter order. If any of this data is changed, the model has to be newly compiled. All the other filter data, such as cut-off frequency or ripple amplitude, can be changed without re-compilation of the model. The ZerosAndPoles transfer function is now constructed for the filters in such a way that the filter zeros and poles are appropriately sorted to give better numerical properties.

Another alternative implementation of the state space system would be to use the function controller canonical form that directly results from the transfer function. The severe disadvantage of this approach is that the structure of the state space system from above is lost for the symbolic preprocessing. If, e.g., index reduction has to be applied (e.g. since a filter is used to realize a non-linear inverse model), then the tool cannot perform the index reduction. Example:

Assume, a generic first order state space system is present

       der(x) = a*x + b*u
            y = c*x + d*u

and the values of the scalars a,b,c,d are parameters that might be changed before the simulation starts. If y has to be differentiated symbolically during code generation, then

          der(y) = c*der(x) + d*der(u)
          der(x) = a*x + b*u

As a result, u needs to be differentiated too, and this might not be possible and therefore translation might fail.

On the other hand, if the first order system is defined to be a low pass filter and the state space system is generated by keeping this structure, we have (see form (5) above):

       der(x) = -b*x + u
            y = x

Differentiating y symbolically leads to:

         der(y) = der(x)
         der(x) = -b*x + u

Therefore, in this case, the derivative of u is not needed and the tool can continue with the symbolic processing.

Extends from Modelica_LinearSystems2.Controller.Interfaces.PartialSISO2 (Partial Single Input Single Output (continuous or discrete) control block of Controller library).

### Parameters

Name | Description
--- | ---
system | Data defining the ZerosAndPoles object
Advanced options
blockType | Type of block (Continuous/Discrete)
methodType | Type of discretization if discrete block
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor
initType | Type of initialization (no init/initial/steady state/output)
x_start[nx] | Initial or guess values of states
y_start | Initial or guess values of output

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block
x[nx] | State of continuous block

## Modelica_LinearSystems2.Controller.Filter

Continuous or discretized analog low or high pass IIR-filter (CriticalDamping/Bessel/Butterworth/Chebyshev)

### Information

For details of the filter characteristics, see ZerosAndPoles.Design.filter.

Extends from ZerosAndPoles (Continuous or discretized, single input single output block described by a ZerosAndPoles object).

### Parameters

Name | Description
--- | ---
system | Data defining the ZerosAndPoles object
analogFilter | Analog filter characteristics (CriticalDamping/Bessel/Butterworth/Chebyshev)
filterType | Type of filter (LowPass/HighPass)
order | Order of filter
f_cut | Cut-off frequency [Hz]
gain | Gain (= amplitude of frequency response at zero frequency)
normalized | = true, if amplitude at f_cut decreases/increases 3 db (for low/high pass filter), otherwise unmodified filter
A_ripple | Pass band ripple for Chebyshev filter (otherwise not used) [dB]
Advanced options
blockType | Type of block (Continuous/Discrete)
methodType | Type of discretization if discrete block
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor
initType | Type of initialization (no init/initial/steady state/output)
x_start[nx] | Initial or guess values of states
y_start | Initial or guess values of output

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block
x[nx] | State of continuous block

## Modelica_LinearSystems2.Controller.FilterFIR

Discrete finite impulse response low or high pass filter

### Information

Extends from Interfaces.PartialSISO_equality (Partial Single Input Single Output (continuous or discrete) control block of Controller library where usually y=u if continuous block).

### Parameters

Name | Description
--- | ---
blockType | Type of block (Continuous/Discrete)
sampleFactor | Sample time = sampleFactor * sampleClock.sampleTime
specType | Specification type of FIR filter
Mean value filter
L | Length of mean value filter
FIR filter design
filterType | Type of filter
order | Order of filter
f_cut | Cut-off frequency [Hz]
window | Type of window
beta | Beta-Parameter for Kaiser-window
FIR filter defined by coefficient vector
a[:] | FIR filter coefficients

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block

## Modelica_LinearSystems2.Controller.Integrator

Output the integral of the input signal (continuous or discrete block)

### Information

This blocks defines the transfer function between the input u and the output y as integrator:

              k
         y = --- * u
              s

The block can be continuous or discrete (with continuous parameterization).

It is not possible to initalize a continuous integrator in steady state. For this reason, option "initType = SteadyState" is ignored for a continuous integrator block and interpreted as "initType = InitialState".

Extends from Interfaces.PartialSISO2 (Partial Single Input Single Output (continuous or discrete) control block of Controller library).

### Parameters

Name | Description
--- | ---
k | Integrator gain
withDelay | = true, if the output is delayed by one sample period (only if discrete)
Advanced options
blockType | Type of block (Continuous/Discrete)
methodType | Type of discretization if discrete block
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor
initType | Type of initialization (no init/initial/steady state/output)
y_start | Initial or guess value of output (=state)

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block

## Modelica_LinearSystems2.Controller.Derivative

Approximate derivative (continuous or discrete block)

### Information

This blocks defines the transfer function between the input u and the output y as approximative derivative (DT1):

                 k * s
         y = ------------ * u
                T * s + 1

The block can be continuous or discrete (with continuous parameterization).

If k=0, the state space realization of the block is specially constructed, in order that the D-part of PID controllers can be set to zero without introducing numerical problems.

If you would like to be able to change easily between different transfer functions (FirstOrder, SecondOrder, ... ) by changing parameters, use the general model class TransferFunction instead and model a DT1 system with parameters
n = {k,0}, d = {T,1}.

Extends from Interfaces.PartialSISO2 (Partial Single Input Single Output (continuous or discrete) control block of Controller library).

### Parameters

Name | Description
--- | ---
k | Gain
T | Time Constant (T>0 required; T=0 is ideal derivative block) [s]
Advanced options
blockType | Type of block (Continuous/Discrete)
methodType | Type of discretization if discrete block
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor
initType | Type of initialization (no init/initial/steady state/output)
x_start | Initial or guess value of state
y_start | Initial or guess value of output

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block
x | State of approximative derivative

## Modelica_LinearSystems2.Controller.FirstOrder

First order (continuous or discrete) transfer function block (= 1 pole)

### Information

This blocks defines the transfer function between the input u and the output y as first order system:

                 k
         y = --------- * u
             T * s + 1

The block can be continuous or discrete (with continuous parameterization).

Extends from Interfaces.PartialSISO2 (Partial Single Input Single Output (continuous or discrete) control block of Controller library).

### Parameters

Name | Description
--- | ---
k | Gain
T | Time Constant
Advanced options
blockType | Type of block (Continuous/Discrete)
methodType | Type of discretization if discrete block
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor
initType | Type of initialization (no init/initial/steady state/output)
y_start | Initial y if initType=InitialState (else guess)

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block

## Modelica_LinearSystems2.Controller.SecondOrder

Second order (continuous or discrete) transfer function block (= 2 poles)

### Information

This blocks defines the transfer function between the input u and the output y as second order system:

                             k
         y = --------------------------------- * u
              ( s / w )^2 + 2*D*( s / w ) + 1

The block can be continuous or discrete (with continuous parameterization).

If you would like to be able to change easily between different transfer functions (FirstOrder, SecondOrder, ... ) by changing parameters, use the general model class TransferFunction instead and model a second order SISO system with parameters
n = {k}, d = {1/w^2, 2*D/w, 1}.

    Example:
       parameter: k =  0.3,  w = 0.5,  D = 0.4
       results in:
                      0.3
          y = ------------------- * u
              4.0 s^2 + 1.6 s + 1

Extends from Interfaces.PartialSISO2 (Partial Single Input Single Output (continuous or discrete) control block of Controller library).

### Parameters

Name | Description
--- | ---
k | Gain
w | Angular frequency
D | Damping
Advanced options
blockType | Type of block (Continuous/Discrete)
methodType | Type of discretization if discrete block
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor
initType | Type of initialization (no init/initial/steady state/output)
y_start | Initial or guess value of output (= state)
yd_start | Initial or guess value of derivative of output (= state)

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
yd | First derivative of y
yy[2] |

## Modelica_LinearSystems2.Controller.PI

Proportional-Integral controller (continuous or discrete block)

### Information

This blocks defines the transfer function between the input u and the output y as integrator:

                         1
          y = k * (1 + ------ ) * u
                        T*s
                   T*s + 1
            = k * --------- * u
                     T*s

The block can be continuous or discrete (with continuous parameterization).

It is not possible to initalize a continuous integrator in steady state. For this reason, option "initType = SteadyState" is ignored for a continuous PI block and interpreted as "initType = InitialState".

Extends from Interfaces.PartialSISO2 (Partial Single Input Single Output (continuous or discrete) control block of Controller library).

### Parameters

Name | Description
--- | ---
k | Gain
T | Time Constant (T>0 required) [s]
Advanced options
blockType | Type of block (Continuous/Discrete)
methodType | Type of discretization if discrete block
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor
initType | Type of initialization (no init/initial/steady state/output)
x_start | Initial or guess value of state
y_start | Initial value of output

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block
x | State of block

## Modelica_LinearSystems2.Controller.PID

PID-controller in additive description form

### Information

This is the text-book version of a PID-controller. For a more practically useful PID-controller, use block LimPID.

The PID 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 or the variable that is used to compute u by an algebraic equation.

Extends from Interfaces.PartialSampledBlock (Partial block of Sampled library (icon + default parameters)).

### Parameters

Name | Description
--- | ---
pidRep | type of PID representation: k*(1 + 1/Ti/s + Td*s) or (kp + Ti/s + Td*s)
k | Gain of controller
Ti | Time constant of Integrator block [s]
Td | Time constant of Derivative block [s]
Nd | The higher Nd, the more ideal the derivative block
kp | P part parameter of gain representation
ki | I part parameter of gain representation
kd | D part parameter of gain representation
Initialization
xi_start | Initial or guess value value for integrator output (= integrator state)
xd_start | Initial or guess value for state of derivative block
y_start | Initial value of output
Advanced options
blockType | Type of block (Continuous/Discrete)
methodType | Type of discretization if discrete block
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor
initType | Type of initialization (no init/initial/steady state/output)

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block

## Modelica_LinearSystems2.Controller.LimPID

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

### Information

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:

Astroem K.J., and Haegglund T.:
  PID Controllers: Theory, Design, and Tuning. Instrument Society of America, 2nd edition, 1995. Information from: http://www.control.lth.se/publications/books/asthagg95.html

Besides the additive proportional, integral and derivative part 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 independantly from the measurement. The controller will respond to load disturbances and measurement noise independantly 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.

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 occuring 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.

Extends from Interfaces.PartialSampledBlock (Partial block of Sampled library (icon + default parameters)), Modelica.Blocks.Interfaces.SVcontrol (Single-Variable continuous controller), Interfaces.PartialBlockIcon (Basic graphical layout of discrete/continuous block).

### Parameters

Name | Description
--- | ---
pidRepresentation | type of PID representation: k*(1 + 1/Ti/s + Td*s) or (kp + Ti/s + Td*s)
controllerType | Type of controller
k | Gain of controller
Ti | Time constant of Integrator block [s]
Td | Time constant of Derivative block [s]
kp | P part parameter of gain representation
ki | I part parameter of gain representation
kd | D part parameter of gain representation
yMax | Upper limit of output
yMin | Lower limit of output
wp | Set-point weight for Proportional block (0..1)
wd | Set-point weight for Derivative block (0..1)
Ni | Ni*Ti is time constant of anti-windup compensation
Nd | The higher Nd, the more ideal the derivative block
Initialization
limitsAtInit | = false, if limits are ignored during initializiation
xi_start | Initial or guess value value for integrator output (= integrator state)
xd_start | Initial or guess value for state of derivative block
y_start | Initial value of output
Advanced options
blockType | Type of block (Continuous/Discrete)
methodType | Type of discretization if discrete block
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor
initType | Type of initialization (no init/initial/steady state/output)

### Connectors

Name | Description
--- | ---
u_s | Connector of setpoint input signal
u_m | Connector of measurement input signal
y | Connector of actuator output signal

## Modelica_LinearSystems2.Controller.UnitDelay

Delay the input by a multiple of the base sample time if discrete block or y=u if continuous block

### Information

If discrete block, the output y is sampled and is the value of the sampled input signal u at the previous sample instant, where sample time = sampleClock.sampleTime * sampleFactor and sampleClock.sampleTime is defined globally in the outer component sampleClock and sampleFactor is an Integer parameter of component UnitDelay.

If continuous block, the output y is identical to the input u.

Extends from Interfaces.PartialSISO_equality (Partial Single Input Single Output (continuous or discrete) control block of Controller library where usually y=u if continuous block).

### Parameters

Name | Description
--- | ---
blockType | Type of block (Continuous/Discrete)
sampleFactor | Sample time = sampleFactor * sampleClock.sampleTime

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block

## Modelica_LinearSystems2.Controller.ADconverter

Analog to digital converter (including sampler)

### Information

If discrete block, the output y is sampled according to sample time sampleClock.sampleTime * sampleFactor, where sampleClock.sampleTime is defined globally in the outer component sampleClock and sampleFactor is an Integer parameter of component Sampler.

The sampled output signal is computed by limiting the input u with the provided y_min and y_max borders and by rounding according to the provided precision of the AD converter defined via parameter bits (e.g. bits = 12 is the precision of simple AD converters).

If continuous block, the output y is identical to the input u, but is limited by y_min and y_max.

Extends from Interfaces.PartialSISO_equality (Partial Single Input Single Output (continuous or discrete) control block of Controller library where usually y=u if continuous block).

### Parameters

Name | Description
--- | ---
y_max | Upper limit of output signal
y_min | Lower limit of output signal
bits | Number of bits (=0 means no quantization error)
blockType | Type of block (Continuous/Discrete)
sampleFactor | Sample time = sampleFactor * sampleClock.sampleTime

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block

## Modelica_LinearSystems2.Controller.DAconverter

Digital to analog converter (including zero order hold)

### Information

Extends from Interfaces.PartialSISO_equality (Partial Single Input Single Output (continuous or discrete) control block of Controller library where usually y=u if continuous block).

### Parameters

Name | Description
--- | ---
y_max | Upper limit of output signal
y_min | Lower limit of output signal
bits | Number of bits (=0 means no quantization error)
unitDelay | = true, if one sample period delay, = false, if computing time not modelled
blockType | Type of block (Continuous/Discrete)
sampleFactor | Sample time = sampleFactor * sampleClock.sampleTime

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block

## Modelica_LinearSystems2.Controller.Interpolator

Increasing the sampling frequency with linear interpolation and optional mean value filtering

### Information

This block decreases the sampling time from the sampling time of the input signal (= inputSampleFactor*sampleClock.sampleTime) to the sampling time of the output signal (= outputSampleFactor*sampleClock.sampleTime). This is performed by linear interpolation between the current and the last sample leading to a delay of one input sampling period. Optionally, the resulting signal is filtered with a mean value FIR-filter, in order to remove undesired frequencies introduced by the linear interpolation. In most cases it is adviceable to utilize this filter. Note, the inputSampleFactor must be an integer multiple of the outputSampleFactor.

This block is demonstrated with example Examples.Interpolator leading to the following result when filtering a sine-signal with "continuous" (interpolator1.y), "discrete, unfiltered" (interpolator2.y) and "discrete, filtered" (interpolator3.y) Interpolator:

Extends from Icons.PartialBlockIcon (Basic graphical layout of discrete/continuous block).

### Parameters

Name | Description
--- | ---
blockType | Type of block (Continuous/Discrete)
inputSampleFactor | Input sample time = inputSampleFactor * sampleClock.sampleTime
outputSampleFactor | Output sample time = outputSampleFactor * sampleClock.sampleTime (inputSampleFactor must be an integer multiple of outputSampleFactor)
meanValueFilter | = true and discrete block, linearly interpolated signal is filtered by mean value filter

### Connectors

Name | Description
--- | ---
u | Continuous or discrete input signal of block
y | Continuous or discrete output signal of block

## Modelica_LinearSystems2.Controller.MatrixGain

Output the product of a gain matrix with the input signal vector. The matrix can be loaded from a file optionally

### Information

This block is similar to Modelica.Blocks.Math.MatrixGain. Additionally this block offers to load the matrix from a MATLAB-file. It computes output vector y as product of the gain matrix K with the input signal vector u:

        y = K * u;

Example:

       parameter: K = [0.12 2; 3 1.5]

       results in the following equations:

         | y[1] |     | 0.12  2.00 |   | u[1] |
         |      |  =  |            | * |      |
         | y[2] |     | 3.00  1.50 |   | u[2] |

Extends from Modelica.Blocks.Interfaces.MIMO (Multiple Input Multiple Output continuous control block), Interfaces.PartialBlockIcon (Basic graphical layout of discrete/continuous block).

### Parameters

Name | Description
--- | ---
nin | Number of inputs
nout | Number of outputs
matrixOnFile | true if matrix should be read from file
fileName |
matrixName | Name of the matrix
K[:, :] | Matrix gain

### Connectors

Name | Description
--- | ---
u[nin] | Connector of Real input signals
y[nout] | Connector of Real output signals

## Modelica_LinearSystems2.Controller.Noise

Block that generates a uniform distributed noise output signal at sample instants if discrete and y=0 if continuous

### Information

If discrete block, the output y is sampled according to sample time sampleClock.sampleTime * sampleFactor, where sampleClock.sampleTime is defined globally in the outer component sampleClock and sampleFactor is an Integer parameter of component Noise. At every sample time, a random output signal y in the range y_min .. y_max is generated, where y_min and y_max are parameters. A typical noise signal is shown in the next figure:

The Integer[3] parameter vector firstSeed is used to initialize the basic random number generator. The 3 elements of firstSeed need to be in the range [0, 255]. The use of the same seed vector will lead to the same sequence of numbers when these are computed serially. This is usually not desired. Therefore, for every usage of block Noise a different firstSeed should be defined.

If continuous block, the output y = 0.0, i.e., no noise signal is generated. The reason is that the noise can only reasonably be used in a simulation if it is a discrete signal, i.e., changes its value only at sample instants. Since a continous block is usually used to speed up the simulation, the noise should also be turned off because it will otherwise significantly limit the maximum step size of the integrator.

This noise generator is based on a function that generates a random real number uniformely in the semi-open range [0.0, 1.0). The function uses the standard Wichmann-Hill generator, combining three pure multiplicative congruential generators of modulus 30269, 30307 and 30323. Its period (how many numbers it generates before repeating the sequence exactly) is 6,953,607,871,644. While of much higher quality than the rand() function supplied by most C libraries, the theoretical properties are much the same as for a single linear congruential generator of large modulus.

Extends from Interfaces.PartialBlockIcon (Basic graphical layout of discrete/continuous block).

### Parameters

Name | Description
--- | ---
y_min | Lower limit of noise band
y_max | Upper limit of noise band
firstSeed[3] | Integer[3] defining random sequence; required element range: 0..255
blockType | Type of block (Continuous/Discrete)
sampleFactor | Ts=sampleClock.sampleTime*sampleFactor

### Connectors

Name | Description
--- | ---
y | Discrete output signal of block

## Modelica_LinearSystems2.Controller.EKF

Extended Kalman filter

### Information

Extends from Modelica_LinearSystems2.Controller.Interfaces.PartialDiscreteBlock (Partial discrete block, i.e. no continuous alternative).

### Parameters

Name | Description
--- | ---
sampleFactor | Sample time=sampleClock.sampleTime*sampleFactor
x_est_init[:] | Initial value for state estimation
Q[:, size(Q, 1)] | Covariance matrix of the associated process noise
G[size(x_est_init, 1), size(Q, 1)] | Process noise weight matrix (usually identity or input matrix)
R[:, size(R, 1)] | Covariance matrix of the measurement noise
M_init[:, :] | Initial value of the Riccati matrix M
nu | Number of system inputs
Advanced options
initType | Type of initialization (no init/initial/steady state/output)

### Connectors

Name | Description
--- | ---
u[nu] | System input vector
x_est[nx] | Estimated state vector
y_measure[ny] | Measured outputs
y_est[ny] | Estimated system outputs

## Modelica_LinearSystems2.Controller.UKF

Unscented Kalman filter

### Information

Extends from Modelica_LinearSystems2.Controller.Interfaces.PartialDiscreteBlock (Partial discrete block, i.e. no continuous alternative).

### Parameters

Name | Description
--- | ---
sampleFactor | Sample time=sampleClock.sampleTime*sampleFactor
x_est_init[:] | Initial value for state estimation
Q[:, size(Q, 1)] | Covariance matrix of the associated process noise
G[size(x_est_init, 1), size(Q, 1)] | Process noise weight matrix (usually identity or input matrix)
R[:, size(R, 1)] | Covariance matrix of the measurement noise
P_init[:, :] | Initial value of the error covariance matrix
nu | Number of system inputs
alpha | Spread of sigma points
beta | Characteristic of the distribution of x
kappa | Scaling kurtosis of sigma point distribution
Advanced options
initType | Type of initialization (no init/initial/steady state/output)

### Connectors

Name | Description
--- | ---
u[nu] | System input vector
x_est[nx] | Estimated state vector
y_measure[ny] | Measured outputs
y_est[ny] | Estimated system outputs

## Modelica_LinearSystems2.Controller.UKF_SR

Unscented Kalman filter

### Information

Extends from Modelica_LinearSystems2.Controller.Interfaces.PartialDiscreteBlock (Partial discrete block, i.e. no continuous alternative).

### Parameters

Name | Description
--- | ---
sampleFactor | Sample time=sampleClock.sampleTime*sampleFactor
x_est_init[:] | Initial value for state estimation
Q[:, size(Q, 1)] | Covariance matrix of the associated process noise
G[size(x_est_init, 1), size(Q, 1)] | Process noise weight matrix (usually identity or input matrix)
R[:, size(R, 1)] | Covariance matrix of the measurement noise
P_init[:, :] | Initial value of the error covariance matrix
nu | Number of system inputs
alpha | Spread of sigma points
beta | Characteristic of the distribution of x
kappa | Scaling kurtosis of sigma point distribution
Advanced options
initType | Type of initialization (no init/initial/steady state/output)

### Connectors

Name | Description
--- | ---
u[nu] | System input vector
x_est[nx] | Estimated state vector
y_measure[ny] | Measured outputs
y_est[ny] | Estimated system outputs