root/trunk/Modelica/Blocks/Nonlinear.mo

Revision 1044, 29.5 kB (checked in by otter, 9 months ago)

Removed "Windows(..)" annotation (an "old" Dymola 4 annotation that was not used anymore and is not part of the Modelica 3 graphical annotations)

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