root/branches/maintenance/2.2.2/Modelica/Blocks/Nonlinear.mo

Revision 550, 25.4 kB (checked in by otter, 15 months ago)

Library description string made in a standardized fashion for the top-level libraries
(Library of xxx)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1within Modelica.Blocks;
2package Nonlinear
3  "Library of discontinuous or non-differentiable algebraic control blocks" 
4  import Modelica.Blocks.Interfaces;
5      extends Modelica.Icons.Library;
6 
7      annotation(preferedView="info",
8        Coordsys(
9          extent=[0, 0; 207, 132],
10          grid=[1, 1],
11          component=[20, 20]),
12        Window(
13          x=0.05,
14          y=0.1,
15          width=0.21,
16          height=0.23,
17          library=1,
18          autolayout=1),
19        Documentation(info="
20<HTML>
21<p>
22This package contains <b>discontinuous</b> and
23<b>non-differentiable, algebraic</b> input/output blocks.
24</p>
25</HTML>
26", revisions="<html>
27<ul>
28<li><i>October 21, 2002</i>
29       by <a href=\"http://www.robotic.dlr.de/Christian.Schweiger/\">Christian Schweiger</a>:<br>
30       New block VariableLimiter added.
31<li><i>August 22, 1999</i>
32       by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
33       Realized, based on an existing Dymola library
34       of Dieter Moormann and Hilding Elmqvist.
35</li>
36</ul>
37</html>
38"));
39      block Limiter "Limit the range of a signal" 
40        parameter Real uMax=1 "Upper limits of input signals";
41        parameter Real uMin= -uMax "Lower limits of input signals";
42        parameter Boolean limitsAtInit = true 
43      "= false, if limits are ignored during initializiation (i.e., y=u)";
44        extends Interfaces.SISO;
45   
46        annotation (
47          Coordsys(
48            extent=[-100, -100; 100, 100],
49            grid=[2, 2],
50            component=[20, 20]),
51          Window(
52            x=0.22,
53            y=0.06,
54            width=0.43,
55            height=0.51),
56          Documentation(info="
57<HTML>
58<p>
59The Limiter block passes its input signal as output signal
60as long as the input is within the specified upper and lower
61limits. If this is not the case, the corresponding limits are passed
62as output.
63</p>
64</HTML>
65"),       Icon(
66            Line(points=[0, -90; 0, 68], style(color=8)),
67            Polygon(points=[0, 90; -8, 68; 8, 68; 0, 90], style(color=8,
68                  fillColor=8)),
69            Line(points=[-90, 0; 68, 0], style(color=8)),
70            Polygon(points=[90, 0; 68, -8; 68, 8; 90, 0], style(color=8,
71                  fillColor=8)),
72            Line(points=[-80, -70; -50, -70; 50, 70; 80, 70], style(color=0)),
73            Text(
74              extent=[-150, -150; 150, -110],
75              string="uMax=%uMax",
76              style(color=0)),
77            Text(extent=[-150, 150; 150, 110], string="%name")),
78          Diagram(
79            Line(points=[0, -60; 0, 50], style(color=8)),
80            Polygon(points=[0, 60; -5, 50; 5, 50; 0, 60], style(color=8,
81                  fillColor=8)),
82            Line(points=[-60, 0; 50, 0], style(color=8)),
83            Polygon(points=[60, 0; 50, -5; 50, 5; 60, 0], style(color=8,
84                  fillColor=8)),
85            Line(points=[-50, -40; -30, -40; 30, 40; 50, 40], style(color=0)),
86            Text(
87              extent=[46, -6; 68, -18],
88              string="u",
89              style(color=10)),
90            Text(
91              extent=[-30, 70; -5, 50],
92              string="y",
93              style(color=10)),
94            Text(
95              extent=[-58, -54; -28, -42],
96              string="uMin",
97              style(color=10)),
98            Text(
99              extent=[26, 40; 66, 56],
100              string="uMax",
101              style(color=10))));
102      equation 
103        assert(uMax >= uMin, "Limiter: Limits must be consistent. However, uMax (=" + String(uMax) +
104                             ") < uMin (=" + String(uMin) + ")");
105        if initial() and not limitsAtInit then
106           y = u;
107           assert(u >= uMin - 0.01*abs(uMin) and 
108                  u <= uMax + 0.01*abs(uMax),
109                 "Limiter: During initialization the limits have been ignored.\n"+
110                 "However, the result is that the input u is not within the required limits:\n"+
111                 "  u = " + String(u) + ", uMin = " + String(uMin) + ", uMax = " + String(uMax));
112        else
113           y = smooth(0,if u > uMax then uMax else if u < uMin then uMin else u);
114        end if;
115      end Limiter;
116 
117  block VariableLimiter "Limit the range of a signal with variable limits" 
118    extends Interfaces.SISO;
119    parameter Boolean limitsAtInit = true 
120      "= false, if limits are ignored during initializiation (i.e., y=u)";
121    Interfaces.RealInput limit1
122      "Connector of Real input signal used as maximum of input u" 
123                                annotation (extent=[-140, 60; -100, 100]);
124    Interfaces.RealInput limit2
125      "Connector of Real input signal used as minimum of input u" 
126                                annotation (extent=[-140, -100; -100, -
127          60]);
128  protected 
129    Real uMax;
130    Real uMin;
131   
132    annotation (
133      Documentation(info="<html>
134<p>
135The Limiter block passes its input signal as output signal
136as long as the input is within the upper and lower
137limits specified by the two additional inputs limit1 and
138limit2. If this is not the case, the corresponding limit
139is passed as output.
140</p>
141</HTML>
142"),   Icon(
143        Line(points=[0, -90; 0, 68], style(color=8)),
144        Line(points=[-90, 0; 68, 0], style(color=8)),
145        Polygon(points=[90, 0; 68, -8; 68, 8; 90, 0], style(color=8, fillColor=
146                8)),
147        Line(points=[-80, -70; -50, -70; 50, 70; 80, 70], style(color=0)),
148        Text(extent=[-150, 150; 150, 110], string="%name"),
149        Line(points=[-100, 80; 66, 80; 66, 70], style(fillPattern=1)),
150        Line(points=[-100, -80; -64, -80; -64, -70], style(fillPattern=1)),
151        Polygon(points=[-64, -70; -66, -74; -62, -74; -64, -70], style(
152              fillPattern=1)),
153        Polygon(points=[66, 70; 64, 74; 68, 74; 66, 70], style(fillPattern=1)),
154        Polygon(points=[0, 90; -8, 68; 8, 68; 0, 90], style(color=8, fillColor=
155                8))),
156      Diagram(
157        Line(points=[0, -60; 0, 50], style(color=8)),
158        Polygon(points=[0, 60; -5, 50; 5, 50; 0, 60], style(color=8, fillColor=
159                8)),
160        Line(points=[-60, 0; 50, 0], style(color=8)),
161        Polygon(points=[60, 0; 50, -5; 50, 5; 60, 0], style(color=8, fillColor=
162                8)),
163        Line(points=[-50, -40; -30, -40; 30, 40; 50, 40], style(color=0)),
164        Text(
165          extent=[46, -6; 68, -18],
166          string="inPort",
167          style(color=10)),
168        Text(
169          extent=[-30, 70; -5, 50],
170          string="outPort",
171          style(color=10)),
172        Text(
173          extent=[-66, -40; -26, -20],
174          string="uMin",
175          style(color=10)),
176        Text(
177          extent=[30, 20; 70, 40],
178          string="uMax",
179          style(color=10)),
180        Line(points=[-100, 80; 40, 80; 40, 40]),
181        Line(points=[-100, -80; -40, -80; -40, -40]),
182        Polygon(points=[40, 40; 35, 50; 45, 50; 40, 40], style(fillPattern=1)),
183        Polygon(points=[-40, -40; -45, -50; -35, -50; -40, -40], style(
184              fillPattern=1))));
185  equation 
186    uMax = max(limit1, limit2);
187    uMin = min(limit1, limit2);
188   
189    if initial() and not limitsAtInit then
190       y = u;
191       assert(u >= uMin - 0.01*abs(uMin) and 
192              u <= uMax + 0.01*abs(uMax),
193             "VariableLimiter: During initialization the limits have been ignored.\n"+
194             "However, the result is that the input u is not within the required limits:\n"+
195             "  u = " + String(u) + ", uMin = " + String(uMin) + ", uMax = " + String(uMax));
196    else
197       y = smooth(0,if u > uMax then uMax else if u < uMin then uMin else u);
198    end if;
199  end VariableLimiter;
200 
201      block DeadZone "Provide a region of zero output" 
202        parameter Real uMax=1 "Upper limits of dead zones";
203        parameter Real uMin=-uMax "Lower limits of dead zones";
204        parameter Boolean deadZoneAtInit = true 
205      "= false, if dead zone is ignored during initializiation (i.e., y=u)";
206        extends Interfaces.SISO;
207   
208        annotation (
209          Coordsys(
210            extent=[-100, -100; 100, 100],
211            grid=[1, 1],
212            component=[20, 20]),
213          Window(
214            x=0.39,
215            y=0.18,
216            width=0.56,
217            height=0.6),
218          Documentation(info="
219<HTML>
220<p>
221The DeadZone block defines a region of zero output.
222</p>
223<p>
224If the input is within uMin ... uMax, the output
225is zero. Outside of this zone, the output is a linear
226function of the input with a slope of 1.
227</p>
228</HTML>
229"),       Icon(
230            Line(points=[0, -90; 0, 68], style(color=8)),
231            Polygon(points=[0, 90; -8, 68; 8, 68; 0, 90], style(color=8,
232                  fillColor=8)),
233            Line(points=[-90, 0; 68, 0], style(color=8)),
234            Polygon(points=[90, 0; 68, -8; 68, 8; 90, 0], style(color=8,
235                  fillColor=8)),
236            Line(points=[-80, -60; -20, 0; 20, 0; 80, 60], style(color=0)),
237            Text(
238              extent=[-150, -150; 150, -110],
239              string="uMax=%uMax",
240              style(color=9)),
241            Text(extent=[-150, 150; 150, 110], string="%name")),
242          Diagram(
243            Line(points=[0, -60; 0, 50], style(color=8)),
244            Polygon(points=[0, 60; -5, 50; 5, 50; 0, 60], style(color=8,
245                  fillColor=8)),
246            Line(points=[-76, 0; 74, 0], style(color=8)),
247            Polygon(points=[84, 0; 74, -5; 74, 5; 84, 0], style(color=8,
248                  fillColor=8)),
249            Line(points=[-81, -40; -38, 0; 40, 0; 80, 40], style(color=0)),
250            Text(
251              extent=[62, -7; 88, -25],
252              string="u",
253              style(color=10)),
254            Text(
255              extent=[-36, 72; -5, 50],
256              string="y",
257              style(color=10)),
258            Text(
259              extent=[-51, 1; -28, 19],
260              string="uMin",
261              style(color=10)),
262            Text(
263              extent=[27, 21; 52, 5],
264              string="uMax",
265              style(color=10))));
266      equation 
267        assert(uMax >= uMin, "DeadZone: Limits must be consistent. However, uMax (=" + String(uMax) +
268                             ") < uMin (=" + String(uMin) + ")");
269   
270        if initial() and not deadZoneAtInit then
271           y = u;
272        else
273           y = smooth(0,if u > uMax then u - uMax else if u < uMin then u - uMin else 0);
274        end if;
275      end DeadZone;
276 
277  block FixedDelay "Delay block with fixed DelayTime" 
278    extends Modelica.Blocks.Interfaces.SISO;
279    parameter SI.Time delayTime=1 
280      "Delay time of output with respect to input signal";
281   
282    annotation (
283      Coordsys(
284        extent=[-100, -100; 100, 100],
285        grid=[2, 2],
286        component=[20, 20]),
287      Window(
288        x=0.27,
289        y=0.09,
290        width=0.65,
291        height=0.78),
292      Documentation(info="<html>
293<p>
294The Input signal is delayed by a given time instant, or more precisely:
295</p>
296<pre>
297   y = u(time - delayTime) for time &gt; time.start + delayTime
298     = u(time.start)       for time &le; time.start + delayTime
299</pre>
300</html>
301"),   Icon(
302        Text(
303          extent=[8, -102; 8, -142],
304          string="delayTime=%delayTime",
305          style(color=0)),
306        Line(points=[-92, 0; -80.7, 34.2; -73.5, 53.1; -67.1, 66.4; -61.4, 74.6;
307                -55.8, 79.1; -50.2, 79.8; -44.6, 76.6; -38.9, 69.7; -33.3, 59.4;
308                -26.9, 44.1; -18.83, 21.2; -1.9, -30.8; 5.3, -50.2; 11.7, -64.2;
309                17.3, -73.1; 23, -78.4; 28.6, -80; 34.2, -77.6; 39.9, -71.5;
310              45.5, -61.9; 51.9, -47.2; 60, -24.8; 68, 0], style(color=73)),
311        Line(points=[-62, 0; -50.7, 34.2; -43.5, 53.1; -37.1, 66.4; -31.4, 74.6;
312                -25.8, 79.1; -20.2, 79.8; -14.6, 76.6; -8.9, 69.7; -3.3, 59.4;
313              3.1, 44.1; 11.17, 21.2; 28.1, -30.8; 35.3, -50.2; 41.7, -64.2;
314              47.3, -73.1; 53, -78.4; 58.6, -80; 64.2, -77.6; 69.9, -71.5; 75.5,
315                -61.9; 81.9, -47.2; 90, -24.8; 98, 0], style(color=9))),
316      Diagram(
317        Line(points=[-80, 80; -88, 80], style(color=8)),
318        Line(points=[-80, -80; -88, -80], style(color=8)),
319        Line(points=[-80, -88; -80, 86], style(color=8)),
320        Text(
321          extent=[-75, 98; -46, 78],
322          string="outPort",
323          style(color=73)),
324        Polygon(points=[-80, 96; -86, 80; -74, 80; -80, 96], style(color=8,
325              fillColor=8)),
326        Line(points=[-100, 0; 84, 0], style(color=8)),
327        Polygon(points=[100, 0; 84, 6; 84, -6; 100, 0], style(color=8,
328              fillColor=8)),
329        Line(points=[-80, 0; -68.7, 34.2; -61.5, 53.1; -55.1, 66.4; -49.4, 74.6;
330                -43.8, 79.1; -38.2, 79.8; -32.6, 76.6; -26.9, 69.7; -21.3, 59.4;
331                -14.9, 44.1; -6.83, 21.2; 10.1, -30.8; 17.3, -50.2; 23.7, -64.2;
332                29.3, -73.1; 35, -78.4; 40.6, -80; 46.2, -77.6; 51.9, -71.5;
333              57.5, -61.9; 63.9, -47.2; 72, -24.8; 80, 0], style(color=73)),
334        Text(
335          extent=[-24, 98; -2, 78],
336          string="inPort",
337          style(color=0)),
338        Line(points=[-64, 0; -52.7, 34.2; -45.5, 53.1; -39.1, 66.4; -33.4, 74.6;
339                -27.8, 79.1; -22.2, 79.8; -16.6, 76.6; -10.9, 69.7; -5.3, 59.4;
340                1.1, 44.1; 9.17, 21.2; 26.1, -30.8; 33.3, -50.2; 39.7, -64.2;
341              45.3, -73.1; 51, -78.4; 56.6, -80; 62.2, -77.6; 67.9, -71.5; 73.5,
342                -61.9; 79.9, -47.2; 88, -24.8; 96, 0], style(color=0)),
343        Text(
344          extent=[67, 22; 96, 6],
345          string="time",
346          style(color=9)),
347        Line(points=[-64, -30; -64, 0], style(color=8)),
348        Text(extent=[-58, -42; -58, -32], string="delayTime"),
349        Line(points=[-94, -26; -80, -26], style(color=8)),
350        Line(points=[-64, -26; -50, -26], style(color=8)),
351        Polygon(points=[-80, -26; -88, -24; -88, -28; -80, -26], style(color=8,
352                fillColor=8)),
353        Polygon(points=[-56, -24; -64, -26; -56, -28; -56, -24], style(color=8,
354                fillColor=8))));
355  equation 
356    y = delay(u, delayTime);
357  end FixedDelay;
358 
359  block PadeDelay "Pade approximation of delay block with fixed DelayTime " 
360    extends Modelica.Blocks.Interfaces.SISO;
361    parameter SI.Time delayTime=1 
362      "Delay time of output with respect to input signal";
363    parameter Integer n(min=1) = 1 "Order of pade approximation";
364    parameter Integer m(
365      min=1,
366      max=n) = n "Order of numerator";
367   
368  protected 
369    Real x1dot "Derivative of first state of TransferFcn";
370    Real xn "Highest order state of TransferFcn";
371    Real a[n + 1];
372    Real b[m + 1];
373   
374  public 
375    final output Real x[n] 
376      "State of transfer function from controller canonical form";
377    annotation (
378      Coordsys(
379        extent=[-100, -100; 100, 100],
380        grid=[2, 2],
381        component=[20, 20]),
382      Window(
383        x=0.27,
384        y=0.09,
385        width=0.65,
386        height=0.78),
387      Documentation(info="<html>
388<p>
389The Input signal is delayed by a given time instant, or more precisely:
390</p>
391<pre>
392   y = u(time - delayTime) for time &gt; time.start + delayTime
393     = u(time.start)       for time &le; time.start + delayTime
394</pre>
395<p>
396The delay is approximated by a Pade approximation, i.e., by
397a transfer function
398</p>
399<pre>
400           b[1]*s^m + b[2]*s^[m-1] + ... + b[m+1]
401   y(s) = --------------------------------------------- * u(s)
402           a[1]*s^n + a[2]*s^[n-1] + ... + a[n+1]
403</pre>
404<p>
405where the coefficients b[:] and a[:] are calculated such that the
406coefficients of the Taylor expansion of the delay exp(-T*s) around s=0
407are identical upto order n+m.
408</p>
409<p>
410The main advantage of this approach is that the delay is
411approximated by a linear differential equation system, which
412is continuous and continuously differentiable. For example, it
413is uncritical to linearize a system containing a Pade-approximated
414delay.
415</p>
416<p>
417The standard text book version uses order \"m=n\", which is
418also the default setting of this block. The setting
419\"m=n-1\" may yield a better approximation in certain cases.
420<p>
421<p>
422Literature:<br>
423Otto Foellinger: Regelungstechnik, 8. Auflage,
424chapter 11.9, page 412-414, Huethig Verlag Heidelberg, 1994
425</p>
426</html>
427"),   Icon(
428        Text(
429          extent=[8, -102; 8, -142],
430          string="delayTime=%delayTime",
431          style(color=0)),
432        Line(points=[-94, 0; -82.7, 34.2; -75.5, 53.1; -69.1, 66.4; -63.4, 74.6;
433                -57.8, 79.1; -52.2, 79.8; -46.6, 76.6; -40.9, 69.7; -35.3, 59.4;
434                -28.9, 44.1; -20.83, 21.2; -3.9, -30.8; 3.3, -50.2; 9.7, -64.2;
435                15.3, -73.1; 21, -78.4; 26.6, -80; 32.2, -77.6; 37.9, -71.5;
436              43.5, -61.9; 49.9, -47.2; 58, -24.8; 66, 0], style(color=73)),
437        Line(points=[-72, 0; -60.7, 34.2; -53.5, 53.1; -47.1, 66.4; -41.4, 74.6;
438                -35.8, 79.1; -30.2, 79.8; -24.6, 76.6; -18.9, 69.7; -13.3, 59.4;
439                -6.9, 44.1; 1.17, 21.2; 18.1, -30.8; 25.3, -50.2; 31.7, -64.2;
440              37.3, -73.1; 43, -78.4; 48.6, -80; 54.2, -77.6; 59.9, -71.5; 65.5,
441                -61.9; 71.9, -47.2; 80, -24.8; 88, 0], style(color=9)),
442        Text(
443          extent=[-10, 100; 100, 38],
444          string="m=%m",
445          style(color=9)),
446        Text(
447          extent=[-98, -34; 6, -96],
448          string="n=%n",
449          style(color=9))),
450      Diagram(
451        Line(points=[-80, 80; -88, 80], style(color=8)),
452        Line(points=[-80, -80; -88, -80], style(color=8)),
453        Line(points=[-80, -88; -80, 86], style(color=8)),
454        Text(
455          extent=[-75, 98; -46, 78],
456          string="outPort",
457          style(color=73)),
458        Polygon(points=[-80, 96; -86, 80; -74, 80; -80, 96], style(color=8,
459              fillColor=8)),
460        Line(points=[-100, 0; 84, 0], style(color=8)),
461        Polygon(points=[100, 0; 84, 6; 84, -6; 100, 0], style(color=8,
462              fillColor