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

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