Modelica.Blocks.Examples

Library of examples to demonstrate the usage of package Blocks

Information

This package contains example models to demonstrate the usage of package blocks.

Extends from Modelica.Icons.ExamplesPackage (Icon for packages containing runnable examples).

Package Content

Name Description
Modelica.Blocks.Examples.PID_Controller PID_Controller Demonstrates the usage of a Continuous.LimPID controller
Modelica.Blocks.Examples.Filter Filter Demonstrates the Continuous.Filter block with various options
Modelica.Blocks.Examples.FilterWithDifferentiation FilterWithDifferentiation Demonstrates the use of low pass filters to determine derivatives of filters
Modelica.Blocks.Examples.FilterWithRiseTime FilterWithRiseTime Demonstrates to use the rise time instead of the cut-off frequency to define a filter
Modelica.Blocks.Examples.InverseModel InverseModel Demonstrates the construction of an inverse model
Modelica.Blocks.Examples.ShowLogicalSources ShowLogicalSources Demonstrates the usage of logical sources together with their diagram animation
Modelica.Blocks.Examples.LogicalNetwork1 LogicalNetwork1 Demonstrates the usage of logical blocks
Modelica.Blocks.Examples.RealNetwork1 RealNetwork1 Demonstrates the usage of blocks from Modelica.Blocks.Math
Modelica.Blocks.Examples.IntegerNetwork1 IntegerNetwork1 Demonstrates the usage of blocks from Modelica.Blocks.MathInteger
Modelica.Blocks.Examples.BooleanNetwork1 BooleanNetwork1 Demonstrates the usage of blocks from Modelica.Blocks.MathBoolean
Modelica.Blocks.Examples.Interaction1 Interaction1 Demonstrates the usage of blocks from Modelica.Blocks.Interaction.Show
Modelica.Blocks.Examples.BusUsage BusUsage Demonstrates the usage of a signal bus
Modelica.Blocks.Examples.NoiseExamples NoiseExamples Library of examples to demonstrate the usage of package Blocks.Noise
Modelica.Blocks.Examples.BusUsage_Utilities BusUsage_Utilities Utility models and connectors for example Modelica.Blocks.Examples.BusUsage

Modelica.Blocks.Examples.PID_Controller Modelica.Blocks.Examples.PID_Controller

Demonstrates the usage of a Continuous.LimPID controller

Information

This is a simple drive train controlled by a PID controller:

The PI controller settings included "limitAtInit=false", in order that the controller output limits of 12 Nm are removed from the initialization problem.

The PI controller is initialized in steady state (initType=SteadyState) and the drive shall also be initialized in steady state. However, it is not possible to initialize "inertia1" in SteadyState, because "der(inertia1.phi)=inertia1.w=0" is an input to the PI controller that defines that the derivative of the integrator state is zero (= the same condition that was already defined by option SteadyState of the PI controller). Furthermore, one initial condition is missing, because the absolute position of inertia1 or inertia2 is not defined. The solution shown in this examples is to initialize the angle and the angular acceleration of "inertia1".

In the following figure, results of a typical simulation are shown:

PID_controller.png
PID_controller2.png

In the upper figure the reference speed (= integrator.y) and the actual speed (= inertia1.w) are shown. As can be seen, the system initializes in steady state, since no transients are present. The inertia follows the reference speed quite good until the end of the constant speed phase. Then there is a deviation. In the lower figure the reason can be seen: The output of the controller (PI.y) is in its limits. The anti-windup compensation works reasonably, since the input to the limiter (PI.limiter.u) is forced back to its limit after a transient phase.

Extends from Modelica.Icons.Example (Icon for runnable examples).

Parameters

NameDescription
driveAngleReference distance to move [rad]

Modelica.Blocks.Examples.Filter Modelica.Blocks.Examples.Filter

Demonstrates the Continuous.Filter block with various options

Information

This example demonstrates various options of the Filter block. A step input starts at 0.1 s with an offset of 0.1, in order to demonstrate the initialization options. This step input drives 4 filter blocks that have identical parameters, with the only exception of the used analog filter type (CriticalDamping, Bessel, Butterworth, Chebyshev of type I). All the main options can be set via parameters and are then applied to all the 4 filters. The default setting uses low pass filters of order 3 with a cut-off frequency of 2 Hz resulting in the following outputs:

Filter1.png

Extends from Modelica.Icons.Example (Icon for runnable examples).

Parameters

NameDescription
order 
f_cut[Hz]
filterTypeType of filter (LowPass/HighPass)
initType of initialization (no init/steady state/initial state/initial output)
normalized 

