-
Notifications
You must be signed in to change notification settings - Fork 299
/
Ticket5821.mo
2642 lines (2471 loc) · 208 KB
/
Ticket5821.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
// name: Ticket5821.mo
// keywords: tests Connections.branch/Connections.uniqueRoot/Connections.uniqueRootIndices
// status: correct
//
// cflags: -d=newInst
//
package Modelica_StateGraph2 "Modelica_StateGraph2 (Version 2.0.3) - Modeling of continuous-time state machines"
model Step "Step (optionally with initial step and/or activePort)"
parameter Integer nIn(min = 0) = 0 "Number of input connections" annotation(Dialog(__Dymola_connectorSizing = true), HideResult = true);
parameter Integer nOut(min = 0) = 0 "Number of output connections" annotation(Dialog(__Dymola_connectorSizing = true), HideResult = true);
parameter Boolean initialStep = false "=true, if initial step (graph starts at this step)" annotation(Evaluate = true, HideResult = true, choices(__Dymola_checkBox = true));
parameter Boolean use_activePort = false "=true, if activePort enabled" annotation(Evaluate = true, HideResult = true, choices(__Dymola_checkBox = true));
Modelica_StateGraph2.Internal.Interfaces.Step_in[nIn] inPort "Port for zero, one, or more input transitions" annotation(Placement(transformation(extent = {{-50, 85}, {50, 115}})));
Modelica_StateGraph2.Internal.Interfaces.Step_out[nOut] outPort "Port for zero, one, or more output transitions" annotation(Placement(transformation(extent = {{-50, -130}, {50, -100}})));
Modelica.Blocks.Interfaces.BooleanOutput activePort = active if use_activePort "= true if step is active, otherwise the step is not active" annotation(Placement(transformation(extent = {{100, -18}, {136, 18}})));
output Boolean active "= true if step is active, otherwise the step is not active";
protected
Boolean newActive(start = initialStep, fixed = true) "Value of active in the next iteration";
Boolean oldActive(start = initialStep, fixed = true) "Value of active when CompositeStep was aborted";
Modelica_StateGraph2.Internal.Interfaces.Node node "Handles rootID as well as suspend and resume transitions from a Modelica_StateGraph2";
Boolean inport_fire;
Boolean outport_fire;
equation
inport_fire = Blocks.BooleanFunctions.anyTrue(inPort.fire);
outport_fire = Blocks.BooleanFunctions.anyTrue(outPort.fire);
newActive = if node.resume then oldActive else inport_fire or active and not outport_fire and not node.suspend;
active = pre(newActive);
when node.suspend then
oldActive = active;
end when;
for i in 1:nOut loop
outPort[i].available = if i == 1 then active and not node.suspend else outPort[i - 1].available and not outPort[i - 1].fire and not node.suspend;
end for;
inPort.checkUnaryConnection = fill(true, nIn);
outPort.checkOneDelayedTransitionPerLoop = fill(Internal.Utilities.propagateLoopCheck(inPort.checkOneDelayedTransitionPerLoop), nOut);
for i in 1:nIn loop
Connections.branch(inPort[i].node, node);
inPort[i].node = node;
end for;
if initialStep then
Connections.uniqueRoot(node, "
The StateGraph has a wrong connection structure. Reasons:
(1) The StateGraph is initialized at two different locations (initial steps or entry ports).
(2) A transition is made wrongly out of a Parallel component.
(3) A transition is made between two branches of a Parallel component.
All these cases are not allowed.
");
node.suspend = false;
node.resume = false;
else
assert(nIn > 0, "Step is not reachable since it has no input transition");
if nIn == 0 then
node.suspend = false;
node.resume = false;
end if;
end if;
for i in 1:nOut loop
Connections.branch(node, outPort[i].node);
outPort[i].node = node;
end for;
for i in 1:size(inPort, 1) loop
if cardinality(inPort[i]) == 0 then
inPort[i].fire = true;
inPort[i].checkOneDelayedTransitionPerLoop = true;
assert(false, "
An element of the inPort connector of this step is not connected. Most likely, the Modelica tool
has a bug and does not correctly handle the connectorSizing annotation in a particular case.
You can fix this by removing all input connections to this step and by manually removing
the line 'nIn=...' in the text layer where this step is declared.
");
end if;
end for;
for i in 1:size(outPort, 1) loop
if cardinality(outPort[i]) == 0 then
outPort[i].fire = true;
assert(false, "
An element of the outPort connector of this step is not connected. Most likely, the Modelica tool
has a bug and does not correctly handle the connectorSizing annotation in a particular case.
You can fix this by removing all output connections to this step and by manually removing
the line 'nOut=...' in the text layer where this step is declared.
");
end if;
end for;
annotation(defaultComponentName = "step1", Documentation(info = "<html>
<p>
A Step is the graphical representation of a state and is said to be either
active or not active. A StateGraph2 model is comprised of one or more
steps that may or may not change their states during execution.
The input port of a Step (inPort) can only be connected to the output port
of a Transition, and the output port of a Step (outPort) can only be connected
to the input of a Transition. An arbitrary number of input and/or output
Transitions can be connected to these ports.
</p>
<p>
The state of a step is available via the output variable <b>active</b> that can
be used in action blocks (e.g. \"step.active\"). Alternatively, via parameter
\"use_activePort\" the Boolean output port \"activePort\" can be enabled.
When the step is active, activePort = <b>true</b>, otherwise it is <b>false</b>. This port can
be connected to Boolean action blocks, e.g., from
<a href=\"modelica://Modelica_StateGraph2.Blocks.MathBoolean\">Modelica_StateGraph2.Blocks.MathBoolean</a>.
</p>
<p>
Every StateGraph2 graph
must have exactly one initial step. An initial step is defined by setting parameter initialStep
at one Step or one Parallel component to true. The initial step is visualized by a
small arrow pointing to this step.
</p>
<p>
In the following table different configurations of a Step are shown:
</p>
<blockquote>
<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" width=\"600\">
<tr><th>Parameter setting</th>
<th>Icon</th>
<th>Description</th>
</tr>
<tr><td> Default step</td>
<td><img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/Elements/Step-default.png\"></td>
<td> If the step is active, the public Step variable "active" is <b>true</b>
otherwise, it is <b>false</b>. An active Step is visualized by a green
fill color in diagram animation.</td>
</tr>
<tr><td> use_activePort = <b>true</b></td>
<td><img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/Elements/Step-use_activePort.png\"></td>
<td>If the step is active, the connector "activePort" is <b>true</b>
otherwise, it is <b>false</b> (the activePort is the small, violet, triangle
at the rigth side of the Step icon). Actions may be triggered, e.g., by connecting block
<a href=\"modelica://Modelica_StateGraph2.Blocks.MathBoolean.MultiSwitch\">MultiSwitch</a>
to the activePort.</td></tr>
<tr><td> initialStep = <b>true</b></td>
<td><img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/Elements/Step-initial.png\"></td>
<td> Exactly <u>one</u> Step or Parallel component in a StateGraph2 graph
must have "initialStep = <b>true</b>". At the first model evaluation
during initialization, "active" is set to <b>true</b> for
the initial Step or the initial Parallel component, i.e.,
the respective component is activated.</td>
</tr>
</table>
</blockquote>
<p>
The inPort and the outPort connectors of a Step are "vectors of connectors".
How connections to these ports are automatically handled in a convenient way is sketched
<a href=\"modelica://Modelica_StateGraph2.UsersGuide.Tutorial.VectorsOfConnectors\">here</a>
in the tutorial.
</p>
</html>"), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.04, grid = {1, 1}), graphics = {Text(extent = {{15, 118}, {470, 193}}, textString = "%name", lineColor = {0, 0, 255}), Rectangle(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, fillColor = DynamicSelect({255, 255, 255}, if active > 0.5 then {0, 255, 0} else {255, 255, 255}), fillPattern = FillPattern.Solid, radius = 60), Line(visible = initialStep, points = {{-235, 181}, {-137, 181}, {-90, 90}}, color = {0, 0, 0}, smooth = Smooth.Bezier), Ellipse(visible = initialStep, extent = {{-255, 199}, {-219, 163}}, lineColor = {0, 0, 0}, fillColor = {0, 0, 0}, fillPattern = FillPattern.Solid), Polygon(visible = initialStep, points = {{-95, 140}, {-90, 90}, {-126, 124}, {-95, 140}}, lineColor = {0, 0, 0}, smooth = Smooth.None, fillColor = {0, 0, 0}, fillPattern = FillPattern.Solid)}), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.04, grid = {1, 1})));
end Step;
model Transition "Transition between steps (optionally with delayed transition and/or condition input port)"
parameter Boolean use_conditionPort = false "= true, if conditionPort enabled" annotation(Evaluate = true, HideResult = true, choices(__Dymola_checkBox = true));
input Boolean condition = true "Fire condition (time varying Boolean expression)" annotation(Dialog(enable = not use_conditionPort));
parameter Boolean delayedTransition = false "= true, if transition fires after waitTime" annotation(Evaluate = true, HideResult = true, choices(__Dymola_checkBox = true));
parameter Modelica.SIunits.Time waitTime = 0 "Wait time before transition fires (> 0 required)" annotation(Dialog(enable = delayedTransition));
parameter Boolean use_firePort = false "= true, if firePort enabled" annotation(Evaluate = true, HideResult = true, choices(__Dymola_checkBox = true));
parameter Boolean loopCheck = true "= true, if one delayed transition per loop required" annotation(Evaluate = true, HideResult = true, Dialog(tab = "Advanced"), choices(__Dymola_checkBox = true));
Modelica_StateGraph2.Internal.Interfaces.Transition_in inPort "Input port of transition (exactly one connection to this port is required)" annotation(Placement(transformation(extent = {{-17, 83}, {17, 117}})));
Modelica_StateGraph2.Internal.Interfaces.Transition_out outPort "Output port of transition (exactly one connection from this port is required)" annotation(Placement(transformation(extent = {{-25, -150}, {25, -100}})));
Modelica.Blocks.Interfaces.BooleanInput conditionPort if use_conditionPort "Fire condition as Boolean input." annotation(Placement(transformation(extent = {{-150, -25}, {-100, 25}})));
Modelica.Blocks.Interfaces.BooleanOutput firePort = fire if use_firePort "= true, if transition fires" annotation(Placement(transformation(extent = {{90, -15}, {120, 15}})));
output Boolean fire "= true, if transition fires";
output Boolean enableFire "= true, if firing condition is true";
protected
constant Modelica.SIunits.Time minimumWaitTime = 100 * Modelica.Constants.eps;
Modelica.SIunits.Time t_start "Time instant at which the transition would fire, if waitTime would be zero";
Modelica.Blocks.Interfaces.BooleanInput localCondition;
initial equation
pre(enableFire) = false;
if delayedTransition then
pre(t_start) = 0;
end if;
equation
connect(conditionPort, localCondition);
if not use_conditionPort then
localCondition = condition;
end if;
enableFire = localCondition and inPort.available;
if delayedTransition then
when enableFire then
t_start = time;
end when;
fire = enableFire and time >= t_start + waitTime;
outPort.checkOneDelayedTransitionPerLoop = true;
else
t_start = 0;
fire = enableFire;
if loopCheck then
outPort.checkOneDelayedTransitionPerLoop = inPort.checkOneDelayedTransitionPerLoop;
else
outPort.checkOneDelayedTransitionPerLoop = true;
end if;
end if;
inPort.fire = fire;
outPort.fire = fire;
Connections.branch(inPort.node, outPort.node);
outPort.node = inPort.node;
assert(not delayedTransition or delayedTransition and waitTime > minimumWaitTime, "Either set delayTransition = false, or set waitTime (= " + String(waitTime) + ") > " + String(minimumWaitTime));
annotation(defaultComponentName = "T1", Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, initialScale = 0.04, preserveAspectRatio = true, grid = {1, 1}), graphics = {Text(visible = delayedTransition, extent = {{-200, 10}, {200, -10}}, lineColor = {255, 0, 0}, textString = "%waitTime", origin = {210, -70}, rotation = 0), Line(visible = delayedTransition, points = {{0, -12.5}, {0, -30}}, color = {255, 0, 0}), Line(visible = delayedTransition, points = {{0, -86}, {0, -100}}, color = {255, 0, 0}), Line(visible = delayedTransition, points = {{0, -47}, {0, -63}}, color = {255, 0, 0}), Line(visible = not delayedTransition, points = {{0, 0}, {0, -100}}, color = {0, 0, 0}), Text(extent = {{-150, -15}, {150, 15}}, textString = "%name", lineColor = {0, 0, 255}, origin = {160, 75}, rotation = 0), Rectangle(extent = {{-100, -15}, {100, 15}}, lineColor = {0, 0, 0}, fillColor = {0, 0, 0}, fillPattern = FillPattern.Solid, radius = 10), Line(points = {{0, 90}, {0, 12}}, color = {0, 0, 0}), Text(visible = not use_conditionPort, extent = {{-300, -15}, {300, 15}}, lineColor = DynamicSelect({128, 128, 128}, if condition > 0.5 then {0, 255, 0} else {128, 128, 128}), textString = "%condition", origin = {-155, -3}, rotation = 90), Text(visible = not loopCheck, extent = {{10, -60}, {400, -80}}, lineColor = {255, 0, 0}, fillColor = {170, 255, 213}, fillPattern = FillPattern.Solid, textString = "no check"), Line(visible = not loopCheck, points = {{0, -15}, {0, -100}}, color = {255, 0, 0}, smooth = Smooth.None)}), Documentation(info = "<html>
<p>
<img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/Elements/SimpleStateGraph.png\" align=\"right\">
To define a possible change of states, a Transition is connected to the output of the preceding Step and to the input of the succeeding Step, see figure to the right, where Transition t1 defines the transition from Step s1 to Step s2. Note: A Transition has exactly one preceding and one succeeding Step. A Transition is said to be enabled if the preceding step is active. An enabled transition is said to be fireable when the Boolean condition defined in the parameter menu of the transition is evaluated to <b>true</b>. This condition is also called <u>Transition condition</u> and is displayed in the icon of the Transition (e.g., "time > 1" is the condition of Transition t1). When parameter <u>use_conditionPort</u> is set, the Transition condition is alternatively defined by a Boolean signal that is connected to the enabled <u>conditionPort</u>.
</p>
<p>
A fireable transition will fire immediately. In the figure to the right, t1 fires when s1 is active and time is greater than one, i.e., s1 becomes inactive and s2 becomes active.
The firing of a transition can optionally also be delayed for a certain period of time defined by parameter "waitTime". See, e.g., t2 in the figure to right, that is delayed for one second before it may fire, given that the condition remains true and the preceding Step remains active during the entire delay time.
</p>
<p>
In the following table different configurations of a Transition are shown:
</p>
<blockquote>
<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" width=\"600\">
<tr><th>Parameter setting</th>
<th>Icon</th>
<th>Description</th></tr>
<tr><td>Default transition</td>
<td><img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/Elements/Transition-default.png\"></td>
<td>The transition fires when the preceding step is active
and the expression "condition" in the parameter menu is <b>true</b>.</td>
</tr>
<tr><td>use_conditionPort = <b>true</b></td>
<td><img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/Elements/Transition-use_conditionPort.png\"></td>
<td>The transition fires when the preceding step is active
and connector "conditionPort" is <b>true</b>.</td>
</tr>
<tr><td>delayedTransition = <b>true</b></td>
<td><img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/Elements/Transition-delayedTransition.png\"></td>
<td>The transition fires after the delay time "waitTime" (here: 1.23 s),
if the preceding step was active, and "condition = <b>true</b>"
during the entire delay time.</td>
</tr>
<tr><td>use_firePort = <b>true</b></td>
<td><img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/Elements/Transition-use_firePort.png\"></td>
<td>Connector "firePort" is <b>true</b> when the transition fires.
Actions may be triggered, e.g., by connecting block
<a href=\"modelica://Modelica_StateGraph2.Blocks.MathBoolean.MultiSwitch\">MultiSwitch</a>
to the firePort.</td>
</tr>
<tr><td>loopCheck = <b>false</b><br>
(in "Advanced" tab)</td>
<td><img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/Elements/Transition-noLoopCheck.png\"></td>
<td>It is <u>not</u> checked whether the loop in which this Transition
is used, has at least one delayed transition.
Use this option only, if you are completley sure that
infinite event looping is not possible in this loop.
Consider to use
<a href=\"modelica://Modelica_StateGraph2.LoopBreakingTransition\">LoopBreakingTransition</a>
instead!</td>
</tr>
</table>
</blockquote>
<p>
<img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/Elements/SimpleInfiniteLoop.png\" align=\"right\">
At an event instant, an iteration occurs, due to the Modelica semantics (= whenever a new event occurs, the model is re-evaluated). This means that Transitions keep firing along a connected graph, as long as the firing conditions are true. In principal, it is therefore possible that infinite event looping occurs.
A simple example of this kind is shown in the figure to the right. Here, all Transition conditions are true and therefore all Transitions would fire forever at the initial time. This is, however, no valid StateGraph2 model and will result in a translation error, since it is required that a StateGraph2 model has at least one delayed Transition per loop.
This means that one of T1, T2, or T3, must have parameter delayedTransition=<b>true</b>. Since event iteration stops at a delayed Transition, infinite event looping cannot occur. This also means that at one time instant every Transition can fire at most once and therefore the number of model evaluations at an event instant is bounded by the number of Transition components.
</p>
<p>
If you have to artifically introduce a delay time in order to fulfill the requirement above, it is recommended to use the special
<a href=\"modelica://Modelica_StateGraph2.LoopBreakingTransition\">LoopBreakingTransition</a>
that is designed for this case.
</p>
<p>
Note, it is still possible that infinite event looping occurs due to <u>model errors</u> in other parts of the model. For example, if a user introduces an equation of the form "J = <b>pre</b>(J) + 1" outside of a when-clause, event iteration does not stop.
</p>
<p>
There are rare situations, where infinite event looping cannot occur even if there is no delayed transition in a loop. When you do not want to introduce an artifical time delay in a loop in this case, you can switch off the loop check by setting parameter "loopCheck = <b>false</b>" in the "Advanced" tab of the parameter menu of one Transition in this loop.
</p>
</html>"), Diagram(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}, grid = {1, 1})));
end Transition;
package Blocks "Input/output blocks that are designed for StateGraph2 but shall be included in the Modelica Standard Library"
package BooleanFunctions "Functions with Boolean inputs (shall be included in Modelica Standard Library)"
function anyTrue "Returns true, if at least on element of the Boolean input vector is true ('or')"
extends Modelica.Icons.Function;
input Boolean[:] b;
output Boolean result;
algorithm
result := false;
for i in 1:size(b, 1) loop
result := result or b[i];
end for;
end anyTrue;
end BooleanFunctions;
annotation(Documentation(info = "<html>
<p>
An important practical aspect of state machines is the ability to assign values and expressions to variables depending on the state of the machine. In StateGraph2, a number of graphical components have been added in this package (= Modelica_StateGraph2.Blocks)
to facilitate usage in a safe and intuitive way. Since these are just input/output blocks and will also be useful in another context, it is planned to add them to the Modelica Standard Library.
Some usage examples are given
<a href=\"modelica://Modelica_StateGraph2.UsersGuide.Tutorial.Actions\">here</a>
in the tutorial, e.g., the example shown in the Figure below.
</p>
<blockquote>
<img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/Elements/MultiSwitch.png\">
</blockquote>
</html>"));
end Blocks;
package Internal "Internal utility models (should usually not be used by user)"
package Interfaces "Connectors and partial models"
record Node "Node of a state machine to communicate information between steps (for suspend/resume actions and to guarantee a valid graph)"
Boolean suspend "= true, if the composite step is terminated via a suspend port";
Boolean resume "= true, if the composite step is entered via a resume port";
function equalityConstraint
input Node node1;
input Node node2;
output Real[0] residue;
algorithm
assert(node1.suspend == node2.suspend and node1.resume == node2.resume, "Internal error");
end equalityConstraint;
end Node;
connector Step_in_base "Input port of a step without icon"
input Boolean fire "true, if transition fires and step is activated" annotation(HideResult = true);
Node node "Communicates suspend/resume flags and is used to check the correct connection structure." annotation(HideResult = true);
output Boolean checkUnaryConnection "Is used to guarantee that only 1:1 connections are possible" annotation(HideResult = true);
input Boolean checkOneDelayedTransitionPerLoop "Is used to check that every connection loop has at least one delayed transition" annotation(__Dymola_BooleanLoopMessage = "
Every loop of a StateGraph must have at least one delayed transition
(an instance of Components.Transition with parameter delayedTransition = true)
in order that infinite event looping cannot occur. Alternatively you can set
checkLoop=false in the Advanced tab of the Transition, provided you are
absolutely sure that this cannot happen.
", HideResult = true);
end Step_in_base;
connector Step_out_base "Output port of a step without icon"
output Boolean available "= true, if step is active and firing is possible" annotation(HideResult = true);
input Boolean fire "= true, if transition fires and step is deactivated" annotation(HideResult = true);
Node node "Communicates suspend/resume flags and is used to check the correct connection structure." annotation(HideResult = true);
output Boolean checkOneDelayedTransitionPerLoop "Is used to check that every connection loop has at least one delayed transition" annotation(__Dymola_BooleanLoopMessage = "
Every loop of a StateGraph must have at least one delayed transition
(an instance of Components.Transition with parameter delayedTransition = true)
in order that infinite event looping cannot occur. Alternatively you can set
checkLoop=false in the Advanced tab of the Transition, provided you are
absolutely sure that this cannot happen.
", HideResult = true);
end Step_out_base;
connector Step_in "Input port of a step"
extends Step_in_base;
annotation(defaultComponentName = "inPort", Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false), graphics = {Ellipse(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, fillColor = {215, 215, 215}, fillPattern = FillPattern.Solid)}), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false), graphics = {Rectangle(extent = {{0, 0}, {0, 0}}, lineColor = {0, 0, 0}, fillColor = {0, 0, 0}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-40, 40}, {40, -40}}, lineColor = {0, 0, 0}, fillColor = {215, 215, 215}, fillPattern = FillPattern.Solid), Text(extent = {{47, 58}, {112, 20}}, lineColor = {0, 0, 0}, textString = "%name")}));
end Step_in;
connector Step_out "Output port of a step"
extends Step_out_base;
annotation(defaultComponentName = "outPort", Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false), graphics = {Polygon(points = {{-100, 100}, {0, -100}, {100, 100}, {-100, 100}}, lineColor = {0, 0, 0}, smooth = Smooth.None, fillColor = {215, 215, 215}, fillPattern = FillPattern.Solid)}), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false), graphics = {Rectangle(extent = {{0, 0}, {0, 0}}, lineColor = {0, 0, 0}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Polygon(points = {{-40, 100}, {0, 20}, {40, 100}, {-40, 100}}, lineColor = {0, 0, 0}, smooth = Smooth.None, fillColor = {215, 215, 215}, fillPattern = FillPattern.Solid), Text(extent = {{40, 66}, {116, 30}}, lineColor = {0, 0, 0}, textString = "%name")}));
end Step_out;
connector Transition_in_base "Input port of a transition without an icon"
input Boolean available "= true, if step connected to the transition input is active and firing is possible" annotation(HideResult = true);
output Boolean fire "= true, if transition fires and the step connected to the transition input is deactivated" annotation(HideResult = true);
Node node "Communicates suspend/resume flags and is used to check the correct connection structure." annotation(HideResult = true);
input Boolean checkOneDelayedTransitionPerLoop "Is used to check that every connection loop has at least one delayed transition" annotation(__Dymola_BooleanLoopMessage = "
Every loop of a StateGraph must have at least one delayed transition
(an instance of Components.Transition with parameter delayedTransition = true)
in order that infinite event looping cannot occur. Alternatively you can set
checkLoop=false in the Advanced tab of the Transition, provided you are
absolutely sure that this cannot happen.
", HideResult = true);
end Transition_in_base;
connector Transition_out_base "Output port of a transition without icon"
output Boolean fire "true, if transition fires and step connected to the transition output becomes active" annotation(HideResult = true);
Node node "Communicates suspend/resume flags and is used to check the correct connection structure." annotation(HideResult = true);
input Boolean checkUnaryConnection "Is used to guarantee that only 1:1 connections are possible" annotation(HideResult = true);
output Boolean checkOneDelayedTransitionPerLoop "Is used to check that every connection loop has at least one delayed transition" annotation(__Dymola_BooleanLoopMessage = "
Every loop of a StateGraph must have at least one delayed transition
(an instance of Components.Transition with parameter delayedTransition = true)
in order that infinite event looping cannot occur. Alternatively you can set
checkLoop=false in the Advanced tab of the Transition, provided you are
absolutely sure that this cannot happen.
", HideResult = true);
end Transition_out_base;
connector Transition_in "Input port of a transition"
extends Transition_in_base;
annotation(defaultComponentName = "inPort", Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false), graphics = {Ellipse(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, fillColor = {215, 215, 215}, fillPattern = FillPattern.Solid)}), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false), graphics = {Ellipse(extent = {{-40, 40}, {40, -40}}, lineColor = {0, 0, 0}, fillColor = {215, 215, 215}, fillPattern = FillPattern.Solid), Text(extent = {{51, 22}, {134, -16}}, lineColor = {0, 0, 0}, textString = "%name")}), Documentation(info = "<html>
</html>"));
end Transition_in;
connector Transition_out "Output port of a transition"
extends Transition_out_base;
annotation(defaultComponentName = "outPort", Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false), graphics = {Polygon(points = {{-100, 100}, {0, -100}, {100, 100}, {-100, 100}}, lineColor = {0, 0, 0}, smooth = Smooth.None, fillColor = {215, 215, 215}, fillPattern = FillPattern.Solid)}), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false), graphics = {Polygon(points = {{-40, 100}, {0, 20}, {40, 100}, {-40, 100}}, lineColor = {0, 0, 0}, smooth = Smooth.None, fillColor = {215, 215, 215}, fillPattern = FillPattern.Solid), Text(extent = {{44, 100}, {138, 68}}, lineColor = {0, 0, 0}, textString = "%name")}), Documentation(info = "<html>
</html>"));
end Transition_out;
end Interfaces;
package Utilities "Utility functions used to implement a Modelica_StateGraph2"
function propagateLoopCheck "Propagate flag to check loop"
extends Modelica.Icons.Function;
input Boolean[:] b;
output Boolean result;
protected
Integer dummy;
algorithm
dummy := 0;
result := true;
end propagateLoopCheck;
end Utilities;
end Internal;
annotation(uses(Modelica(version = "3.2.3")), Dymola(checkSum = "90067705:1029089882"), preferredView = "info", version = "2.0.3", versionBuild = 0, versionDate = "2016-03-11", dateModified = "2016-03-11 15:20:00Z", revisionId = "$Id:: package.mo 9594 2016-12-19 07:05:33Z #$", Documentation(info = "<html>
<p>
<img src=\"modelica://Modelica_StateGraph2/Resources/Images/StateGraph/UsersGuide/StateGraphElements.png\" align=\"right\">
Library <b>Modelica_StateGraph2</b> is a <b>free</b> Modelica package providing
components to model <b>discrete event</b>, <b>reactive</b> and
<b>hybrid</b> systems in a convenient way with <b>deterministic hierarchical state diagrams</b>.
For convenience, the abbreviation \"StateGraph2\" will be
often used for this library. An example model constructed with this
library is shown in the figure to the right.
</p>
<p>
This library is inspired by Grafcet/Sequential Function Charts (SFC), Statecharts,
Safe State Machines (SSM) and Mode Automata, and utilizes Modelica as action language.
It has a similar modeling power as
these formalisms, e.g. synchronization of parallel executing branches
as in SFC (not easy in Statecharts), or suspending a hierarchical subgraph with one
transition and resuming at the same states afterwards when entering it again, as in Statechart (not possible in SFC). A StateGraph2 model is always deterministic due to
Modelicas \"single assignment rule\". Via special blocks in subpackage \"Blocks\",
actions can be defined in a graphical way depending on the active step.
</p>
<p>
In order to construct a new state machine, exactly one instance of either \"Step\"
or of \"Parallel\" must have parameter \"initialStep = <b>true</b>\".
The \"Parallel\" component is both used as \"composite step\" (so only one branch),
as well as \"parallel step\" (so several execution branches). The branches can be
synchronized (if parameter use_outPort = <b>true</b>) or can run unsynchronized
to each other (if parameter use_outPort = <b>false</b>).
</p>
<p>
For an introduction, have especially a look at:
</p>
<ul>
<li><a href=\"modelica://Modelica_StateGraph2.UsersGuide.Tutorial\">Tutorial</a>
provides an overview of the library inside the User's Guide.</li>
<li><a href=\"modelica://Modelica_StateGraph2.Examples\">Examples</a>
provides simple introductory examples as well as involved application examples.</li>
<li> <a href=\"modelica://Modelica_StateGraph2.UsersGuide.ComparisonWithStateGraph1\">ComparisonWithStateGraph1</a>
summarizes the enhancements with respect to the previous version of
Modelica.StateGraph.</li>
</ul>
<p>
This library is implemented with Modelica 3.1 and utilizes non-standard extensions to Modelica 3.1 as summarized
<a href=\"modelica://Modelica_StateGraph2.UsersGuide.UsedModelicaExtensions\">here</a>.
</p>
<p>
<b>Licensed by DLR and Dynasim under the Modelica License 2</b><br>
Copyright © 2003-2013, DLR and 2007-2009, Dynasim AB
</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_StateGraph2.UsersGuide.ModelicaLicense2\">here</a></u>
or at
<a href=\"http://www.Modelica.org/licenses/ModelicaLicense2\">
http://www.Modelica.org/licenses/ModelicaLicense2</a>.</i>
</p>
</html>"));
end Modelica_StateGraph2;
package ModelicaServices "ModelicaServices (OpenModelica implementation) - Models and functions used in the Modelica Standard Library requiring a tool specific implementation"
extends Modelica.Icons.Package;
package Machine "Machine dependent constants"
extends Modelica.Icons.Package;
final constant Real eps = 1e-15 "Biggest number such that 1.0 + eps = 1.0";
final constant Real small = 1e-60 "Smallest number such that small and -small are representable on the machine";
final constant Real inf = 1e60 "Biggest Real number such that inf and -inf are representable on the machine";
final constant Integer Integer_inf = OpenModelica.Internal.Architecture.integerMax() "Biggest Integer number such that Integer_inf and -Integer_inf are representable on the machine";
annotation(Documentation(info = "<html>
<p>
Package in which processor specific constants are defined that are needed
by numerical algorithms. Typically these constants are not directly used,
but indirectly via the alias definition in
<a href=\"modelica://Modelica.Constants\">Modelica.Constants</a>.
</p>
</html>"));
end Machine;
annotation(preferredView = "info", version = "3.2.3", versionBuild = 3, versionDate = "2019-01-23", dateModified = "2019-09-21 12:00:00Z", revisionId = "$Format:%h %ci$", uses(Modelica(version = "3.2.3")), conversion(noneFromVersion = "1.0", noneFromVersion = "1.1", noneFromVersion = "1.2", noneFromVersion = "3.2.1", noneFromVersion = "3.2.2"), Documentation(info = "<html>
<p>
This package contains a set of functions and models to be used in the
Modelica Standard Library that requires a tool specific implementation.
These are:
</p>
<ul>
<li> <a href=\"modelica://ModelicaServices.Animation.Shape\">Animation.Shape</a>
provides a 3-dim. visualization of elementary
mechanical objects. It is used in
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Advanced.Shape\">Modelica.Mechanics.MultiBody.Visualizers.Advanced.Shape</a>
via inheritance.</li>
<li> <a href=\"modelica://ModelicaServices.Animation.Surface\">Animation.Surface</a>
provides a 3-dim. visualization of
moveable parameterized surface. It is used in
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Advanced.Surface\">Modelica.Mechanics.MultiBody.Visualizers.Advanced.Surface</a>
via inheritance.</li>
<li> <a href=\"modelica://ModelicaServices.ExternalReferences.loadResource\">ExternalReferences.loadResource</a>
provides a function to return the absolute path name of an URI or a local file name. It is used in
<a href=\"modelica://Modelica.Utilities.Files.loadResource\">Modelica.Utilities.Files.loadResource</a>
via inheritance.</li>
<li> <a href=\"modelica://ModelicaServices.Machine\">Machine</a>
provides a package of machine constants. It is used in
<a href=\"modelica://Modelica.Constants\">Modelica.Constants</a>.</li>
<li> <a href=\"modelica://ModelicaServices.System.exit\">System.exit</a> provides a function to terminate the execution of the Modelica environment. It is used in <a href=\"modelica://Modelica.Utilities.System.exit\">Modelica.Utilities.System.exit</a> via inheritance.</li>
<li> <a href=\"modelica://ModelicaServices.Types.SolverMethod\">Types.SolverMethod</a>
provides a string defining the integration method to solve differential equations in
a clocked discretized continuous-time partition (see Modelica 3.3 language specification).
It is not yet used in the Modelica Standard Library, but in the Modelica_Synchronous library
that provides convenience blocks for the clock operators of Modelica version ≥ 3.3.</li>
</ul>
<p>
This is the default implementation, if no tool-specific implementation is available.
This ModelicaServices package provides only \"dummy\" models that do nothing.
</p>
<p>
<strong>Licensed by the Modelica Association under the 3-Clause BSD License</strong><br>
Copyright © 2009-2019, Modelica Association and contributors
</p>
<p>
<em>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 3-Clause BSD license. For license conditions (including the disclaimer of warranty) visit <a href=\"https://modelica.org/licenses/modelica-3-clause-bsd\">https://modelica.org/licenses/modelica-3-clause-bsd</a>.</em>
</p>
</html>"));
end ModelicaServices;
package Modelica "Modelica Standard Library - Version 3.2.3"
extends Modelica.Icons.Package;
package Blocks "Library of basic input/output control blocks (continuous, discrete, logical, table blocks)"
extends Modelica.Icons.Package;
package Interfaces "Library of connectors and partial models for input/output blocks"
extends Modelica.Icons.InterfacesPackage;
connector RealInput = input Real "'input Real' as connector" annotation(defaultComponentName = "u", Icon(graphics = {Polygon(lineColor = {0, 0, 127}, fillColor = {0, 0, 127}, fillPattern = FillPattern.Solid, points = {{-100.0, 100.0}, {100.0, 0.0}, {-100.0, -100.0}})}, coordinateSystem(extent = {{-100.0, -100.0}, {100.0, 100.0}}, preserveAspectRatio = true, initialScale = 0.2)), Diagram(coordinateSystem(preserveAspectRatio = true, initialScale = 0.2, extent = {{-100.0, -100.0}, {100.0, 100.0}}), graphics = {Polygon(lineColor = {0, 0, 127}, fillColor = {0, 0, 127}, fillPattern = FillPattern.Solid, points = {{0.0, 50.0}, {100.0, 0.0}, {0.0, -50.0}, {0.0, 50.0}}), Text(lineColor = {0, 0, 127}, extent = {{-10.0, 60.0}, {-10.0, 85.0}}, 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.0, -100.0}, {100.0, 100.0}}), graphics = {Polygon(lineColor = {0, 0, 127}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, points = {{-100.0, 100.0}, {100.0, 0.0}, {-100.0, -100.0}})}), Diagram(coordinateSystem(preserveAspectRatio = true, extent = {{-100.0, -100.0}, {100.0, 100.0}}), graphics = {Polygon(lineColor = {0, 0, 127}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, points = {{-100.0, 50.0}, {0.0, 0.0}, {-100.0, -50.0}}), Text(lineColor = {0, 0, 127}, extent = {{30.0, 60.0}, {30.0, 110.0}}, textString = "%name")}), Documentation(info = "<html>
<p>
Connector with one output signal of type Real.
</p>
</html>"));
connector BooleanInput = input Boolean "'input Boolean' as connector" annotation(defaultComponentName = "u", Icon(graphics = {Polygon(points = {{-100, 100}, {100, 0}, {-100, -100}, {-100, 100}}, lineColor = {255, 0, 255}, fillColor = {255, 0, 255}, 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}}), graphics = {Polygon(points = {{0, 50}, {100, 0}, {0, -50}, {0, 50}}, lineColor = {255, 0, 255}, fillColor = {255, 0, 255}, fillPattern = FillPattern.Solid), Text(extent = {{-10, 85}, {-10, 60}}, lineColor = {255, 0, 255}, textString = "%name")}), Documentation(info = "<html>
<p>
Connector with one input signal of type Boolean.
</p>
</html>"));
connector BooleanOutput = output Boolean "'output Boolean' as connector" annotation(defaultComponentName = "y", Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Polygon(points = {{-100, 100}, {100, 0}, {-100, -100}, {-100, 100}}, lineColor = {255, 0, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid)}), Diagram(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Polygon(points = {{-100, 50}, {0, 0}, {-100, -50}, {-100, 50}}, lineColor = {255, 0, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Text(extent = {{30, 110}, {30, 60}}, lineColor = {255, 0, 255}, textString = "%name")}), Documentation(info = "<html>
<p>
Connector with one output signal of type Boolean.
</p>
</html>"));
partial block MO "Multiple Output continuous control block"
extends Modelica.Blocks.Icons.Block;
parameter Integer nout(min = 1) = 1 "Number of outputs";
RealOutput[nout] y "Connector of Real output signals" annotation(Placement(transformation(extent = {{100, -10}, {120, 10}})));
annotation(Documentation(info = "<html>
<p>
Block has one continuous Real output signal vector.
</p>
</html>"));
end MO;
partial block partialBooleanSISO "Partial block with 1 input and 1 output Boolean signal"
extends Modelica.Blocks.Icons.PartialBooleanBlock;
Blocks.Interfaces.BooleanInput u "Connector of Boolean input signal" annotation(Placement(transformation(extent = {{-140, -20}, {-100, 20}})));
Blocks.Interfaces.BooleanOutput y "Connector of Boolean output signal" annotation(Placement(transformation(extent = {{100, -10}, {120, 10}})));
annotation(Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Ellipse(extent = {{-71, 7}, {-85, -7}}, lineColor = DynamicSelect({235, 235, 235}, if u then {0, 255, 0} else {235, 235, 235}), fillColor = DynamicSelect({235, 235, 235}, if u then {0, 255, 0} else {235, 235, 235}), fillPattern = FillPattern.Solid), Ellipse(extent = {{71, 7}, {85, -7}}, lineColor = DynamicSelect({235, 235, 235}, if y then {0, 255, 0} else {235, 235, 235}), fillColor = DynamicSelect({235, 235, 235}, if y then {0, 255, 0} else {235, 235, 235}), fillPattern = FillPattern.Solid)}), Documentation(info = "<html>
<p>
Block has one continuous Boolean input and one continuous Boolean output signal
with a 3D icon (e.g., used in Blocks.Logical library).
</p>
</html>"));
end partialBooleanSISO;
partial block partialBooleanSO "Partial block with 1 output Boolean signal"
Blocks.Interfaces.BooleanOutput y "Connector of Boolean output signal" annotation(Placement(transformation(extent = {{100, -10}, {120, 10}})));
extends Modelica.Blocks.Icons.PartialBooleanBlock;
annotation(Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Ellipse(extent = {{71, 7}, {85, -7}}, lineColor = DynamicSelect({235, 235, 235}, if y then {0, 255, 0} else {235, 235, 235}), fillColor = DynamicSelect({235, 235, 235}, if y then {0, 255, 0} else {235, 235, 235}), fillPattern = FillPattern.Solid)}), Documentation(info = "<html>
<p>
Block has one continuous Boolean output signal
with a 3D icon (e.g., used in Blocks.Logical library).
</p>
</html>"));
end partialBooleanSO;
annotation(Documentation(info = "<html>
<p>
This package contains interface definitions for
<strong>continuous</strong> 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><em>Oct. 21, 2002</em>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>
and Christian Schweiger:<br>
Added several new interfaces.</li>
<li><em>Oct. 24, 1999</em>
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><em>June 30, 1999</em>
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>"));
end Interfaces;
package Logical "Library of components with Boolean input and output signals"
extends Modelica.Icons.Package;
block Not "Logical 'not': y = not u"
extends Blocks.Interfaces.partialBooleanSISO;
equation
y = not u;
annotation(defaultComponentName = "not1", Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Text(extent = {{-90, 40}, {90, -40}}, textString = "not")}), Documentation(info = "<html>
<p>
The output is <strong>true</strong> if the input is <strong>false</strong>, otherwise
the output is <strong>false</strong>.
</p>
</html>"));
end Not;
annotation(Documentation(info = "<html>
<p>
This package provides blocks with Boolean input and output signals
to describe logical networks. A typical example for a logical
network built with package Logical is shown in the next figure:
</p>
<p>
<img src=\"modelica://Modelica/Resources/Images/Blocks/LogicalNetwork1.png\"
alt=\"LogicalNetwork1.png\">
</p>
<p>
The actual value of Boolean input and/or output signals is displayed
in the respective block icon as \"circle\", where \"white\" color means
value <strong>false</strong> and \"green\" color means value <strong>true</strong>. These
values are visualized in a diagram animation.
</p>
</html>"), Icon(graphics = {Line(points = {{-86, -22}, {-50, -22}, {-50, 22}, {48, 22}, {48, -22}, {88, -24}}, color = {255, 0, 255})}));
end Logical;
package Math "Library of Real mathematical functions as input/output blocks"
extends Modelica.Icons.Package;
block RealToBoolean "Convert Real to Boolean signal"
Blocks.Interfaces.RealInput u "Connector of Real input signal" annotation(Placement(transformation(extent = {{-140, -20}, {-100, 20}})));
extends .Modelica.Blocks.Interfaces.partialBooleanSO;
parameter Real threshold = 0.5 "Output signal y is true, if input u >= threshold";
equation
y = u >= threshold;
annotation(Documentation(info = "<html>
<p>
This block computes the Boolean output <strong>y</strong>
from the Real input <strong>u</strong> by the equation:
</p>
<pre> y = u ≥ threshold;
</pre>
<p>
where <strong>threshold</strong> is a parameter.
</p>
</html>"), Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Text(extent = {{-86, 92}, {-6, 10}}, lineColor = {0, 0, 127}, textString = "R"), Polygon(points = {{-12, -46}, {-32, -26}, {-32, -36}, {-64, -36}, {-64, -56}, {-32, -56}, {-32, -66}, {-12, -46}}, lineColor = {255, 0, 255}, fillColor = {255, 0, 255}, fillPattern = FillPattern.Solid), Text(extent = {{8, -4}, {92, -94}}, lineColor = {255, 0, 255}, textString = "B")}));
end RealToBoolean;
annotation(Documentation(info = "<html>
<p>
This package contains basic <strong>mathematical operations</strong>,
such as summation and multiplication, and basic <strong>mathematical
functions</strong>, such as <strong>sqrt</strong> and <strong>sin</strong>, 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><em>August 24, 2016</em>
by Christian Kral: added WrapAngle</li>
<li><em>October 21, 2002</em>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>
and Christian Schweiger:<br>
New blocks added: RealToInteger, IntegerToReal, Max, Min, Edge, BooleanChange, IntegerChange.</li>
<li><em>August 7, 1999</em>
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>"), Icon(graphics = {Line(points = {{-80, -2}, {-68.7, 32.2}, {-61.5, 51.1}, {-55.1, 64.4}, {-49.4, 72.6}, {-43.8, 77.1}, {-38.2, 77.8}, {-32.6, 74.6}, {-26.9, 67.7}, {-21.3, 57.4}, {-14.9, 42.1}, {-6.83, 19.2}, {10.1, -32.8}, {17.3, -52.2}, {23.7, -66.2}, {29.3, -75.1}, {35, -80.4}, {40.6, -82}, {46.2, -79.6}, {51.9, -73.5}, {57.5, -63.9}, {63.9, -49.2}, {72, -26.8}, {80, -2}}, color = {95, 95, 95}, smooth = Smooth.Bezier)}));
end Math;
package Sources "Library of signal source blocks generating Real, Integer and Boolean signals"
extends Modelica.Icons.SourcesPackage;
block CombiTimeTable "Table look-up with respect to time and linear/periodic extrapolation methods (data from matrix/file)"
extends Modelica.Blocks.Interfaces.MO(final nout = max([size(columns, 1); size(offset, 1)]));
parameter Boolean tableOnFile = false "= true, if table is defined on file or in function usertab" annotation(Dialog(group = "Table data definition"));
parameter Real[:, :] table = fill(0.0, 0, 2) "Table matrix (time = first column; e.g., table=[0, 0; 1, 1; 2, 4])" annotation(Dialog(group = "Table data definition", enable = not tableOnFile));
parameter String tableName = "NoName" "Table name on file or in function usertab (see docu)" annotation(Dialog(group = "Table data definition", enable = tableOnFile));
parameter String fileName = "NoName" "File where matrix is stored" annotation(Dialog(group = "Table data definition", enable = tableOnFile, loadSelector(filter = "Text files (*.txt);;MATLAB MAT-files (*.mat)", caption = "Open file in which table is present")));
parameter Boolean verboseRead = true "= true, if info message that file is loading is to be printed" annotation(Dialog(group = "Table data definition", enable = tableOnFile));
parameter Integer[:] columns = 2:size(table, 2) "Columns of table to be interpolated" annotation(Dialog(group = "Table data interpretation", groupImage = "modelica://Modelica/Resources/Images/Blocks/Sources/CombiTimeTable.png"));
parameter Modelica.Blocks.Types.Smoothness smoothness = Modelica.Blocks.Types.Smoothness.LinearSegments "Smoothness of table interpolation" annotation(Dialog(group = "Table data interpretation"));
parameter Modelica.Blocks.Types.Extrapolation extrapolation = Modelica.Blocks.Types.Extrapolation.LastTwoPoints "Extrapolation of data outside the definition range" annotation(Dialog(group = "Table data interpretation"));
parameter Modelica.SIunits.Time timeScale(min = Modelica.Constants.eps) = 1 "Time scale of first table column" annotation(Dialog(group = "Table data interpretation"), Evaluate = true);
parameter Real[:] offset = {0} "Offsets of output signals" annotation(Dialog(group = "Table data interpretation"));
parameter Modelica.SIunits.Time startTime = 0 "Output = offset for time < startTime" annotation(Dialog(group = "Table data interpretation"));
parameter Modelica.SIunits.Time shiftTime = startTime "Shift time of first table column" annotation(Dialog(group = "Table data interpretation"));
parameter Modelica.Blocks.Types.TimeEvents timeEvents = Modelica.Blocks.Types.TimeEvents.Always "Time event handling of table interpolation" annotation(Dialog(group = "Table data interpretation", enable = smoothness == Modelica.Blocks.Types.Smoothness.LinearSegments));
parameter Boolean verboseExtrapolation = false "= true, if warning messages are to be printed if time is outside the table definition range" annotation(Dialog(group = "Table data interpretation", enable = extrapolation == Modelica.Blocks.Types.Extrapolation.LastTwoPoints or extrapolation == Modelica.Blocks.Types.Extrapolation.HoldLastPoint));
final parameter Modelica.SIunits.Time t_min = t_minScaled * timeScale "Minimum abscissa value defined in table";
final parameter Modelica.SIunits.Time t_max = t_maxScaled * timeScale "Maximum abscissa value defined in table";
final parameter Real t_minScaled = .Modelica.Blocks.Tables.Internal.getTimeTableTmin(tableID) "Minimum (scaled) abscissa value defined in table";
final parameter Real t_maxScaled = .Modelica.Blocks.Tables.Internal.getTimeTableTmax(tableID) "Maximum (scaled) abscissa value defined in table";
protected
final parameter Real[nout] p_offset = if size(offset, 1) == 1 then ones(nout) * offset[1] else offset "Offsets of output signals";
parameter Modelica.Blocks.Types.ExternalCombiTimeTable tableID = Modelica.Blocks.Types.ExternalCombiTimeTable(if tableOnFile then tableName else "NoName", if tableOnFile and fileName <> "NoName" and not Modelica.Utilities.Strings.isEmpty(fileName) then fileName else "NoName", table, startTime / timeScale, columns, smoothness, extrapolation, shiftTime / timeScale, if smoothness == Modelica.Blocks.Types.Smoothness.LinearSegments then timeEvents elseif smoothness == Modelica.Blocks.Types.Smoothness.ConstantSegments then Modelica.Blocks.Types.TimeEvents.Always else Modelica.Blocks.Types.TimeEvents.NoTimeEvents, if tableOnFile then verboseRead else false) "External table object";
discrete Modelica.SIunits.Time nextTimeEvent(start = 0, fixed = true) "Next time event instant";
discrete Real nextTimeEventScaled(start = 0, fixed = true) "Next scaled time event instant";
Real timeScaled "Scaled time";
equation
if tableOnFile then
assert(tableName <> "NoName", "tableOnFile = true and no table name given");
else
assert(size(table, 1) > 0 and size(table, 2) > 0, "tableOnFile = false and parameter table is an empty matrix");
end if;
if verboseExtrapolation and (extrapolation == Modelica.Blocks.Types.Extrapolation.LastTwoPoints or extrapolation == Modelica.Blocks.Types.Extrapolation.HoldLastPoint) then
assert(noEvent(time >= t_min), "
Extrapolation warning: Time (=" + String(time) + ") must be greater or equal
than the minimum abscissa value t_min (=" + String(t_min) + ") defined in the table.
", AssertionLevel.warning);
assert(noEvent(time <= t_max), "
Extrapolation warning: Time (=" + String(time) + ") must be less or equal
than the maximum abscissa value t_max (=" + String(t_max) + ") defined in the table.
", AssertionLevel.warning);
end if;
timeScaled = time / timeScale;
when {time >= pre(nextTimeEvent), initial()} then
nextTimeEventScaled = .Modelica.Blocks.Tables.Internal.getNextTimeEvent(tableID, timeScaled);
nextTimeEvent = if nextTimeEventScaled < Modelica.Constants.inf then nextTimeEventScaled * timeScale else Modelica.Constants.inf;
end when;
if smoothness == Modelica.Blocks.Types.Smoothness.ConstantSegments then
for i in 1:nout loop
y[i] = p_offset[i] + .Modelica.Blocks.Tables.Internal.getTimeTableValueNoDer(tableID, i, timeScaled, nextTimeEventScaled, pre(nextTimeEventScaled));
end for;
else
for i in 1:nout loop
y[i] = p_offset[i] + .Modelica.Blocks.Tables.Internal.getTimeTableValue(tableID, i, timeScaled, nextTimeEventScaled, pre(nextTimeEventScaled));
end for;
end if;
annotation(Documentation(info = "<html>
<p>
This block generates an output signal y[:] by <strong>constant</strong>,
<strong>linear</strong> or <strong>cubic Hermite spline interpolation</strong>
in a table. The time points and function values are stored in a matrix
<strong>table[i,j]</strong>, where the first column table[:,1] contains the
time points and the other columns contain the data to be interpolated.
</p>
<p>
<img src=\"modelica://Modelica/Resources/Images/Blocks/Sources/CombiTimeTable.png\"
alt=\"CombiTimeTable.png\">
</p>
<p>
Via parameter <strong>columns</strong> it can be defined which columns of the
table are interpolated. If, e.g., columns={2,4}, it is assumed that
2 output signals are present and that the first output is computed
by interpolation of column 2 and the second output is computed
by interpolation of column 4 of the table matrix.
The table interpolation has the following properties:
</p>
<ul>
<li>The interpolation interval is found by a binary search where the interval used in the
last call is used as start interval.</li>
<li>The time points need to be <strong>strictly increasing</strong> for cubic Hermite
spline interpolation, otherwise <strong>monotonically increasing</strong>.</li>
<li><strong>Discontinuities</strong> are allowed for (constant or) linear interpolation,
by providing the same time point twice in the table.</li>
<li>Via parameter <strong>smoothness</strong> it is defined how the data is interpolated:
<pre>
smoothness = 1: Linear interpolation
= 2: Akima interpolation: Smooth interpolation by cubic Hermite
splines such that der(y) is continuous, also if extrapolated.
= 3: Constant segments
= 4: Fritsch-Butland interpolation: Smooth interpolation by cubic
Hermite splines such that y preserves the monotonicity and
der(y) is continuous, also if extrapolated.
= 5: Steffen interpolation: Smooth interpolation by cubic Hermite
splines such that y preserves the monotonicity and der(y)
is continuous, also if extrapolated.
</pre></li>
<li>Values <strong>outside</strong> of the table range, are computed by
extrapolation according to the setting of parameter <strong>extrapolation</strong>:
<pre>
extrapolation = 1: Hold the first or last value of the table,
if outside of the table scope.
= 2: Extrapolate by using the derivative at the first/last table
points if outside of the table scope.
(If smoothness is LinearSegments or ConstantSegments
this means to extrapolate linearly through the first/last
two table points.).
= 3: Periodically repeat the table data (periodical function).
= 4: No extrapolation, i.e. extrapolation triggers an error
</pre></li>
<li>If the table has only <strong>one row</strong>, no interpolation is performed and
the table values of this row are just returned.</li>
<li>Via parameters <strong>shiftTime</strong> and <strong>offset</strong> the curve defined
by the table can be shifted both in time and in the ordinate value.
The time instants stored in the table are therefore <strong>relative</strong>
to <strong>shiftTime</strong>.</li>
<li>If time < startTime, no interpolation is performed and the offset
is used as ordinate value for all outputs.</li>
<li>The table is implemented in a numerically sound way by
generating <strong>time events</strong> at interval boundaries, in case of
interpolation by linear segments.
This generates continuously differentiable values for the integrator.
Via parameter <strong>timeEvents</strong> it is defined how the time events are generated:
<pre>
timeEvents = 1: Always generate time events at interval boundaries
= 2: Generate time events at discontinuities (defined by duplicated sample points)
= 3: No time events at interval boundaries
</pre>
For interpolation by constant segments time events are always generated at interval boundaries.
For smooth interpolation by cubic Hermite splines no time events are generated at interval boundaries.</li>
<li>Via parameter <strong>timeScale</strong> the first column of the table array can
be scaled, e.g., if the table array is given in hours (instead of seconds)
<strong>timeScale</strong> shall be set to 3600.</li>
<li>For special applications it is sometimes needed to know the minimum
and maximum time instant defined in the table as a parameter. For this
reason parameters <strong>t_min</strong>/<strong>t_minScaled</strong> and
<strong>t_max</strong>/<strong>t_maxScaled</strong> are provided and can be
accessed from the outside of the table object. Whereas <strong>t_min</strong> and
<strong>t_max</strong> define the scaled abscissa values (using parameter
<strong>timeScale</strong>) in SIunits.Time, <strong>t_minScaled</strong> and
<strong>t_maxScaled</strong> define the unitless original abscissa values of
the table.</li>
</ul>
<p>
Example:
</p>
<pre>
table = [0, 0;
1, 0;
1, 1;
2, 4;
3, 9;
4, 16];
extrapolation = 2 (default), timeEvents = 2
If, e.g., time = 1.0, the output y = 0.0 (before event), 1.0 (after event)
e.g., time = 1.5, the output y = 2.5,
e.g., time = 2.0, the output y = 4.0,
e.g., time = 5.0, the output y = 23.0 (i.e., extrapolation via last 2 points).
</pre>
<p>
The table matrix can be defined in the following ways:
</p>
<ol>
<li>Explicitly supplied as <strong>parameter matrix</strong> \"table\",
and the other parameters have the following values:
<pre>
tableName is \"NoName\" or has only blanks,
fileName is \"NoName\" or has only blanks.
</pre></li>
<li><strong>Read</strong> from a <strong>file</strong> \"fileName\" where the matrix is stored as
\"tableName\". Both text and MATLAB MAT-file format is possible.
(The text format is described below).
The MAT-file format comes in four different versions: v4, v6, v7 and v7.3.
The library supports at least v4, v6 and v7 whereas v7.3 is optional.
It is most convenient to generate the MAT-file from FreeMat or MATLAB®
by command
<pre>
save tables.mat tab1 tab2 tab3
</pre>
or Scilab by command
<pre>
savematfile tables.mat tab1 tab2 tab3
</pre>
when the three tables tab1, tab2, tab3 should be used from the model.<br>
Note, a fileName can be defined as URI by using the helper function
<a href=\"modelica://Modelica.Utilities.Files.loadResource\">loadResource</a>.</li>
<li>Statically stored in function \"usertab\" in file \"usertab.c\".
The matrix is identified by \"tableName\". Parameter
fileName = \"NoName\" or has only blanks. Row-wise storage is always to be
preferred as otherwise the table is reallocated and transposed.</li>
</ol>
<p>
When the constant \"NO_FILE_SYSTEM\" is defined, all file I/O related parts of the
source code are removed by the C-preprocessor, such that no access to files takes place.
</p>
<p>
If tables are read from a text file, the file needs to have the
following structure (\"-----\" is not part of the file content):
</p>
<pre>
-----------------------------------------------------
#1
double tab1(6,2) # comment line
0 0
1 0
1 1
2 4
3 9
4 16
double tab2(6,2) # another comment line
0 0
2 0
2 2
4 8
6 18
8 32
-----------------------------------------------------
</pre>
<p>
Note, that the first two characters in the file need to be
\"#1\" (a line comment defining the version number of the file format).
Afterwards, the corresponding matrix has to be declared
with type (= \"double\" or \"float\"), name and actual dimensions.
Finally, in successive rows of the file, the elements of the matrix
have to be given. The elements have to be provided as a sequence of
numbers in row-wise order (therefore a matrix row can span several
lines in the file and need not start at the beginning of a line).
Numbers have to be given according to C syntax (such as 2.3, -2, +2.e4).
Number separators are spaces, tab (\\t), comma (,), or semicolon (;).
Several matrices may be defined one after another. Line comments start
with the hash symbol (#) and can appear everywhere.
Text files should either be ASCII or UTF-8 encoded, where UTF-8 encoded strings are only allowed in line comments and an optional UTF-8 BOM at the start of the text file is ignored.
Other characters, like trailing non comments, are not allowed in the file.
</p>
<p>
MATLAB is a registered trademark of The MathWorks, Inc.
</p>
</html>", revisions = "<html>
<p><strong>Release Notes:</strong></p>
<ul>
<li><em>April 09, 2013</em>
by Thomas Beutlich:<br>
Implemented as external object.</li>
<li><em>March 31, 2001</em>
by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br>
Used CombiTableTime as a basis and added the
arguments <strong>extrapolation, columns, startTime</strong>.
This allows periodic function definitions.</li>
</ul>