-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathInverseModel.mo
2035 lines (1901 loc) · 76.9 KB
/
InverseModel.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package Modelica "Modelica Standard Library (Version 3.1)"
extends Modelica.Icons.Library;
annotation (
preferredView="info",
version="3.1",
versionBuild=4,
versionDate="2009-08-14",
dateModified = "2009-08-28 08:30:00Z",
revisionId="$Id: package.mo,v 1.1.1.2 2009/09/07 15:17:14 Dag Exp $",
conversion(
noneFromVersion="3.0.1",
noneFromVersion="3.0",
from(version="2.1", script="Scripts/ConvertModelica_from_2.2.2_to_3.0.mos"),
from(version="2.2", script="Scripts/ConvertModelica_from_2.2.2_to_3.0.mos"),
from(version="2.2.1", script="Scripts/ConvertModelica_from_2.2.2_to_3.0.mos"),
from(version="2.2.2", script="Scripts/ConvertModelica_from_2.2.2_to_3.0.mos")),
__Dymola_classOrder={"UsersGuide","Blocks","StateGraph","Electrical","Magnetic","Mechanics","Fluid","Media","Thermal",
"Math","Utilities","Constants", "Icons", "SIunits"},
Settings(NewStateSelection=true),
Documentation(info="<HTML>
<p>
Package <b>Modelica</b> is a <b>standardized</b> and <b>free</b> package
that is developed together with the Modelica language from the
Modelica Association, see
<a href=\"http://www.Modelica.org\">http://www.Modelica.org</a>.
It is also called <b>Modelica Standard Library</b>.
It provides model components in many domains that are based on
standardized interface definitions. Some typical examples are shown
in the next figure:
</p>
<p>
<img src=\"../Images/UsersGuide/ModelicaLibraries.png\">
</p>
<p>
For an introduction, have especially a look at:
</p>
<ul>
<li> <a href=\"Modelica://Modelica.UsersGuide.Overview\">Overview</a>
provides an overview of the Modelica Standard Library
inside the <a href=\"Modelica://Modelica.UsersGuide\">User's Guide</a>.</li>
<li><a href=\"Modelica://Modelica.UsersGuide.ReleaseNotes\">Release Notes</a>
summarizes the changes of new versions of this package.</li>
<li> <a href=\"Modelica://Modelica.UsersGuide.Contact\">Contact</a>
lists the contributors of the Modelica Standard Library.</li>
<li> <a href=\"../help/Documentation/ModelicaStandardLibrary.pdf\">ModelicaStandardLibrary.pdf</a>
is the complete documentation of the library in pdf format.
<li> The <b>Examples</b> packages in the various libraries, demonstrate
how to use the components of the corresponding sublibrary.</li>
</ul>
<p>
This version of the Modelica Standard Library consists of
</p>
<ul>
<li> <b>922</b> models and blocks, and</li>
<li> <b>615</b> functions
</ul>
<p>
that are directly usable (= number of public, non-partial classes).
</p>
<p>
<b>Licensed by the Modelica Association under the Modelica License 2</b><br>
Copyright © 1998-2009, ABB, arsenal research, T. Bödrich, DLR, Dynasim, Fraunhofer, Modelon,
TU Hamburg-Harburg, Politecnico di Milano.
</p>
<p>
<i>This Modelica package is <u>free</u> software and
the use is completely at <u>your own risk</u>;
it can be redistributed and/or modified under the terms of the
Modelica license 2, see the license conditions (including the
disclaimer of warranty)
<a href=\"Modelica://Modelica.UsersGuide.ModelicaLicense2\">here</a></u>
or at
<a href=\"http://www.Modelica.org/licenses/ModelicaLicense2\">
http://www.Modelica.org/licenses/ModelicaLicense2</a>.
</p>
</HTML>
"));
package Blocks
"Library of basic input/output control blocks (continuous, discrete, logical, table blocks)"
import SI = Modelica.SIunits;
extends Modelica.Icons.Library2;
annotation (
Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,
100}}), graphics={
Rectangle(extent={{-32,-6},{16,-35}}, lineColor={0,0,0}),
Rectangle(extent={{-32,-56},{16,-85}}, lineColor={0,0,0}),
Line(points={{16,-20},{49,-20},{49,-71},{16,-71}}, color={0,0,0}),
Line(points={{-32,-72},{-64,-72},{-64,-21},{-32,-21}}, color={0,0,0}),
Polygon(
points={{16,-71},{29,-67},{29,-74},{16,-71}},
lineColor={0,0,0},
fillColor={0,0,0},
fillPattern=FillPattern.Solid),
Polygon(
points={{-32,-21},{-46,-17},{-46,-25},{-32,-21}},
lineColor={0,0,0},
fillColor={0,0,0},
fillPattern=FillPattern.Solid)}),
Documentation(info="<html>
<p>
This library contains input/output blocks to build up block diagrams.
</p>
<dl>
<dt><b>Main Author:</b>
<dd><a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a><br>
Deutsches Zentrum für Luft und Raumfahrt e. V. (DLR)<br>
Oberpfaffenhofen<br>
Postfach 1116<br>
D-82230 Wessling<br>
email: <A HREF=\"mailto:Martin.Otter@dlr.de\">Martin.Otter@dlr.de</A><br>
</dl>
<p>
Copyright © 1998-2009, Modelica Association and DLR.
</p>
<p>
<i>This Modelica package is <b>free</b> software; it can be redistributed and/or modified
under the terms of the <b>Modelica license</b>, see the license conditions
and the accompanying <b>disclaimer</b>
<a href=\"Modelica://Modelica.UsersGuide.ModelicaLicense\">here</a>.</i>
</p>
</HTML>
", revisions="<html>
<ul>
<li><i>June 23, 2004</i>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
Introduced new block connectors and adapated all blocks to the new connectors.
Included subpackages Continuous, Discrete, Logical, Nonlinear from
package ModelicaAdditions.Blocks.
Included subpackage ModelicaAdditions.Table in Modelica.Blocks.Sources
and in the new package Modelica.Blocks.Tables.
Added new blocks to Blocks.Sources and Blocks.Logical.
</li>
<li><i>October 21, 2002</i>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>
and <a href=\"http://www.robotic.dlr.de/Christian.Schweiger/\">Christian Schweiger</a>:<br>
New subpackage Examples, additional components.
</li>
<li><i>June 20, 2000</i>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a> and
Michael Tiller:<br>
Introduced a replaceable signal type into
Blocks.Interfaces.RealInput/RealOutput:
<pre>
replaceable type SignalType = Real
</pre>
in order that the type of the signal of an input/output block
can be changed to a physical type, for example:
<pre>
Sine sin1(outPort(redeclare type SignalType=Modelica.SIunits.Torque))
</pre>
</li>
<li><i>Sept. 18, 1999</i>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
Renamed to Blocks. New subpackages Math, Nonlinear.
Additional components in subpackages Interfaces, Continuous
and Sources. </li>
<li><i>June 30, 1999</i>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
Realized a first version, based on an existing Dymola library
of Dieter Moormann and Hilding Elmqvist.</li>
</ul>
</html>"));
package Examples
"Library of examples to demonstrate the usage of package Blocks"
extends Icons.Library;
model InverseModel "Demonstrates the construction of an inverse model"
extends Modelica.Icons.Example;
Continuous.FirstOrder firstOrder1(
k=1,
T=0.3,
initType=Modelica.Blocks.Types.Init.SteadyState)
annotation (Placement(transformation(extent={{20,20},{0,40}})));
Sources.Sine sine(
freqHz=2,
offset=1,
startTime=0.2)
annotation (Placement(transformation(extent={{-80,20},{-60,40}})));
annotation (Diagram(coordinateSystem(preserveAspectRatio=true, extent={{-100,
-100},{100,100}}), graphics), Documentation(info="<html>
<p>
This example demonstrates how to construct an inverse model in Modelica
(for more details see <a href=\"http://www.modelica.org/events/Conference2005/online_proceedings/Session3/Session3c3.pdf\">Looye, Thümmel, Kurze, Otter, Bals: Nonlinear Inverse Models for Control</a>).
</p>
<p>
For a linear, single input, single output system
</p>
<pre>
y = n(s)/d(s) * u // plant model
</pre>
<p>
the inverse model is derived by simply exchanging the numerator and
the denominator polynomial:
</p>
<pre>
u = d(s)/n(s) * y // inverse plant model
</pre>
<p>
If the denominator polynomial d(s) has a higher degree as the
numerator polynomial n(s) (which is usually the case for plant models),
then the inverse model is no longer proper, i.e., it is not causal.
To avoid this, an approximate inverse model is constructed by adding
a sufficient number of poles to the denominator of the inverse model.
This can be interpreted as filtering the desired output signal y:
</p>
<pre>
u = d(s)/(n(s)*f(s)) * y // inverse plant model with filtered y
</pre>
<p>
With Modelica it is in principal possible to construct inverse models not only
for linear but also for non-linear models and in particular for every
Modelica model. The basic construction mechanism is explained at hand
of this example:
</p>
<p>
<img src=\"../Images/Blocks/InverseModelSchematic.png\">
</p>
<p>
Here the first order block \"firstOrder1\" shall be inverted. This is performed
by connecting its inputs and outputs with an instance of block
Modelica.Blocks.Math.<b>InverseBlockConstraints</b>. By this connection,
the inputs and outputs are exchanged. The goal is to compute the input of the
\"firstOrder1\" block so that its output follows a given sine signal.
For this, the sine signal \"sin\" is first filtered with a \"CriticalDamping\"
filter of order 1 and then the output of this filter is connected to the output
of the \"firstOrder1\" block (via the InverseBlockConstraints block, since
2 outputs cannot be connected directly together in a block diagram).
</p>
<p>
In order to check the inversion, the computed input of \"firstOrder1\" is used
as input in an identical block \"firstOrder2\". The output of \"firstOrder2\" should
be the given \"sine\" function. The difference is constructed with the \"feedback\"
block. Since the \"sine\" function is filtered, one cannot expect that this difference
is zero. The higher the cut-off frequency of the filter, the closer is the
agreement. A typical simulation result is shown in the next figure:
</p>
<p>
<img src=\"../Images/Blocks/InverseModel.png\">
</p>
</html>"));
Math.InverseBlockConstraints inverseBlockConstraints
annotation (Placement(transformation(extent={{-10,20},{30,40}})));
Continuous.FirstOrder firstOrder2(
k=1,
T=0.3,
initType=Modelica.Blocks.Types.Init.SteadyState)
annotation (Placement(transformation(extent={{20,-20},{0,0}})));
Math.Feedback feedback
annotation (Placement(transformation(extent={{-40,0},{-60,-20}})));
Continuous.CriticalDamping criticalDamping(n=1, f=50*sine.freqHz)
annotation (Placement(transformation(extent={{-40,20},{-20,40}})));
equation
connect(firstOrder1.y, inverseBlockConstraints.u2) annotation (Line(
points={{-1,30},{-6,30}},
color={0,0,127},
smooth=Smooth.None));
connect(inverseBlockConstraints.y2, firstOrder1.u) annotation (Line(
points={{27,30},{22,30}},
color={0,0,127},
smooth=Smooth.None));
connect(firstOrder2.y, feedback.u1) annotation (Line(
points={{-1,-10},{-42,-10}},
color={0,0,127},
smooth=Smooth.None));
connect(sine.y, criticalDamping.u) annotation (Line(
points={{-59,30},{-42,30}},
color={0,0,127},
smooth=Smooth.None));
connect(criticalDamping.y, inverseBlockConstraints.u1) annotation (Line(
points={{-19,30},{-12,30}},
color={0,0,127},
smooth=Smooth.None));
connect(sine.y, feedback.u2) annotation (Line(
points={{-59,30},{-50,30},{-50,-2}},
color={0,0,127},
smooth=Smooth.None));
connect(inverseBlockConstraints.y1, firstOrder2.u) annotation (Line(
points={{31,30},{40,30},{40,-10},{22,-10}},
color={0,0,127},
smooth=Smooth.None));
end InverseModel;
annotation (Documentation(info="<html>
<p>
This package contains example models to demonstrate the
usage of package blocks.
</p>
</HTML>
"));
end Examples;
package Continuous
"Library of continuous control blocks with internal states"
import Modelica.Blocks.Interfaces;
import Modelica.SIunits;
extends Modelica.Icons.Library;
annotation (
Documentation(info="<html>
<p>
This package contains basic <b>continuous</b> input/output blocks
described by differential equations.
</p>
<p>
All blocks of this package can be initialized in different
ways controlled by parameter <b>initType</b>. The possible
values of initType are defined in
<a href=\"Modelica://Modelica.Blocks.Types.Init\">Modelica.Blocks.Types.Init</a>:
</p>
<table border=1 cellspacing=0 cellpadding=2>
<tr><td valign=\"top\"><b>Name</b></td>
<td valign=\"top\"><b>Description</b></td></tr>
<tr><td valign=\"top\"><b>Init.NoInit</b></td>
<td valign=\"top\">no initialization (start values are used as guess values with fixed=false)</td></tr>
<tr><td valign=\"top\"><b>Init.SteadyState</b></td>
<td valign=\"top\">steady state initialization (derivatives of states are zero)</td></tr>
<tr><td valign=\"top\"><b>Init.InitialState</b></td>
<td valign=\"top\">Initialization with initial states</td></tr>
<tr><td valign=\"top\"><b>Init.InitialOutput</b></td>
<td valign=\"top\">Initialization with initial outputs (and steady state of the states if possibles)</td></tr>
</table>
<p>
For backward compatibility reasons the default of all blocks is
<b>Init.NoInit</b>, with the exception of Integrator and LimIntegrator
where the default is <b>Init.InitialState</b> (this was the initialization
defined in version 2.2 of the Modelica standard library).
</p>
<p>
In many cases, the most useful initial condition is
<b>Init.SteadyState</b> because initial transients are then no longer
present. The drawback is that in combination with a non-linear
plant, non-linear algebraic equations occur that might be
difficult to solve if appropriate guess values for the
iteration variables are not provided (i.e. start values with fixed=false).
However, it is often already useful to just initialize
the linear blocks from the Continuous blocks library in SteadyState.
This is uncritical, because only linear algebraic equations occur.
If Init.NoInit is set, then the start values for the states are
interpreted as <b>guess</b> values and are propagated to the
states with fixed=<b>false</b>.
</p>
<p>
Note, initialization with Init.SteadyState is usually difficult
for a block that contains an integrator
(Integrator, LimIntegrator, PI, PID, LimPID).
This is due to the basic equation of an integrator:
</p>
<pre>
<b>initial equation</b>
<b>der</b>(y) = 0; // Init.SteadyState
<b>equation</b>
<b>der</b>(y) = k*u;
</pre>
<p>
The steady state equation leads to the condition that the input to the
integrator is zero. If the input u is already (directly or indirectly) defined
by another initial condition, then the initialization problem is <b>singular</b>
(has none or infinitely many solutions). This situation occurs often
for mechanical systems, where, e.g., u = desiredSpeed - measuredSpeed and
since speed is both a state and a derivative, it is always defined by
Init.InitialState or Init.SteadyState initializtion.
</p>
<p>
In such a case, <b>Init.NoInit</b> has to be selected for the integrator
and an additional initial equation has to be added to the system
to which the integrator is connected. E.g., useful initial conditions
for a 1-dim. rotational inertia controlled by a PI controller are that
<b>angle</b>, <b>speed</b>, and <b>acceleration</b> of the inertia are zero.
</p>
</html>
"));
block FirstOrder "First order transfer function block (= 1 pole)"
import Modelica.Blocks.Types.Init;
parameter Real k=1 "Gain";
parameter SIunits.Time T(start=1) "Time Constant";
parameter Modelica.Blocks.Types.Init initType=Modelica.Blocks.Types.Init.NoInit
"Type of initialization (1: no init, 2: steady state, 3/4: initial output)"
annotation(Evaluate=true,
Dialog(group="Initialization"));
parameter Real y_start=0 "Initial or guess value of output (= state)"
annotation (Dialog(group="Initialization"));
extends Interfaces.SISO(y(start=y_start));
annotation (
Documentation(info="<HTML>
<p>
This blocks defines the transfer function between the input u
and the output y (element-wise) as <i>first order</i> system:
</p>
<pre>
k
y = ------------ * u
T * s + 1
</pre>
<p>
If you would like to be able to change easily between different
transfer functions (FirstOrder, SecondOrder, ... ) by changing
parameters, use the general block <b>TransferFunction</b> instead
and model a first order SISO system with parameters<br>
b = {k}, a = {T, 1}.
</p>
<pre>
Example:
parameter: k = 0.3, T = 0.4
results in:
0.3
y = ----------- * u
0.4 s + 1.0
</pre>
</HTML>
"), Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={
Line(points={{-80,78},{-80,-90}}, color={192,192,192}),
Polygon(
points={{-80,90},{-88,68},{-72,68},{-80,88},{-80,90}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-90,-80},{82,-80}}, color={192,192,192}),
Polygon(
points={{90,-80},{68,-72},{68,-88},{90,-80}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-80,-80},{-70,-45.11},{-60,-19.58},{-50,-0.9087},{-40,
12.75},{-30,22.75},{-20,30.06},{-10,35.41},{0,39.33},{10,
42.19},{20,44.29},{30,45.82},{40,46.94},{50,47.76},{60,48.36},
{70,48.8},{80,49.12}}, color={0,0,127}),
Text(
extent={{0,0},{60,-60}},
lineColor={192,192,192},
textString="PT1"),
Text(
extent={{-150,-150},{150,-110}},
lineColor={0,0,0},
textString="T=%T")}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={
Text(
extent={{-48,52},{50,8}},
lineColor={0,0,0},
textString="k"),
Text(
extent={{-54,-6},{56,-56}},
lineColor={0,0,0},
textString="T s + 1"),
Line(points={{-50,0},{50,0}}, color={0,0,0}),
Rectangle(extent={{-60,60},{60,-60}}, lineColor={0,0,255}),
Line(points={{-100,0},{-60,0}}, color={0,0,255}),
Line(points={{60,0},{100,0}}, color={0,0,255})}));
initial equation
if initType == Init.SteadyState then
der(y) = 0;
elseif initType == Init.InitialState or initType == Init.InitialOutput then
y = y_start;
end if;
equation
der(y) = (k*u - y)/T;
end FirstOrder;
block CriticalDamping
"Output the input signal filtered with an n-th order filter with critical damping"
import Modelica.Blocks.Types.Init;
extends Modelica.Blocks.Interfaces.SISO;
parameter Integer n=2 "Order of filter";
parameter Modelica.SIunits.Frequency f(start=1) "Cut-off frequency";
parameter Boolean normalized = true
"= true, if amplitude at f_cut is 3 dB, otherwise unmodified filter";
parameter Modelica.Blocks.Types.Init initType=Modelica.Blocks.Types.Init.NoInit
"Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)"
annotation(Evaluate=true,
Dialog(group="Initialization"));
parameter Real x_start[n]=zeros(n) "Initial or guess values of states"
annotation (Dialog(group="Initialization"));
parameter Real y_start=0.0
"Initial value of output (remaining states are in steady state)"
annotation(Dialog(enable=initType == Init.InitialOutput, group=
"Initialization"));
output Real x[n](start=x_start) "Filter states";
annotation (
Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{
100,100}}), graphics={
Line(points={{-80.6897,77.6256},{-80.6897,-90.3744}}, color={192,
192,192}),
Polygon(
points={{-79.7044,90.6305},{-87.7044,68.6305},{-71.7044,68.6305},
{-79.7044,88.6305},{-79.7044,90.6305}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-90,-80},{82,-80}}, color={192,192,192}),
Polygon(
points={{90,-80},{68,-72},{68,-88},{90,-80}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Text(
extent={{0,0},{60,-60}},
lineColor={192,192,192},
textString="PTn"),
Line(points={{-80.7599,-80.5082},{-70.7599,-74.5082},{-56,-60},{-48,
-42},{-42,-18},{-36,4},{-26,20},{-10.7599,34.9018},{-0.759907,
38.8218},{9.24009,41.6818},{19.2401,43.7818},{29.2401,45.3118},
{39.2401,46.4318},{49.2401,47.2518},{59.2401,47.8518},{
69.2401,48.2918},{79.2401,48.6118}}, color={0,0,127}),
Text(
extent={{-70,94},{26,48}},
lineColor={192,192,192},
textString="%n"),
Text(
extent={{8,-106},{8,-146}},
lineColor={0,0,0},
textString="f=%f")}),
Diagram(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{
100,100}}), graphics={
Line(points={{40,0},{-40,0}}, color={0,0,0}),
Text(
extent={{-55,55},{55,5}},
lineColor={0,0,0},
textString="1"),
Rectangle(extent={{-60,60},{60,-60}}, lineColor={0,0,255}),
Line(points={{-100,0},{-60,0}}, color={0,0,255}),
Line(points={{60,0},{100,0}}, color={0,0,255}),
Text(
extent={{-54,-6},{44,-56}},
lineColor={0,0,0},
textString="(s/w + 1)"),
Text(
extent={{38,-10},{58,-30}},
lineColor={0,0,0},
textString="n")}),
Documentation(info="<html>
<p>This block defines the transfer function between the
input u and the output y
as an n-th order filter with <i>critical damping</i>
characteristics and cut-off frequency f. It is
implemented as a series of first order filters.
This filter type is especially useful to filter the input of an
inverse model, since the filter does not introduce any transients.
</p>
<p>
If parameter <b>normalized</b> = <b>true</b> (default), the filter
is normalized such that the amplitude of the filter transfer function
at the cut-off frequency f is 1/sqrt(2) (= 3 dB). Otherwise, the filter
is not normalized, i.e., it is unmodified. A normalized filter is usually
much better for applications, since filters of different orders are
\"comparable\", whereas non-normalized filters usually require to adapt the
cut-off frequency, when the order of the filter is changed.
Figures of the filter step responses are shown below.
Note, in versions before version 3.0 of the Modelica Standard library,
the CriticalDamping filter was provided only in non-normalzed form.
</p>
<p>If transients at the simulation start shall be avoided, the filter
should be initialized in steady state (e.g., using option
initType=Modelica.Blocks.Types.Init.SteadyState).
</p>
<p>
The critical damping filter is defined as
</p>
<pre>
α = <b>if</b> normalized <b>then</b> <b>sqrt</b>(2^(1/n) - 1) <b>else</b> 1 // frequency correction factor
ω = 2*π*f/α
1
y = ------------- * u
(s/w + 1)^n
</pre>
<p>
<img src=\"../Images/Blocks/CriticalDampingNormalized.png\">
</p>
<p>
<img src=\"../Images/Blocks/CriticalDampingNonNormalized.png\">
</p>
</html>
"));
protected
parameter Real alpha=if normalized then sqrt(2^(1/n) - 1) else 1.0
"Frequency correction factor for normalized filter";
parameter Real w=2*Modelica.Constants.pi*f/alpha;
initial equation
if initType == Init.SteadyState then
der(x) = zeros(n);
elseif initType == Init.InitialState then
x = x_start;
elseif initType == Init.InitialOutput then
y = y_start;
der(x[1:n-1]) = zeros(n-1);
end if;
equation
der(x[1]) = (u - x[1])*w;
for i in 2:n loop
der(x[i]) = (x[i - 1] - x[i])*w;
end for;
y = x[n];
end CriticalDamping;
end Continuous;
package Interfaces
"Library of connectors and partial models for input/output blocks"
import Modelica.SIunits;
extends Modelica.Icons.Library;
annotation (
Documentation(info="<HTML>
<p>
This package contains interface definitions for
<b>continuous</b> input/output blocks with Real,
Integer and Boolean signals. Furthermore, it contains
partial models for continuous and discrete blocks.
</p>
</HTML>
", revisions="<html>
<ul>
<li><i>Oct. 21, 2002</i>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>
and <a href=\"http://www.robotic.dlr.de/Christian.Schweiger/\">Christian Schweiger</a>:<br>
Added several new interfaces. <a href=\"../Documentation/ChangeNotes1.5.html\">Detailed description</a> available.
<li><i>Oct. 24, 1999</i>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
RealInputSignal renamed to RealInput. RealOutputSignal renamed to
output RealOutput. GraphBlock renamed to BlockIcon. SISOreal renamed to
SISO. SOreal renamed to SO. I2SOreal renamed to M2SO.
SignalGenerator renamed to SignalSource. Introduced the following
new models: MIMO, MIMOs, SVcontrol, MVcontrol, DiscreteBlockIcon,
DiscreteBlock, DiscreteSISO, DiscreteMIMO, DiscreteMIMOs,
BooleanBlockIcon, BooleanSISO, BooleanSignalSource, MI2BooleanMOs.</li>
<li><i>June 30, 1999</i>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
Realized a first version, based on an existing Dymola library
of Dieter Moormann and Hilding Elmqvist.</li>
</ul>
</html>
"));
connector RealInput = input Real "'input Real' as connector"
annotation (defaultComponentName="u",
Icon(graphics={Polygon(
points={{-100,100},{100,0},{-100,-100},{-100,100}},
lineColor={0,0,127},
fillColor={0,0,127},
fillPattern=FillPattern.Solid)},
coordinateSystem(extent={{-100,-100},{100,100}}, preserveAspectRatio=true, initialScale=0.2)),
Diagram(coordinateSystem(
preserveAspectRatio=true, initialScale=0.2,
extent={{-100,-100},{100,100}},
grid={1,1}), graphics={Polygon(
points={{0,50},{100,0},{0,-50},{0,50}},
lineColor={0,0,127},
fillColor={0,0,127},
fillPattern=FillPattern.Solid), Text(
extent={{-10,85},{-10,60}},
lineColor={0,0,127},
textString="%name")}),
Documentation(info="<html>
<p>
Connector with one input signal of type Real.
</p>
</html>"));
connector RealOutput = output Real "'output Real' as connector"
annotation (defaultComponentName="y",
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={1,1}), graphics={Polygon(
points={{-100,100},{100,0},{-100,-100},{-100,100}},
lineColor={0,0,127},
fillColor={255,255,255},
fillPattern=FillPattern.Solid)}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={1,1}), graphics={Polygon(
points={{-100,50},{0,0},{-100,-50},{-100,50}},
lineColor={0,0,127},
fillColor={255,255,255},
fillPattern=FillPattern.Solid), Text(
extent={{30,110},{30,60}},
lineColor={0,0,127},
textString="%name")}),
Documentation(info="<html>
<p>
Connector with one output signal of type Real.
</p>
</html>"));
partial block BlockIcon "Basic graphical layout of input/output block"
annotation (
Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},
{100,100}}), graphics={Rectangle(
extent={{-100,-100},{100,100}},
lineColor={0,0,127},
fillColor={255,255,255},
fillPattern=FillPattern.Solid), Text(
extent={{-150,150},{150,110}},
textString="%name",
lineColor={0,0,255})}),
Documentation(info="<html>
<p>
Block that has only the basic icon for an input/output
block (no declarations, no equations). Most blocks
of package Modelica.Blocks inherit directly or indirectly
from this block.
</p>
</html>"));
end BlockIcon;
partial block SO "Single Output continuous control block"
extends BlockIcon;
RealOutput y "Connector of Real output signal"
annotation (Placement(transformation(extent={{100,-10},{120,10}},
rotation=0)));
annotation (
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics),
Documentation(info="<html>
<p>
Block has one continuous Real output signal.
</p>
</html>"));
end SO;
partial block SISO
"Single Input Single Output continuous control block"
extends BlockIcon;
RealInput u "Connector of Real input signal"
annotation (Placement(transformation(extent={{-140,-20},{-100,20}},
rotation=0)));
RealOutput y "Connector of Real output signal"
annotation (Placement(transformation(extent={{100,-10},{120,10}},
rotation=0)));
annotation (
Documentation(info="<html>
<p>
Block has one continuous Real input and one continuous Real output signal.
</p>
</html>"));
end SISO;
end Interfaces;
package Math "Library of mathematical functions as input/output blocks"
import Modelica.SIunits;
import Modelica.Blocks.Interfaces;
extends Modelica.Icons.Library;
annotation (
Documentation(info="
<HTML>
<p>
This package contains basic <b>mathematical operations</b>,
such as summation and multiplication, and basic <b>mathematical
functions</b>, such as <b>sqrt</b> and <b>sin</b>, as
input/output blocks. All blocks of this library can be either
connected with continuous blocks or with sampled-data blocks.
</p>
</HTML>
", revisions="<html>
<ul>
<li><i>October 21, 2002</i>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>
and <a href=\"http://www.robotic.dlr.de/Christian.Schweiger/\">Christian Schweiger</a>:<br>
New blocks added: RealToInteger, IntegerToReal, Max, Min, Edge, BooleanChange, IntegerChange.</li>
<li><i>August 7, 1999</i>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
Realized (partly based on an existing Dymola library
of Dieter Moormann and Hilding Elmqvist).
</li>
</ul>
</html>"));
block InverseBlockConstraints
"Construct inverse model by requiring that two inputs and two outputs are identical (replaces the previously, unbalanced, TwoInputs and TwoOutputs blocks)"
Modelica.Blocks.Interfaces.RealInput u1 "Input signal 1 (u1 = u2)"
annotation (Placement(transformation(extent={{-240,
-20},{-200,20}}, rotation=0), iconTransformation(extent={{-240,-20},
{-200,20}})));
Modelica.Blocks.Interfaces.RealInput u2 "Input signal 2 (u1 = u2)"
annotation (Placement(transformation(extent={{-140,
-20},{-180,20}}, rotation=0), iconTransformation(extent={{-140,-20},
{-180,20}})));
Modelica.Blocks.Interfaces.RealOutput y1 "Output signal 1 (y1 = y2)"
annotation (Placement(transformation(extent={{200,-10},
{220,10}}, rotation=0), iconTransformation(extent={{200,-10},{
220,10}})));
Modelica.Blocks.Interfaces.RealOutput y2 "Output signal 2 (y2 = y2)"
annotation (Placement(transformation(extent={{10,-10},
{-10,10}}, rotation=0,
origin={170,0}), iconTransformation(extent={{180,-10},{160,10}})));
annotation(__Dymola_structurallyIncomplete=true,
Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-200,-120},{
200,120}}),
graphics),
Icon(coordinateSystem(preserveAspectRatio=false, extent={{-200,-120},
{200,120}}), graphics={
Line(
points={{180,0},{200,0}},
color={0,0,127},
smooth=Smooth.None),
Line(
points={{-200,0},{-180,0}},
color={0,0,127},
smooth=Smooth.None),
Rectangle(extent={{-190,120},{190,-120}}, lineColor={135,135,135})}),
Documentation(info="<html>
<p>
Exchange input and ouput signals of a block, i.e., the previous
block inputs become block outputs and the previous block outputs become
block inputs. This block is used to construct inverse models.
Its usage is demonstrated in example:
<a href=\"Modelica://Modelica.Blocks.Examples.InverseModel\">Modelica.Blocks.Examples.InverseModel</a>.
</p>
<p>
Note, if a block shall be inverted that has several input and output blocks,
then this can be easily achieved by using a vector of InverseBlockConstraints
instances:
</p>
<pre>
InverseBlockConstraint invert[3]; // Block to be inverted has 3 input signals
</pre>
</html>"));
equation
u1 = u2;
y1 = y2;
end InverseBlockConstraints;
block Feedback
"Output difference between commanded and feedback input"
input Interfaces.RealInput u1 annotation (Placement(transformation(
extent={{-100,-20},{-60,20}}, rotation=0)));
input Interfaces.RealInput u2
annotation (Placement(transformation(
origin={0,-80},
extent={{-20,-20},{20,20}},
rotation=90)));
output Interfaces.RealOutput y annotation (Placement(transformation(
extent={{80,-10},{100,10}}, rotation=0)));
annotation (
Documentation(info="
<HTML>
<p>
This blocks computes output <b>y</b> as <i>difference</i> of the
commanded input <b>u1</b> and the feedback
input <b>u2</b>:
</p>
<pre>
<b>y</b> = <b>u1</b> - <b>u2</b>;
</pre>
<p>
Example:
</p>
<pre>
parameter: n = 2
results in the following equations:
y = u1 - u2
</pre>
</HTML>
"), Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={
Ellipse(
extent={{-20,20},{20,-20}},
lineColor={0,0,127},
fillColor={235,235,235},
fillPattern=FillPattern.Solid),
Line(points={{-60,0},{-20,0}}, color={0,0,127}),
Line(points={{20,0},{80,0}}, color={0,0,127}),
Line(points={{0,-20},{0,-60}}, color={0,0,127}),
Text(
extent={{-14,0},{82,-94}},
lineColor={0,0,0},
textString="-"),
Text(
extent={{-150,94},{150,44}},
textString="%name",
lineColor={0,0,255})}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={
Ellipse(
extent={{-20,20},{20,-20}},
pattern=LinePattern.Solid,
lineThickness=0.25,
fillColor={235,235,235},
fillPattern=FillPattern.Solid,
lineColor={0,0,255}),
Line(points={{-60,0},{-20,0}}, color={0,0,255}),
Line(points={{20,0},{80,0}}, color={0,0,255}),
Line(points={{0,-20},{0,-60}}, color={0,0,255}),
Text(
extent={{-12,10},{84,-84}},
lineColor={0,0,0},
textString="-")}));
equation
y = u1 - u2;
end Feedback;
end Math;
package Sources
"Library of signal source blocks generating Real and Boolean signals"
import Modelica.Blocks.Interfaces;
import Modelica.SIunits;
extends Modelica.Icons.Library;
annotation (
Documentation(info="<HTML>
<p>
This package contains <b>source</b> components, i.e., blocks which
have only output signals. These blocks are used as signal generators
for Real, Integer and Boolean signals.
</p>
<p>
All Real source signals (with the exception of the Constant source)
have at least the following two parameters:
</p>
<table border=1 cellspacing=0 cellpadding=2>
<tr><td valign=\"top\"><b>offset</b></td>
<td valign=\"top\">Value which is added to the signal</td>
</tr>
<tr><td valign=\"top\"><b>startTime</b></td>
<td valign=\"top\">Start time of signal. For time < startTime,
the output y is set to offset.</td>
</tr>
</table>
<p>
The <b>offset</b> parameter is especially useful in order to shift
the corresponding source, such that at initial time the system
is stationary. To determine the corresponding value of offset,
usually requires a trimming calculation.
</p>
</HTML>