Modelica.Blocks.Examples.FilterWithDifferentiation Modelica.Blocks.Examples.FilterWithDifferentiation

Demonstrates the use of low pass filters to determine derivatives of filters

Information

This example demonstrates that the output of the Filter block can be differentiated up to the order of the filter. This feature can be used in order to make an inverse model realizable or to "smooth" a potential discontinuous control signal.

Extends from Modelica.Icons.Example (Icon for runnable examples).

Parameters

NameDescription
f_cut[Hz]

Modelica.Blocks.Examples.FilterWithRiseTime Modelica.Blocks.Examples.FilterWithRiseTime

Demonstrates to use the rise time instead of the cut-off frequency to define a filter

Information

Filters are usually parameterized with the cut-off frequency. Sometimes, it is more meaningful to parameterize a filter with its rise time, i.e., the time it needs until the output reaches the end value of a step input. This is performed with the formula:

f_cut = fac/(2*pi*riseTime);

where "fac" is typically 3, 4, or 5. The following image shows the results of a simulation of this example model (riseTime = 2 s, fac=3, 4, and 5):

FilterWithRiseTime.png

Since the step starts at 1 s, and the rise time is 2 s, the filter output y shall reach the value of 1 after 1+2=3 s. Depending on the factor "fac" this is reached with different precisions. This is summarized in the following table:

Filter order Factor fac Percentage of step value reached after rise time
1 3 95.1 %
1 4 98.2 %
1 5 99.3 %
2 3 94.7 %
2 4 98.6 %
2 5 99.6 %

Extends from Modelica.Icons.Example (Icon for runnable examples).

Parameters

NameDescription
orderFilter order
riseTimeTime to reach the step input [s]

Modelica.Blocks.Examples.InverseModel Modelica.Blocks.Examples.InverseModel

Demonstrates the construction of an inverse model

Information

This example demonstrates how to construct an inverse model in Modelica (for more details see Looye, Thümmel, Kurze, Otter, Bals: Nonlinear Inverse Models for Control).

For a linear, single input, single output system

   y = n(s)/d(s) * u   // plant model

the inverse model is derived by simply exchanging the numerator and the denominator polynomial:

   u = d(s)/n(s) * y   // inverse plant model

If the denominator polynomial d(s) has a higher degree as the numerator polynomial n(s) (which is usually the case for plant models), then the inverse model is no longer proper, i.e., it is not causal. To avoid this, an approximate inverse model is constructed by adding a sufficient number of poles to the denominator of the inverse model. This can be interpreted as filtering the desired output signal y:

   u = d(s)/(n(s)*f(s)) * y  // inverse plant model with filtered y

With Modelica it is in principal possible to construct inverse models not only for linear but also for non-linear models and in particular for every Modelica model. The basic construction mechanism is explained at hand of this example:

InverseModelSchematic.png

Here the first order block "firstOrder1" shall be inverted. This is performed by connecting its inputs and outputs with an instance of block Modelica.Blocks.Math.InverseBlockConstraints. By this connection, the inputs and outputs are exchanged. The goal is to compute the input of the "firstOrder1" block so that its output follows a given sine signal. For this, the sine signal "sin" is first filtered with a "CriticalDamping" filter of order 1 and then the output of this filter is connected to the output of the "firstOrder1" block (via the InverseBlockConstraints block, since 2 outputs cannot be connected directly together in a block diagram).

In order to check the inversion, the computed input of "firstOrder1" is used as input in an identical block "firstOrder2". The output of "firstOrder2" should be the given "sine" function. The difference is constructed with the "feedback" block. Since the "sine" function is filtered, one cannot expect that this difference is zero. The higher the cut-off frequency of the filter, the closer is the agreement. A typical simulation result is shown in the next figure:

InverseModel.png

Extends from Modelica.Icons.Example (Icon for runnable examples).

Modelica.Blocks.Examples.ShowLogicalSources Modelica.Blocks.Examples.ShowLogicalSources

Demonstrates the usage of logical sources together with their diagram animation

Information

This simple example demonstrates the logical sources in Modelica.Blocks.Sources and demonstrate their diagram animation (see "small circle" close to the output connector). The "booleanExpression" source shows how a logical expression can be defined in its parameter menu referring to variables available on this level of the model.

Extends from Modelica.Icons.Example (Icon for runnable examples).

Modelica.Blocks.Examples.LogicalNetwork1 Modelica.Blocks.Examples.LogicalNetwork1

Demonstrates the usage of logical blocks

Information

This example demonstrates a network of logical blocks. Note, that the Boolean values of the input and output signals are visualized in the diagram animation, by the small "circles" close to the connectors. If a "circle" is "white", the signal is false. It a "circle" is "green", the signal is true.

