1 | package Test_SendOnDeltaWithTimeout
|
---|
2 | model TriggerByDeltaAndTimeout
|
---|
3 | parameter Real Delta = 0.01 "SOD threshold";
|
---|
4 | parameter Real TOq = 0.01 "timeout quantum";
|
---|
5 | parameter Real TOmul[:] = {5, 10, 20, 50, 100, 20, 500} "timeout multipliers";
|
---|
6 | protected
|
---|
7 | final parameter Integer N = size(TOmul, 1);
|
---|
8 | Integer dex;
|
---|
9 | Real tlast, ulast;
|
---|
10 | public
|
---|
11 | Modelica.Blocks.Interfaces.BooleanOutput trig annotation(
|
---|
12 | Placement(visible = true, transformation(origin = {152, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, -3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
|
---|
13 | Modelica.Blocks.Interfaces.RealInput u annotation(
|
---|
14 | Placement(visible = true, transformation(origin = {-94, -2}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
|
---|
15 | algorithm
|
---|
16 | when pre(dex) == 1 and time - tlast > TOq * TOmul[pre(dex)] or pre(dex) > 1 and (abs(u - ulast) > Delta or time - tlast > TOq * TOmul[pre(dex)]) then
|
---|
17 | if time - tlast > TOq * TOmul[pre(dex)] then
|
---|
18 | dex := min(pre(dex) + 1, N);
|
---|
19 | else
|
---|
20 | dex := 1;
|
---|
21 | end if;
|
---|
22 | trig := not trig;
|
---|
23 | tlast := time;
|
---|
24 | ulast := u;
|
---|
25 | end when;
|
---|
26 | initial algorithm
|
---|
27 | trig := false;
|
---|
28 | dex := 1;
|
---|
29 | tlast := time;
|
---|
30 | ulast := u;
|
---|
31 | annotation(
|
---|
32 | Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})),
|
---|
33 | Icon(graphics = {Rectangle(fillColor = {255, 255, 127}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {-2, -7}, extent = {{-52, 47}, {52, -47}}, textString = "SOD\n+TO")}));
|
---|
34 | end TriggerByDeltaAndTimeout;
|
---|
35 |
|
---|
36 | model Test_TriggerByDeltaAndTimeout
|
---|
37 | Modelica.Blocks.Sources.RealExpression IN(y = sin(time)) annotation(
|
---|
38 | Placement(visible = true, transformation(origin = {-120, -1.42109e-14}, extent = {{-40, -40}, {40, 40}}, rotation = 0)));
|
---|
39 | Test_SendOnDeltaWithTimeout.TriggerByDeltaAndTimeout T annotation(
|
---|
40 | Placement(visible = true, transformation(origin = {1, -1}, extent = {{-41, -41}, {41, 41}}, rotation = 0)));
|
---|
41 | equation
|
---|
42 | connect(IN.y, T.u) annotation(
|
---|
43 | Line(points = {{-76, 0}, {-44, 0}, {-44, 0}, {-40, 0}}, color = {0, 0, 127}));
|
---|
44 | annotation(
|
---|
45 | Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})));
|
---|
46 | end Test_TriggerByDeltaAndTimeout;
|
---|
47 | annotation(
|
---|
48 | Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})),
|
---|
49 | uses(Modelica(version = "3.2.2")));
|
---|
50 | annotation(
|
---|
51 | Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})));
|
---|
52 | annotation(
|
---|
53 | Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})));
|
---|
54 | end Test_SendOnDeltaWithTimeout;
|
---|