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

Revision 1182, 130.6 kB (checked in by otter, 4 weeks ago)

Blocks.KinematicPTP/KinematicPTP2: Fixed tiny bug using forgotten "each"

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1within Modelica.Blocks;
2package Sources
3  "Library of signal source blocks generating Real and Boolean signals" 
4  block RealExpression "Set output signal to a time varying Real expression" 
5   
6    Blocks.Interfaces.RealOutput y=0.0 "Value of Real output" 
7      annotation (extent=[100, -10; 120, 10], Dialog(group=
8            "Time varying output signal"));
9   
10    annotation (
11      Coordsys(
12        extent=[-100, -100; 100, 100],
13        grid=[2, 2],
14        component=[20, 20]),
15      Window(
16        x=0.29,
17        y=0.23,
18        width=0.6,
19        height=0.6),
20      Icon(
21        Rectangle(extent=[-100,40; 100,-40],   style(
22            color=0,
23            fillColor=30,
24            fillPattern=11)),
25        Text(
26          extent=[-96,15; 96,-15],
27          string="%y",
28          style(
29            color=0,
30            fillColor=2,
31            fillPattern=1)), Text(extent=[-150,90; 140,50],     string="%name")),
32      Diagram,
33      Documentation(info="<html>
34<p>
35The (time varying) Real output signal of this block can be defined in its
36parameter menu via variable <b>y</b>. The purpose is to support the
37easy definition of Real expressions in a block diagram. For example,
38in the y-menu the definition \"if time &lt; 1 then 0 else 1\" can be given in order
39to define that the output signal is one, if time &ge; 1 and otherwise
40it is zero. Note, that \"time\" is a built-in variable that is always
41accessible and represents the \"model time\" and that
42Variable <b>y</b> is both a variable and a connector.
43</p>
44</html>"));
45   
46  end RealExpression;
47 
48  block IntegerExpression
49    "Set output signal to a time varying Integer expression" 
50   
51    Blocks.Interfaces.IntegerOutput y=0 "Value of Integer output" 
52      annotation (extent=[100, -10; 120, 10], Dialog(group=
53            "Time varying output signal"));
54   
55    annotation (
56      Coordsys(
57        extent=[-100, -100; 100, 100],
58        grid=[2, 2],
59        component=[20, 20]),
60      Window(
61        x=0.29,
62        y=0.23,
63        width=0.6,
64        height=0.6),
65      Icon(
66        Rectangle(extent=[-100,40; 100,-40],   style(
67            color=0,
68            fillColor=30,
69            fillPattern=11)),
70        Text(
71          extent=[-96,15; 96,-15],
72          string="%y",
73          style(
74            color=0,
75            fillColor=2,
76            fillPattern=1)), Text(extent=[-150,90; 140,50],     string="%name")),
77      Diagram,
78      Documentation(info="<html>
79<p>
80The (time varying) Integer output signal of this block can be defined in its
81parameter menu via variable <b>y</b>. The purpose is to support the
82easy definition of Integer expressions in a block diagram. For example,
83in the y-menu the definition \"if time &lt; 1 then 0 else 1\" can be given in order
84to define that the output signal is one, if time &ge; 1 and otherwise
85it is zero. Note, that \"time\" is a built-in variable that is always
86accessible and represents the \"model time\" and that
87Variable <b>y</b> is both a variable and a connector.
88</p>
89</html>"));
90   
91  end IntegerExpression;
92 
93  block BooleanExpression
94    "Set output signal to a time varying Boolean expression" 
95   
96    Blocks.Interfaces.BooleanOutput y=false "Value of Boolean output" 
97      annotation (extent=[100, -10; 120, 10], Dialog(group=
98            "Time varying output signal"));
99   
100    annotation (
101      Coordsys(
102        extent=[-100, -100; 100, 100],
103        grid=[2, 2],
104        component=[20, 20]),
105      Window(
106        x=0.29,
107        y=0.23,
108        width=0.6,
109        height=0.6),
110      Icon(
111        Rectangle(extent=[-100,40; 100,-40],   style(
112            color=0,
113            fillColor=30,
114            fillPattern=11)),
115        Text(
116          extent=[-96,15; 96,-15],
117          string="%y",
118          style(
119            color=0,
120            fillColor=2,
121            fillPattern=1)), Text(extent=[-150,90; 140,50],     string="%name"),
122  Polygon(points=[100,10; 120,0; 100,-10; 100,10],
123             style(color=DynamicSelect(5, if y > 0.5 then 2 else 5),
124              fillColor=DynamicSelect(7, if y > 0.5 then 2 else 7)))),
125      Diagram,
126      Documentation(info="<html>
127<p>
128The (time varying) Boolean output signal of this block can be defined in its
129parameter menu via variable <b>y</b>. The purpose is to support the
130easy definition of Boolean expressions in a block diagram. For example,
131in the y-menu the definition \"time &gt;= 1 and time &lt;= 2\" can be given in order
132to define that the output signal is <b>true</b> in the time interval
1331 &le; time &le; 2 and otherwise it is <b>false</b>.
134Note, that \"time\" is a built-in variable that is always
135accessible and represents the \"model time\" and that
136Variable <b>y</b> is both a variable and a connector.
137</p>
138</html>"));
139   
140  end BooleanExpression;
141  import Modelica.Blocks.Interfaces;
142  import Modelica.SIunits;
143      extends Modelica.Icons.Library;
144 
145      annotation(preferedView="info",
146        Coordsys(
147          extent=[0, 0; 430, 442],
148          grid=[1, 1],
149          component=[20, 20]),
150        Window(
151          x=0.06,
152          y=0.1,
153          width=0.43,
154          height=0.65,
155          library=1,
156          autolayout=1),
157        Documentation(info="<HTML>
158<p>
159This package contains <b>source</b> components, i.e., blocks which
160have only output signals. These blocks are used as signal generators
161for Real, Integer and Boolean signals.
162</p>
163
164<p>
165All Real source signals (with the exception of the Constant source)
166have at least the following two parameters:
167</p>
168
169<table border=1 cellspacing=0 cellpadding=2>
170  <tr><td valign=\"top\"><b>offset</b></td>
171      <td valign=\"top\">Value which is added to the signal</td>
172  </tr>
173  <tr><td valign=\"top\"><b>startTime</b></td>
174      <td valign=\"top\">Start time of signal. For time &lt; startTime,
175                the output y is set to offset.</td>
176  </tr>
177</table>
178
179<p>
180The <b>offset</b> parameter is especially useful in order to shift
181the corresponding source, such that at initial time the system
182is stationary. To determine the corresponding value of offset,
183usually requires a trimming calculation.
184</p>
185</HTML>
186", revisions="<html>
187<ul>
188<li><i>October 21, 2002</i>
189       by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>
190       and <a href=\"http://www.robotic.dlr.de/Christian.Schweiger/\">Christian Schweiger</a>:<br>
191       Integer sources added. Step, TimeTable and BooleanStep slightly changed.</li>
192<li><i>Nov. 8, 1999</i>
193       by <a href=\"mailto:clauss@eas.iis.fhg.de\">Christoph Clau&szlig;</a>,
194       <A HREF=\"mailto:schneider@eas.iis.fhg.de\">schneider@eas.iis.fhg.de</A>,
195       <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
196       New sources: Exponentials, TimeTable. Trapezoid slightly enhanced
197       (nperiod=-1 is an infinite number of periods).</li>
198<li><i>Oct. 31, 1999</i>
199       by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
200       <a href=\"mailto:clauss@eas.iis.fhg.de\">Christoph Clau&szlig;</a>,
201       <A HREF=\"mailto:schneider@eas.iis.fhg.de\">schneider@eas.iis.fhg.de</A>,
202       All sources vectorized. New sources: ExpSine, Trapezoid,
203       BooleanConstant, BooleanStep, BooleanPulse, SampleTrigger.
204       Improved documentation, especially detailed description of
205       signals in diagram layer.</li>
206<li><i>June 29, 1999</i>
207       by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
208       Realized a first version, based on an existing Dymola library
209       of Dieter Moormann and Hilding Elmqvist.</li>
210</ul>
211</html>"));
212      block Clock "Generate actual time signal " 
213        parameter Modelica.SIunits.Time offset=0 "Offset of output signal";
214        parameter Modelica.SIunits.Time startTime=0 
215      "Output = offset for time < startTime";
216        extends Interfaces.SO;
217   
218        annotation (
219          Coordsys(
220            extent=[-100, -100; 100, 100],
221            grid=[1, 1],
222            component=[20, 20]),
223          Window(
224            x=0.26,
225            y=0,
226            width=0.36,
227            height=0.52),
228          Icon(
229            Ellipse(extent=[-80, 80; 80, -80], style(color=9)),
230            Line(points=[0, 80; 0, 60], style(color=9)),
231            Line(points=[80, 0; 60, 0], style(color=9)),
232            Line(points=[0, -80; 0, -60], style(color=9)),
233            Line(points=[-80, 0; -60, 0], style(color=9)),
234            Line(points=[37, 70; 26, 50], style(color=9)),
235            Line(points=[70, 38; 49, 26], style(color=9)),
236            Line(points=[71, -37; 52, -27], style(color=9)),
237            Line(points=[39, -70; 29, -51], style(color=9)),
238            Line(points=[-39, -70; -29, -52], style(color=9)),
239            Line(points=[-71, -37; -50, -26], style(color=9)),
240            Line(points=[-71, 37; -54, 28], style(color=9)),
241            Line(points=[-38, 70; -28, 51], style(color=9)),
242            Line(points=[0, 0; -50, 50], style(color=0, thickness=2)),
243            Line(points=[0, 0; 40, 0], style(color=0, thickness=2)),
244            Text(
245              extent=[-150, -150; 150, -110],
246              string="startTime=%startTime",
247              style(color=0))),
248          Diagram(
249            Polygon(points=[-80,90; -85,68; -75,68; -80,90], style(
250            color=10,
251            rgbcolor={95,95,95},
252            fillColor=10,
253            rgbfillColor={95,95,95})),
254            Line(points=[-80, 68; -80, -80], style(
255            color=10,
256            rgbcolor={95,95,95},
257            fillColor=10,
258            rgbfillColor={95,95,95})),
259            Line(points=[-80, 0; -10, 0; 60, 70], style(
260            color=3,
261            rgbcolor={0,0,255},
262            thickness=2)),
263            Line(points=[-90, -70; 82, -70], style(
264            color=10,
265            rgbcolor={95,95,95},
266            fillColor=10,
267            rgbfillColor={95,95,95})),
268            Polygon(points=[90,-70; 68,-64; 68,-76; 90,-70], style(
269            color=10,
270            rgbcolor={95,95,95},
271            fillColor=10,
272            rgbfillColor={95,95,95})),
273            Polygon(points=[-34, 0; -37, -13; -30, -13; -34, 0], style(
274            color=10,
275            rgbcolor={95,95,95},
276            fillColor=10,
277            rgbfillColor={95,95,95})),
278            Line(points=[-34, -13; -34, -70], style(
279            color=10,
280            rgbcolor={95,95,95},
281            fillColor=10,
282            rgbfillColor={95,95,95})),
283            Polygon(points=[-34, -69; -37, -56; -31, -56; -34, -69; -34, -69], style(
284            color=10,
285            rgbcolor={95,95,95},
286            fillColor=10,
287            rgbfillColor={95,95,95})),
288            Text(
289              extent=[-77,-28; -35,-40],
290              string="offset",
291          style(
292            color=0,
293            rgbcolor={0,0,0},
294            fillColor=10,
295            rgbfillColor={95,95,95})),
296            Text(
297              extent=[-30,-73; 18,-86],
298              string="startTime",
299          style(
300            color=0,
301            rgbcolor={0,0,0},
302            fillColor=10,
303            rgbfillColor={95,95,95})),
304            Text(
305              extent=[-81,91; -40,71],
306              string="y",
307          style(
308            color=0,
309            rgbcolor={0,0,0},
310            fillColor=10,
311            rgbfillColor={95,95,95})),
312            Text(
313              extent=[63,-79; 94,-89],
314              string="time",
315          style(
316            color=0,
317            rgbcolor={0,0,0},
318            fillColor=10,
319            rgbfillColor={95,95,95})),
320            Line(points=[-10, 0; -10, -70], style(
321            color=10,
322            rgbcolor={95,95,95},
323            fillColor=10,
324            rgbfillColor={95,95,95})),
325            Line(points=[-10, 0; 50, 0], style(
326            color=10,
327            rgbcolor={95,95,95},
328            fillColor=10,
329            rgbfillColor={95,95,95})),
330            Line(points=[50, 0; 50, 60], style(
331            color=10,
332            rgbcolor={95,95,95},
333            fillColor=10,
334            rgbfillColor={95,95,95})),
335            Text(
336              extent=[35, 33; 50, 23],
337              string="1",
338          style(
339            color=0,
340            rgbcolor={0,0,0},
341            fillColor=10,
342            rgbfillColor={95,95,95})),
343            Text(
344              extent=[14, 13; 32, 1],
345              string="1",
346          style(
347            color=0,
348            rgbcolor={0,0,0},
349            fillColor=10,
350            rgbfillColor={95,95,95}))),
351      Documentation(info="<html>
352<p>
353The Real output y is a clock signal:
354</p>
355
356<p>
357<img src=\"../Images/Blocks/Sources/Clock.png\">
358</p>
359</html>"));
360   
361      equation 
362        y = offset + (if time < startTime then 0 else time - startTime);
363      end Clock;
364 
365      block Constant "Generate constant signal of type Real" 
366        parameter Real k=1 "Constant output value";
367        extends Interfaces.SO;
368   
369        annotation (defaultComponentName="const",
370          Coordsys(
371            extent=[-100, -100; 100, 100],
372            grid=[2, 2],
373            component=[20, 20]),
374          Window(
375            x=0.29,
376            y=0.19,
377            width=0.6,
378            height=0.6),
379          Icon(
380            Line(points=[-80, 68; -80, -80], style(color=8)),
381            Polygon(points=[-80, 90; -88, 68; -72, 68; -80, 90], style(color=8,
382                   fillColor=8)),
383            Line(points=[-90, -70; 82, -70], style(color=8)),
384            Polygon(points=[90, -70; 68, -62; 68, -78; 90, -70], style(color=8,
385                   fillColor=8)),
386            Line(points=[-80, 0; 80, 0], style(color=0)),
387            Text(
388              extent=[-150, -150; 150, -110],
389              string="k=%k",
390              style(color=0))),
391          Diagram(
392            Polygon(points=[-80,90; -86,68; -74,68; -80,90], style(
393            color=10,
394            rgbcolor={95,95,95},
395            fillColor=10,
396            rgbfillColor={95,95,95})),
397            Line(points=[-80, 68; -80, -80], style(
398            color=10,
399            rgbcolor={95,95,95},
400            fillColor=10,
401            rgbfillColor={95,95,95})),
402            Line(points=[-80, 0; 80, 0], style(
403            color=3,
404            rgbcolor={0,0,255},
405            thickness=2)),
406            Line(points=[-90, -70; 82, -70], style(
407            color=10,
408            rgbcolor={95,95,95},
409            fillColor=10,
410            rgbfillColor={95,95,95})),
411            Polygon(points=[90,-70; 68,-64; 68,-76; 90,-70], style(
412            color=10,
413            rgbcolor={95,95,95},
414            fillColor=10,
415            rgbfillColor={95,95,95})),
416            Text(
417              extent=[-83,92; -30,74],
418              string="y",
419          style(
420            color=0,
421            rgbcolor={0,0,0},
422            fillColor=10,
423            rgbfillColor={95,95,95})),
424            Text(
425              extent=[70, -80; 94, -100],
426              string="time",
427          style(
428            color=0,
429            rgbcolor={0,0,0},
430            fillColor=10,
431            rgbfillColor={95,95,95})),
432            Text(
433              extent=[-101, 8; -81, -12],
434              string="k",
435          style(
436            color=0,
437            rgbcolor={0,0,0},
438            fillColor=10,
439            rgbfillColor={95,95,95}))),
440      Documentation(info="<html>
441<p>
442The Real output y is a constant signal:
443</p>
444
445<p>
446<img src=\"../Images/Blocks/Sources/Constant.png\">
447</p>
448</html>"));
449      equation 
450        y = k;
451      end Constant;
452 
453      block Step "Generate step signal of type Real" 
454        parameter Real height=1 "Height of step";
455        extends Interfaces.SignalSource;
456        annotation (
457          Coordsys(
458            extent=[-100, -100; 100, 100],
459            grid=[1, 1],
460            component=[20, 20]),
461          Window(
462            x=0.38,
463            y=0.11,
464            width=0.6,
465            height=0.6),
466          Icon(
467            Line(points=[-80, 68; -80, -80], style(color=8)),
468            Polygon(points=[-80, 90; -88, 68; -72, 68; -80, 90], style(color=8,
469                   fillColor=8)),
470            Line(points=[-90, -70; 82, -70], style(color=8)),
471            Polygon(points=[90, -70; 68, -62; 68, -78; 90, -70], style(color=8,
472                   fillColor=8)),
473            Line(points=[-80, -70; 0, -70; 0, 50; 80, 50], style(color=0)),
474            Text(
475              extent=[-150, -150; 150, -110],
476              string="startTime=%startTime",
477              style(color=0))),
478          Diagram(
479            Polygon(points=[-80,90; -86,68; -74,68; -80,90], style(
480            color=10,
481            rgbcolor={95,95,95},
482            fillColor=10,
483            rgbfillColor={95,95,95})),
484            Line(points=[-80, 68; -80, -80], style(
485            color=10,
486            rgbcolor={95,95,95},
487            fillColor=10,
488            rgbfillColor={95,95,95})),
489            Line(points=[-80, -18; 0, -18; 0, 50; 80, 50], style(
490            color=3,
491            rgbcolor={0,0,255},
492            thickness=2)),
493            Line(points=[-90, -70; 82, -70], style(
494            color=10,
495            rgbcolor={95,95,95},
496            fillColor=10,
497            rgbfillColor={95,95,95})),
498            Polygon(points=[90,-70; 68,-64; 68,-76; 90,-70], style(
499            color=10,
500            rgbcolor={95,95,95},
501            fillColor=10,
502            rgbfillColor={95,95,95})),
503            Text(
504              extent=[70, -80; 94, -100],
505              string="time",
506          style(
507            color=0,
508            rgbcolor={0,0,0},
509            fillColor=10,
510            rgbfillColor={95,95,95})),
511            Text(
512              extent=[-21, -72; 25, -90],
513              string="startTime",
514          style(
515            color=0,
516            rgbcolor={0,0,0},
517            fillColor=10,
518            rgbfillColor={95,95,95})),
519            Line(points=[0, -17; 0, -71], style(
520            color=10,
521            rgbcolor={95,95,95},
522            fillColor=10,
523            rgbfillColor={95,95,95})),
524            Text(
525              extent=[-68, -36; -22, -54],
526              string="offset",
527          style(
528            color=0,
529            rgbcolor={0,0,0},
530            fillColor=10,
531            rgbfillColor={95,95,95})),
532            Line(points=[-13, 50; -13, -17], style(
533            color=10,
534            rgbcolor={95,95,95},
535            fillColor=10,
536            rgbfillColor={95,95,95})),
537            Polygon(points=[2, 50; -19, 50; 2, 50], style(
538            color=10,
539            rgbcolor={95,95,95},
540            fillColor=10,
541            rgbfillColor={95,95,95})),
542            Polygon(points=[-13, -17; -16, -4; -10, -4; -13, -17; -13, -17], style(
543            color=10,
544            rgbcolor={95,95,95},
545            fillColor=10,
546            rgbfillColor={95,95,95})),
547            Polygon(points=[-13, 50; -16, 37; -9,