1 | package TwoStatesMachine2
|
---|
2 | model State1
|
---|
3 | outer output Integer i;
|
---|
4 | equation
|
---|
5 | i = previous(i)+2;
|
---|
6 | annotation(
|
---|
7 | Icon(graphics = {Text(extent = {{-100, 100}, {100, -100}}, textString = "%name")}, coordinateSystem(initialScale = 0.1)),
|
---|
8 | __Dymola_state = true,
|
---|
9 | singleInstance = true,
|
---|
10 | Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})));
|
---|
11 | end State1;
|
---|
12 |
|
---|
13 | model State2
|
---|
14 | outer output Integer i;
|
---|
15 | equation
|
---|
16 | i = previous(i)-1;
|
---|
17 |
|
---|
18 | annotation(
|
---|
19 | Icon(graphics = {Text(extent = {{-100, 100}, {100, -100}}, textString = "%name")}, coordinateSystem(initialScale = 0.1)),
|
---|
20 | __Dymola_state = true,
|
---|
21 | singleInstance = true,
|
---|
22 | Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})));
|
---|
23 | end State2;
|
---|
24 |
|
---|
25 | model Machine
|
---|
26 | inner Integer i(start=0);
|
---|
27 | TwoStatesMachine2.State1 state11 annotation(
|
---|
28 | Placement(visible = true, transformation(origin = {-12, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
|
---|
29 | TwoStatesMachine2.State2 state21 annotation(
|
---|
30 | Placement(visible = true, transformation(origin = {-12, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
|
---|
31 | equation
|
---|
32 | initialState(state11);
|
---|
33 | transition(state21, state11, i < 1, immediate = true, reset = true, synchronize = false, priority = 1) annotation(
|
---|
34 | Line(points = {{-2, 10}, {12, 10}, {12, 50}, {-2, 50}}, color = {175, 175, 175}, smooth = Smooth.Bezier),
|
---|
35 | Text(lineColor = {95, 95, 95}, extent = {{-4, 4}, {-4, 10}}, textString = "%condition", fontSize = 10, textStyle = {TextStyle.Bold}, horizontalAlignment = TextAlignment.Right));
|
---|
36 | transition(state11, state21, i > 10, immediate = true, reset = true, synchronize = false, priority = 1) annotation(
|
---|
37 | Line(points = {{-22, 50}, {-36, 50}, {-36, 10}, {-22, 10}}, color = {175, 175, 175}, smooth = Smooth.Bezier),
|
---|
38 | Text(lineColor = {95, 95, 95}, extent = {{-4, 4}, {-4, 10}}, textString = "%condition", fontSize = 10, textStyle = {TextStyle.Bold}, horizontalAlignment = TextAlignment.Right));
|
---|
39 | annotation(
|
---|
40 | Icon(coordinateSystem(grid = {0.1, 0.1})),
|
---|
41 | Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})));
|
---|
42 | end Machine;
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | annotation(
|
---|
50 | Icon(coordinateSystem(grid = {0.1, 0.1})),
|
---|
51 | Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})));
|
---|
52 | end TwoStatesMachine2;
|
---|