root/branches/maintenance/2.2.1/Modelica/Blocks/package.mo

Revision 463, 22.0 kB (checked in by hubertus, 22 months ago)

Created maintenance version from Dynasims version with minimal changes (no checksum, 1 graphics, a few improved documentation places, structurallyIncomplete annotations in Visualizers)

Line 
1package Blocks "Library for basic input/output control blocks (continuous, discrete, logical, table blocks)"
2  import SI = Modelica.SIunits;
3
4
5extends Modelica.Icons.Library2;
6
7
8annotation(preferedView="info",
9  Window(
10    x=0.03,
11    y=0.05,
12    width=0.21,
13    height=0.48,
14    library=1,
15    autolayout=1),
16  Icon(
17    Rectangle(extent=[-32, -6; 16, -35], style(color=0)),
18    Rectangle(extent=[-32, -56; 16, -85], style(color=0)),
19    Line(points=[16, -20; 49, -20; 49, -71; 16, -71], style(color=0)),
20    Line(points=[-32, -72; -64, -72; -64, -21; -32, -21], style(color=0)),
21    Polygon(points=[16, -71; 29, -67; 29, -74; 16, -71], style(
22        color=0,
23        fillColor=0,
24        fillPattern=1)),
25    Polygon(points=[-32, -21; -46, -17; -46, -25; -32, -21], style(
26        color=0,
27        fillColor=0,
28        fillPattern=1))), Documentation(info="<html>
29<p>
30This library contains input/output blocks to build up block diagrams.
31</p>
32
33<dl>
34<dt><b>Main Author:</b>
35<dd><a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a><br>
36    Deutsches Zentrum f&uuml;r Luft und Raumfahrt e. V. (DLR)<br>
37    Oberpfaffenhofen<br>
38    Postfach 1116<br>
39    D-82230 Wessling<br>
40    email: <A HREF=\"mailto:Martin.Otter@dlr.de\">Martin.Otter@dlr.de</A><br>
41</dl>
42<br>
43<br>
44
45<p>
46Copyright &copy; 1998-2006, Modelica Association and DLR.
47</p>
48<p>
49<i>This Modelica package is <b>free</b> software; it can be redistributed and/or modified
50under the terms of the <b>Modelica license</b>, see the license conditions
51and the accompanying <b>disclaimer</b> 
52<a href=\"Modelica://Modelica.UsersGuide.ModelicaLicense\">here</a>.</i>
53</p><br>
54</HTML>
55", revisions="<html>
56<ul>
57<li><i>June 23, 2004</i>
58       by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
59       Introduced new block connectors and adapated all blocks to the new connectors.
60       Included subpackages Continuous, Discrete, Logical, Nonlinear from
61       package ModelicaAdditions.Blocks.
62       Included subpackage ModelicaAdditions.Table in Modelica.Blocks.Sources
63       and in the new package Modelica.Blocks.Tables.
64       Added new blocks to Blocks.Sources and Blocks.Logical.
65       </li>
66<li><i>October 21, 2002</i>
67       by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>
68       and <a href=\"http://www.robotic.dlr.de/Christian.Schweiger/\">Christian Schweiger</a>:<br>
69       New subpackage Examples, additional components.
70       </li>
71<li><i>June 20, 2000</i>
72       by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a> and
73       Michael Tiller:<br>
74       Introduced a replaceable signal type into
75       Blocks.Interfaces.RealInput/RealOutput:
76<pre>
77   replaceable type SignalType = Real
78</pre>
79       in order that the type of the signal of an input/output block
80       can be changed to a physical type, for example:
81<pre>
82   Sine sin1(outPort(redeclare type SignalType=Modelica.SIunits.Torque))
83</pre>
84      </li>
85<li><i>Sept. 18, 1999</i>
86       by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
87       Renamed to Blocks. New subpackages Math, Nonlinear.
88       Additional components in subpackages Interfaces, Continuous
89       and Sources. </li>
90<li><i>June 30, 1999</i>
91       by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
92       Realized a first version, based on an existing Dymola library
93       of Dieter Moormann and Hilding Elmqvist.</li>
94</ul>
95</html>"));
96
97
98package Examples "Demonstration examples of the components of this package" 
99 
100  extends Icons.Library;
101 
102  model PID_Controller "Demonstrate usage of the Continuous.LimPID controller" 
103    extends Modelica.Icons.Example;
104    parameter Modelica.SIunits.Angle driveAngle=1.57;
105    Modelica.Blocks.Continuous.LimPID PI(
106      k=100,
107      Ti=0.1,
108      yMax=12,
109      Ni=0.1,
110      initType=Modelica.Blocks.Types.Init.SteadyState,
111      limitsAtInit=false, 
112      controllerType=Modelica.Blocks.Types.SimpleController.PI) 
113      annotation (extent=[-56,-20; -36,0]);
114    Modelica.Mechanics.Rotational.Inertia inertia1(initType=Modelica.Mechanics.
115          Rotational.Types.Init.InitialAngleAcceleration) 
116                                              annotation (extent=[2,-20; 22,0]);
117    annotation (
118      Diagram(
119        Rectangle(extent=[-99,48; -32,8], style(color=1, rgbcolor={255,0,0})),
120        Text(
121          extent=[-98,59; -31,51],
122          style(color=1, rgbcolor={255,0,0}),
123          string="reference speed generation"),
124        Text(
125          extent=[-98,-46; -60,-52],
126          style(color=1, rgbcolor={255,0,0}),
127          string="PI controller"),
128        Line(points=[-76,-44; -57,-23], style(
129            color=1,
130            rgbcolor={255,0,0},
131            arrow=1)),
132        Rectangle(extent=[-25,6; 99,-50], style(color=1, rgbcolor={255,0,0})),
133        Text(
134          extent=[4,14; 71,7],
135          style(color=1, rgbcolor={255,0,0}),
136          string="plant (simple drive train)")),
137      Coordsys(
138        extent=[-100,-100; 100,100],
139        grid=[1,1],
140        scale=0),
141      experiment(StopTime=4),
142      experimentSetupOutput,
143      Documentation(info="<html>
144
145<p>
146This is a simple drive train controlled by a PID controller:
147</p>
148
149<ul>
150<li> The two blocks \"kinematic_PTP\" and \"integrator\" are used to generate
151     the reference speed (= constant acceleration phase, constant speed phase,
152     constant deceleration phase until inertia is at rest). To check
153     whether the system starts in steady state, the reference speed is
154     zero until time = 0.5 s and then follows the sketched trajectory.</li>
155
156<li> The block \"PI\" is an instance of \"Blocks.Continuous.LimPID\" which is
157     a PID controller where several practical important aspects, such as
158     anti-windup-compensation has been added. In this case, the control block
159     is used as PI controller.</li>
160
161<li> The output of the controller is a torque that drives a motor inertia
162     \"inertia1\". Via a complöiant spring/damper component, the load
163     inertia \"inertia2\" is attached. A constant external torque of 10 Nm
164     is acting on the load inertia.</li>
165</ul>
166
167<p>
168The PI controller settings included \"limitAtInit=false\", in order that
169the controller output limits of 12 Nm are removed from the initialization
170problem.
171</p>
172
173<p>
174The PI controller is initialized in steady state (initType=SteadyState)
175and the drive shall also be initialized in steady state.
176However, it is not possible to initialize \"inertia1\" in SteadyState, because
177\"der(inertia1.phi)=inertia1.w=0\" is an input to the PI controller that
178defines that the derivative of the integrator state is zero (= the same
179condition that was already defined by option SteadyState of the PI controller).
180Furthermore, one initial condition is missing, because the absolute position
181of inertia1 or inertia2 is not defined. The solution shown in this examples is
182to initialize the angle and the angular acceleration of \"inertia1\".
183</p>
184
185<p>
186In the following figure, results of a typical simulation are shown:
187</p>
188
189<p>
190<img src=\"../Images/Blocks/PID_controller.png\"><br>
191<img src=\"../Images/Blocks/PID_controller2.png\">
192</p>
193
194<p>
195In the upper figure the reference speed (= integrator.y) and
196the actual speed (= inertia1.w) are shown. As can be seen,
197the system initializes in steady state, since no transients
198are present. The inertia follows the reference speed quite good
199until the end of the constant speed phase. Then there is a deviation.
200In the lower figure the reason can be seen: The output of the
201controller (PI.y) is in its limits. The anti-windup compensation
202works reasonably, since the input to the limiter (PI.limiter.u)
203is forced back to its limit after a transient phase.
204</p>
205
206</html>"));
207    Modelica.Mechanics.Rotational.Torque torque
208      annotation (extent=[-25,-20; -5,0]);
209    Modelica.Mechanics.Rotational.SpringDamper spring(c=1e4, d=100,
210      initType=Modelica.Mechanics.Rotational.Types.Init.SteadyState,
211      stateSelection=Modelica.Blocks.Types.StateSelection.Prefer) 
212      annotation (extent=[32,-20; 52,0]);
213    Modelica.Mechanics.Rotational.Inertia inertia2(J=2) 
214      annotation (extent=[60,-20; 80,0]);
215    Modelica.Blocks.Sources.KinematicPTP kinematicPTP(startTime=0.5, deltaq={
216          driveAngle}) annotation (extent=[-92,20; -72,40]);
217    Modelica.Blocks.Continuous.Integrator integrator(initType=Modelica.Blocks.
218          Types.Init.InitialState) annotation (extent=[-63,20; -43,40]);
219    Modelica.Mechanics.Rotational.Sensors.SpeedSensor speedSensor
220      annotation (extent=[22,-50; 2,-30]);
221    Modelica.Mechanics.Rotational.ConstantTorque loadTorque(tau_constant=10) 
222      annotation (extent=[98,-15; 88,-5]);
223  equation 
224    connect(spring.flange_b,inertia2. flange_a) 
225      annotation (points=[52,-10; 60,-10], style(color=0, rgbcolor={0,0,0}));
226    connect(inertia1.flange_b, spring.flange_a) 
227      annotation (points=[22,-10; 32,-10], style(color=0, rgbcolor={0,0,0}));
228    connect(torque.flange_b, inertia1.flange_a) 
229      annotation (points=[-5,-10; 2,-10], style(color=0, rgbcolor={0,0,0}));
230    connect(kinematicPTP.y[1], integrator.u) annotation (points=[-71,30; -65,30],
231        style(color=74, rgbcolor={0,0,127}));
232    connect(speedSensor.flange_a, inertia1.flange_b) 
233      annotation (points=[22,-40; 22,-10], style(color=0, rgbcolor={0,0,0}));
234    connect(loadTorque.flange, inertia2.flange_b) 
235      annotation (points=[88,-10; 80,-10], style(color=0, rgbcolor={0,0,0}));
236    connect(PI.y, torque.tau)  annotation (points=[-35,-10; -27,-10], style(
237          color=74, rgbcolor={0,0,127}));
238    connect(speedSensor.w, PI.u_m)  annotation (points=[1,-40; -46,-40; -46,-22],
239        style(color=74, rgbcolor={0,0,127}));
240    connect(integrator.y, PI.u_s)  annotation (points=[-42,30; -37,30; -37,11;
241          -67,11; -67,-10; -58,-10], style(color=74, rgbcolor={0,0,127}));
242  end PID_Controller;
243 
244     model ShowLogicalSources
245       extends Modelica.Icons.Example;
246       Sources.BooleanTable table(table={2,4,6,8}) 
247                                       annotation(extent=[-60,-100; -40,-80]);
248       Sources.BooleanConstant const    annotation(extent=[-60,60; -40,80]);
249       Sources.BooleanStep step(startTime=4) annotation(extent=[-60,20; -40,40]);
250       Sources.BooleanPulse pulse(period=1.5) annotation(extent=[-60,-20; -40,0]);
251       annotation(Diagram,
252      experiment(StopTime=10),
253      experimentSetupOutput);
254      Sources.SampleTrigger sample(
255                          period=0.5) annotation(extent=[-60,-60; -40,-40]);
256      Sources.BooleanExpression booleanExpression(
257                                                y=pulse.y and step.y) 
258      annotation(extent=[20,20; 80,40]);
259     end ShowLogicalSources;
260 
261    model LogicalNetwork1
262   
263    extends Modelica.Icons.Example;
264    Sources.BooleanTable table2(table={1,3,5,7}) annotation(extent=[-80,-20; -60,0]);
265    Sources.BooleanTable table1(table={2,4,6,8}) annotation(extent=[-80,20; -60,40]);
266    Logical.Not Not1 annotation(extent=[-40,-20; -20,0]);
267   
268    annotation(Diagram,
269        experiment(StopTime=10),
270        experimentSetupOutput);
271    Logical.And And1 annotation(extent=[0,-20; 20,0]);
272    Logical.Or Or1 annotation(extent=[40,20; 60,40]);
273    Logical.Pre Pre1 annotation(extent=[-40,-60; -20,-40]);
274    equation 
275   
276    connect(table2.y, Not1.u) annotation(points=[-59,-10; -42,-10], style(
277          color=5, rgbcolor={255,0,255}));
278   
279    connect(And1.y, Or1.u2) annotation(points=[21,-10; 28,-10; 28,22; 38,22],
280        style(color=5, rgbcolor={255,0,255}));
281   
282    connect(table1.y, Or1.u1) annotation(points=[-59,30; 38,30], style(color=
283            5, rgbcolor={255,0,255}));
284   
285    connect(Not1.y, And1.u1) annotation(points=[-19,-10; -2,-10], style(color=
286           5, rgbcolor={255,0,255}));
287   
288    connect(Pre1.y, And1.u2) annotation(points=[-19,-50; -10,-50; -10,-18; -2,
289          -18], style(color=5, rgbcolor={255,0,255}));
290   
291    connect(Or1.y, Pre1.u) annotation(points=[61,30; 68,30; 68,-70; -60,-70;
292          -60,-50; -42,-50], style(color=5, rgbcolor={255,0,255}));
293   
294    end LogicalNetwork1;
295 
296  encapsulated model BusUsage "Demonstration of signal bus usage" 
297    import Modelica.Icons;
298    import Modelica.Blocks.Interfaces.Adaptors;
299    import Modelica.Blocks.Sources;
300    import Modelica;
301   
302    extends Icons.Example;
303   
304    annotation (preferedView="info",Documentation(info="<HTML>
305<p><b>Signal bus concept</b></p>
306<p>
307In technical systems, such as vehicles, robots or satellites, many signals
308are exchanged between components. In a simulation system, these signals
309are  usually modelled by signal connections of input/output blocks.
310Unfortunately, the signal connection structure may become very complicated,
311especially for hierarchical models.
312</p>
313<p>
314The same is also true for real technical systems. To reduce complexity
315and get higher flexibility, many technical systems use data buses to
316exchange data between components. For the same reasons, it is often better
317to use a \"signal bus\" concept also in a Modelica model. This is demonstrated
318at hand of this model (Modelica.Blocks.Examples.BusUsage), see diagram layer:
319</p>
320<ul>
321<li>The thick line in the middle called \"bus\" is just a connector instance
322    which is drawn such that it looks like a \"usual\" bus representation. </li>
323<li>A component, such as \"part\", can be directly connected to the \"bus\",
324    provided it has also a bus connector, or the \"part\" connector is a
325    sub-connector contained in the \"bus\". </li>
326</ul>
327<p>
328Difficulties arise if the input or output connector of an
329input/output block shall be connected directly to a variable
330of a bus because connections can only be performed between
331connectors but not between variables. For convenience,
332single variable connectors for Real, Integer and Boolean
333variables are provided as Modelica.Blocks.Interfaces.<b>RealSignal</b>,
334Modelica.Blocks.Interfaces.<b>IntegerSignal</b>,
335Modelica.Blocks.Interfaces.<b>BooleanSignal</b>.
336For example, the RealSignal connector is basically defined as:
337</p>
338<pre>  <b>connector</b> RealSignal = Real;
339</pre>
340<p>
341This allows a definition of a bus in the form:
342</p>
343<pre>   <b>connector</b> Bus
344      RealSignal r1;
345      RealSignal r2;
346        ...
347   <b>end</b> Bus;
348</pre>
349<p>
350and a connection to r1 and r2 is possible since these are connectors.
351Unfortunately, signals defined in this way have, by default, no unit.
352To improve this situation, a RealSignal is actually defined as
353</p>
354<pre>   <b>connector</b> RealSignal
355      <b>replaceable type</b> SignalType = Real;
356      <b>extends</b> SignalType;
357   <b>end</b> RealSignal;
358</pre>
359<p>
360This allows a redeclaration of the Real type to the desired type, such as:
361</p>
362<pre>   <b>connector</b> Bus
363      <b>import</b> SI=Modelica.SIunits;
364      RealSignal v(<b>redeclare</b> SignalType=SI.Velocity);
365      RealSignal p(<b>redeclare</b> SignalType=SI.Pressure);
366      ...
367   <b>end</b> Bus;
368</pre>
369<p>
370Note, since RealSignal, RealInput and RealOutput have basically
371the same definition, it is possible to directly connector
372from a RealSignal of a bus to a RealInput or RealOutput of
373a block component.
374</p>
375<p>
376If a bus connector contains many signals it is no longer so easy
377to test just one part of a system, because all parts of
378the bus connector must get a value. To simplify this,
379it is practical to provide a <b>RestBus</b> component which
380sets all parts of a bus to a default value when selected
381via the parameter menu. This is also demonstrated in the example
382model (see diagram layer).
383</p>
384<p>Simulate the system for 1 s. The output of the \"gain\" block
385should be the same as the one from the \"generateRealSignal1\"
386block.
387</p>
388</HTML>"), Diagram);
389  protected 
390    Interfaces.Bus bus annotation (Hide=false, extent=[-80, -20; 80, -14]);
391  public 
392    RestBus restBus(set_realSignal2=true) annotation (extent=[60, 20; 80, 40]);
393    Sources.IntegerStep integerStep(
394      height=1,
395      offset=2,
396      startTime=0.5)   annotation (extent=[20,20; 40,40],   rotation=270);
397    Sources.BooleanStep booleanStep(startTime=0.5)             annotation (
398        extent=[-20,20; 0,40],   rotation=270);
399    Sources.Sine sine                annotation (extent=[-60,20; -40,40],
400        rotation=270);
401   
402    encapsulated package Interfaces "Interfaces specialised for this example" 
403     
404      connector MultiPort "Combined port of real and boolean signal" 
405        Real myRealSignal;
406        Boolean myBooleanSignal;
407       
408        annotation (Icon(Rectangle(extent=[-100, 100; 100, -100], style(
409                  fillColor=76, fillPattern=1))), Diagram(Rectangle(extent=[-
410                  100, 100; 100, -100], style(fillColor=76, fillPattern=1))));
411      end MultiPort;
412     
413      connector Bus "Signal bus" 
414        import SI = Modelica.SIunits;
415        import Modelica.Blocks.Interfaces.*;
416       
417        RealSignal realSignal1(redeclare type SignalType = SI.AngularVelocity) 
418          "First Real signal (angular velocity)";
419        RealSignal realSignal2 "Second Real signal";
420        IntegerSignal integerSignal "Integer signal";
421        BooleanSignal booleanSignal "Boolean signal";
422        MultiPort multiSignal "Combined signal";
423       
424        annotation (
425          Icon(Rectangle(extent=[-100, 100; 100, -100], style(
426                color=77,
427                fillColor=77,
428                fillPattern=1)), Text(
429              extent=[-134, 168; 134, 108],
430              string="%name",
431              style(color=77))),
432          Diagram(Text(
433              extent=[-134, 168; 134, 108],
434              string="%name",
435              style(color=77)), Rectangle(extent=[-100, 100; 100, -100], style(
436                color=77,
437                fillColor=77,
438                fillPattern=1))),
439          Documentation(info="<HTML>
440<p>Defines connector for signalbus.</p>
441</HTML>
442"));
443      end Bus;
444    end Interfaces;
445   
446    encapsulated model Part "Component with MultiPort connector" 
447      import Modelica.Blocks.Examples;
448     
449      Examples.BusUsage.Interfaces.MultiPort multiSignal annotation (extent=[
450            100, -10; 120, 10]);
451     
452      annotation (Icon(Rectangle(extent=[-100, 60; 100, -60], style(fillColor=
453                  76, fillPattern=1)), Text(
454            extent=[-106, 124; 114, 68],
455            style(fillColor=76, fillPattern=1),
456            string="%name")));
457    equation 
458      multiSignal.myRealSignal = time;
459      multiSignal.myBooleanSignal = time > 0.5;
460    end Part;
461   
462    encapsulated model RestBus
463      "Set default values for bus variables that are not defined elsewhere" 
464     
465      import Modelica.Blocks.Examples;
466     
467      parameter Boolean set_realSignal1=false 
468        "Set dummy value for desiredThrottle";
469      parameter Boolean set_realSignal2=false "Set dummy value for brake";
470      parameter Boolean set_integerSignal=false 
471        "Set dummy value for controlLeverPosition";
472      parameter Boolean set_booleanSignal=false 
473        "Set dummy value for desiredGear";
474      parameter Boolean set_multiSignal=false "Set dummy value for ignition";
475     
476      annotation (Icon(
477          Rectangle(extent=[-100, 100; 100, -100], style(fillColor=7,
478                fillPattern=1)),
479          Text(
480            extent=[-100, 156; 100, 96],
481            string="%name",
482            style(pattern=0)),
483          style(color=77),
484          Text(
485            extent=[46, -10; 88, -40],
486            style(color=0),
487            string="0"),
488          Text(
489            extent=[-82, 62; 38, 34],
490            style(color=0),
491            string="false"),
492          Line(points=[-28, 24; -28, -66; 0, -66; 0, -104; 0, -102], style(
493              color=77,
494              fillColor=7,
495              fillPattern=1)),
496          Line(points=[68, -46; 68, -66; 0, -66; 0, -108], style(
497              color=77,
498              fillColor=7,
499              fillPattern=1)),
500          Rectangle(extent=[-90, 78; 46, 24], style(color=0)),
501          Rectangle(extent=[40, -4; 92, -46], style(color=0))));
502      Examples.BusUsage.Interfaces.Bus bus annotation (extent=[-10, -120; 10, -
503            100], rotation=90);
504    equation 
505      if set_realSignal1 then
506        bus.realSignal1 = 0;
507      end if;
508      if set_realSignal2 then
509        bus.realSignal2 = 0;
510      end if;
511      if set_integerSignal then
512        bus.integerSignal = 0;
513      end if;
514      if set_booleanSignal then
515        bus.booleanSignal = false;
516      end if;
517      if set_multiSignal then
518        bus.multiSignal.myRealSignal = 0;
519        bus.multiSignal.myBooleanSignal = false;
520      end if;
521    end RestBus;
522   
523    Part part annotation (extent=[-96,-60; -76,-40]);
524    Modelica.Blocks.Math.Gain gain
525      annotation(extent=[-46,-80; -26,-60], rotation=-90);
526  equation 
527   
528    connect(restBus.bus, bus) annotation (points=[70,19; 70,-17; 0,-17],
529                                                                    style(color=
530           77));
531    connect(part.multiSignal, bus.multiSignal) annotation (points=[-75,-50; -58,
532          -50; -58,-16; 0,-16; 0,-17]);
533    connect(sine.y, bus.realSignal1) 
534      annotation(points=[-50,19; -50,-17; 0,-17],
535                                           style(color=3, rgbcolor={0,0,255}));
536    connect(booleanStep.y, bus.booleanSignal)           annotation(points=[-10,
537          19; -10,-16; 0,-16; 0,-17],
538                        style(color=5, rgbcolor={255,0,255}));
539    connect(integerStep.y, bus.integerSignal)           annotation(points=[30,
540          19; 30,-17; 0,-17],         style(color=45, rgbcolor={255,127,0}));
541    connect(gain.u, bus.realSignal1) annotation(points=[-36,-58; -36,-18],
542        style(color=3, rgbcolor={0,0,255}));
543  end BusUsage;
544 
545  annotation (Documentation(info="<html>
546<p>
547This package contains example models to demonstrate the
548usage of package blocks.
549</p>
550</HTML>
551"));
552 
553end Examples;
554end Blocks;
Note: See TracBrowser for help on using the browser.