This package contains example models to demonstrate the usage of package blocks.
Extends from Icons.Library (Icon for library).
Name | Description |
---|---|
PID_Controller | Demonstrates the usage of a Continuous.LimPID controller |
InverseModel | Demonstrates the construction of an inverse model |
ShowLogicalSources | Demonstrates the usage of logical sources together with their diagram animation |
LogicalNetwork1 | Demonstrates the usage of logical blocks |
BusUsage | Demonstrates the usage of a signal bus |
BusUsage_Utilities | Utility models and connectors for example Modelica.Blocks.Examples.BusUsage |
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:
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 an example model).
Type | Name | Default | Description |
---|---|---|---|
Angle | driveAngle | 1.57 | Reference distance to move [rad] |
model PID_Controller "Demonstrates the usage of a Continuous.LimPID controller" extends Modelica.Icons.Example; parameter Modelica.SIunits.Angle driveAngle=1.57 "Reference distance to move";Modelica.Blocks.Continuous.LimPID PI( k=100, Ti=0.1, yMax=12, Ni=0.1, initType=Modelica.Blocks.Types.Init.SteadyState, limitsAtInit=false, controllerType=Modelica.Blocks.Types.SimpleController.PI, Td=0.1); Modelica.Mechanics.Rotational.Components.Inertia inertia1( a(fixed=true), phi(fixed= true, start=0), J=1); Modelica.Mechanics.Rotational.Sources.Torque torque; Modelica.Mechanics.Rotational.Components.SpringDamper spring( c=1e4, d=100, stateSelect=StateSelect.prefer, w_rel(fixed=true)); Modelica.Mechanics.Rotational.Components.Inertia inertia2( J=2); Modelica.Blocks.Sources.KinematicPTP kinematicPTP(startTime=0.5, deltaq={ driveAngle}, qd_max={1}, qdd_max={1}); Modelica.Blocks.Continuous.Integrator integrator(initType=Modelica.Blocks. Types.Init.InitialState); Modelica.Mechanics.Rotational.Sensors.SpeedSensor speedSensor; Modelica.Mechanics.Rotational.Sources.ConstantTorque loadTorque( tau_constant=10, useSupport=false); initial equation der(spring.w_rel) = 0; equationconnect(spring.flange_b,inertia2. flange_a); connect(inertia1.flange_b, spring.flange_a); connect(torque.flange, inertia1.flange_a); connect(kinematicPTP.y[1], integrator.u); connect(speedSensor.flange, inertia1.flange_b); connect(loadTorque.flange, inertia2.flange_b); connect(PI.y, torque.tau); connect(speedSensor.w, PI.u_m); connect(integrator.y, PI.u_s); end PID_Controller;
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:
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:
Extends from Modelica.Icons.Example (Icon for an example model).
model InverseModel "Demonstrates the construction of an inverse model" extends Modelica.Icons.Example;Continuous.FirstOrder firstOrder1( k=1, T=0.3, initType=Modelica.Blocks.Types.Init.SteadyState); Sources.Sine sine( freqHz=2, offset=1, startTime=0.2); Math.InverseBlockConstraints inverseBlockConstraints; Continuous.FirstOrder firstOrder2( k=1, T=0.3, initType=Modelica.Blocks.Types.Init.SteadyState); Math.Feedback feedback; Continuous.CriticalDamping criticalDamping(n=1, f=50*sine.freqHz); equationconnect(firstOrder1.y, inverseBlockConstraints.u2); connect(inverseBlockConstraints.y2, firstOrder1.u); connect(firstOrder2.y, feedback.u1); connect(sine.y, criticalDamping.u); connect(criticalDamping.y, inverseBlockConstraints.u1); connect(sine.y, feedback.u2); connect(inverseBlockConstraints.y1, firstOrder2.u); end InverseModel;
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 refering to variables available on this level of the model.
Extends from Modelica.Icons.Example (Icon for an example model).
model ShowLogicalSources "Demonstrates the usage of logical sources together with their diagram animation" extends Modelica.Icons.Example;Sources.BooleanTable table(table={2,4,6,8}); Sources.BooleanConstant const; Sources.BooleanStep step(startTime=4); Sources.BooleanPulse pulse(period=1.5); Sources.SampleTrigger sample( period=0.5); Sources.BooleanExpression booleanExpression( y=pulse.y and step.y); end ShowLogicalSources;
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 an example model).
model LogicalNetwork1 "Demonstrates the usage of logical blocks" extends Modelica.Icons.Example;Sources.BooleanTable table2(table={1,3,5,7}); Sources.BooleanTable table1(table={2,4,6,8}); Logical.Not Not1; Logical.And And1; Logical.Or Or1; Logical.Pre Pre1; equationconnect(table2.y, Not1.u); connect(And1.y, Or1.u2); connect(table1.y, Or1.u1); connect(Not1.y, And1.u1); connect(Pre1.y, And1.u2); connect(Or1.y, Pre1.u); end LogicalNetwork1;
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):
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 (Icon(Rectangle(extent=[-20, 2; 22, -2], style(rgbcolor={255,204,51}, thickness=0.5)))); 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:
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.InternalConnectors 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:
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 an example model).
model BusUsage "Demonstrates the usage of a signal bus" extends Modelica.Icons.Example;public Modelica.Blocks.Sources.IntegerStep integerStep( height=1, offset=2, startTime=0.5); Modelica.Blocks.Sources.BooleanStep booleanStep(startTime=0.5); Modelica.Blocks.Sources.Sine sine(freqHz=1); Modelica.Blocks.Examples.BusUsage_Utilities.Part part; Modelica.Blocks.Math.Gain gain(k=1); protected BusUsage_Utilities.Interfaces.ControlBus controlBus; equationconnect(sine.y, controlBus.realSignal1); connect(booleanStep.y, controlBus.booleanSignal); connect(integerStep.y, controlBus.integerSignal); connect(part.subControlBus, controlBus.subControlBus); connect(gain.u, controlBus.realSignal1); end BusUsage;