Extends from Modelica.Icons.Example (Icon for runnable examples).

Modelica.Blocks.Examples.RealNetwork1 Modelica.Blocks.Examples.RealNetwork1

Demonstrates the usage of blocks from Modelica.Blocks.Math

Information

This example demonstrates a network of mathematical Real blocks. from package Modelica.Blocks.Math. Note, that

Extends from Modelica.Icons.Example (Icon for runnable examples).

Modelica.Blocks.Examples.IntegerNetwork1 Modelica.Blocks.Examples.IntegerNetwork1

Demonstrates the usage of blocks from Modelica.Blocks.MathInteger

Information

This example demonstrates a network of Integer blocks. from package Modelica.Blocks.MathInteger. Note, that

Extends from Modelica.Icons.Example (Icon for runnable examples).

Modelica.Blocks.Examples.BooleanNetwork1 Modelica.Blocks.Examples.BooleanNetwork1

Demonstrates the usage of blocks from Modelica.Blocks.MathBoolean

Information

This example demonstrates a network of Boolean blocks from package Modelica.Blocks.MathBoolean. Note, that

Extends from Modelica.Icons.Example (Icon for runnable examples).

Modelica.Blocks.Examples.Interaction1 Modelica.Blocks.Examples.Interaction1

Demonstrates the usage of blocks from Modelica.Blocks.Interaction.Show

Information

This example demonstrates a network of blocks from package Modelica.Blocks.Interaction to show how diagram animations can be constructed.

Extends from Modelica.Icons.Example (Icon for runnable examples).

Modelica.Blocks.Examples.BusUsage Modelica.Blocks.Examples.BusUsage

Demonstrates the usage of a signal bus

Information

Signal bus concept

In technical systems, such as vehicles, robots or satellites, many signals are exchanged between components. In a simulation system, these signals are usually modelled by signal connections of input/output blocks. Unfortunately, the signal connection structure may become very complicated, especially for hierarchical models.

The same is also true for real technical systems. To reduce complexity and get higher flexibility, many technical systems use data buses to exchange data between components. For the same reasons, it is often better to use a "signal bus" concept also in a Modelica model. This is demonstrated at hand of this model (Modelica.Blocks.Examples.BusUsage):

BusUsage.png

The control and sub-control bus icons are provided within Modelica.Icons. In Modelica.Blocks.Examples.BusUsage_Utilities.Interfaces the buses for this example are defined. Both the "ControlBus" and the "SubControlBus" are expandable connectors that do not define any variable. For example, Interfaces.ControlBus is defined as:

  expandable connector ControlBus
      extends Modelica.Icons.ControlBus;
      annotation ();
  end ControlBus;

Note, the "annotation" in the connector is important since the color and thickness of a connector line are taken from the first line element in the icon annotation of a connector class. Above, a small rectangle in the color of the bus is defined (and therefore this rectangle is not visible). As a result, when connecting from an instance of this connector to another connector instance, the connecting line has the color of the "ControlBus" with double width (due to "thickness=0.5").

An expandable connector is a connector where the content of the connector is constructed by the variables connected to instances of this connector. For example, if "sine.y" is connected to the "controlBus", the following menu pops-up in Dymola:

BusUsage2.png

The "Add variable/New name" field allows the user to define the name of the signal on the "controlBus". When typing "realSignal1" as "New name", a connection of the form:

     connect(sine.y, controlBus.realSignal1)

is generated and the "controlBus" contains the new signal "realSignal1". Modelica tools may give more support in order to list potential signals for a connection. For example, in Dymola all variables are listed in the menu that are contained in connectors which are derived by inheritance from "controlBus". Therefore, in BusUsage_Utilities.Interfaces the expected implementation of the "ControlBus" and of the "SubControlBus" are given. For example "Internal.ControlBus" is defined as:

  expandable connector StandardControlBus
    extends BusUsage_Utilities.Interfaces.ControlBus;

    import SI = Modelica.SIunits;
    SI.AngularVelocity    realSignal1   "First Real signal";
    SI.Velocity           realSignal2   "Second Real signal";
    Integer               integerSignal "Integer signal";
    Boolean               booleanSignal "Boolean signal";
    StandardSubControlBus subControlBus "Combined signal";
  end StandardControlBus;

Consequently, when connecting now from "sine.y" to "controlBus", the menu looks differently:

BusUsage3.png

Note, even if the signals from "Internal.StandardControlBus" are listed, these are just potential signals. The user might still add different signal names.

Extends from Modelica.Icons.Example (Icon for runnable examples).

Automatically generated Tue Apr 05 09:36:11 2016.