/
SystemModel1.mo
204 lines (168 loc) · 11.8 KB
/
SystemModel1.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
//This code is generated from a ModelicaML model.
within ModelicaMLModel.Design;
model SystemModel1
annotation(Diagram(coordinateSystem(extent={{-148.5,-105.0},{148.5,105.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10})), Icon(coordinateSystem(extent={{-100.0,-100.0},{100.0,100.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10}), graphics={Rectangle(visible=true, origin={0.0,65.0}, fillColor={255,255,255}, fillPattern=FillPattern.Solid, lineThickness=1, extent={{-100.0,-35.0},{100.0,35.0}}),Rectangle(visible=true, origin={0.0,-35.0}, fillColor={255,255,255}, fillPattern=FillPattern.Solid, lineThickness=1, extent={{-100.0,-65.0},{100.0,65.0}}),Text(visible=true, origin={0.0,52.0578}, fillPattern=FillPattern.Solid, extent={{-96.311,-15.0969},{96.311,15.0969}}, textString="SystemModel1", fontName="Arial"),Text(visible=true, origin={0.0,83.1521}, fillPattern=FillPattern.Solid, extent={{-90.0,-11.3192},{90.0,11.3192}}, textString="«model»", fontName="Arial"),Text(visible=true, origin={0.3349,-37.1756}, fillPattern=FillPattern.Solid, extent={{-97.7954,-59.2801},{97.7954,59.2801}}, textString="M", fontName="Arial")}));
Integer realVar;
record SystemModel1_StateMachine_StateMachine0
annotation(Diagram(coordinateSystem(extent={{-148.5,-105.0},{148.5,105.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10})), Icon(coordinateSystem(extent={{-100.0,-100.0},{100.0,100.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10}), graphics={Rectangle(visible=true, origin={-6.722,3.6841}, lineColor={0,85,127}, fillColor={85,170,255}, fillPattern=FillPattern.Solid, lineThickness=10, extent={{-75.0,-50.0},{75.0,50.0}}, radius=40),Rectangle(visible=true, origin={70.0,2.6556}, lineColor={85,170,255}, fillColor={0,85,127}, fillPattern=FillPattern.Solid, lineThickness=4, extent={{-26.8908,-25.0},{26.8908,25.0}})}));
// lib properties STATE MACHINE
Boolean active(fixed=true); // indicates if the state is active.
Real timeAtActivation(fixed=true); // time when the state is entered.
Real stime; // stime means "state time". It is is a local timer. It starts when the state is entered and is equal to zero if the state is not active.
Boolean selfTransitionActivated(fixed=true);
Boolean startBehaviour;
// REGIONS instantiation
StateMachine0_Region0 Region0;
// REGIONS classes
record StateMachine0_Region0
annotation(Diagram(coordinateSystem(extent={{-148.5,-105.0},{148.5,105.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10})), Icon(coordinateSystem(extent={{-100.0,-100.0},{100.0,100.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10}), graphics={Rectangle(visible=true, origin={0.3349,3.6841}, lineColor={0,85,127}, fillColor={104,182,221}, fillPattern=FillPattern.Solid, lineThickness=10, extent={{-84.7336,-50.0},{84.7336,50.0}}, radius=40),Rectangle(visible=true, origin={2.0095,40.0}, fillPattern=FillPattern.Solid, extent={{-2.0095,-8.4441},{2.0095,8.4441}}),Rectangle(visible=true, origin={2.0095,4.4251}, fillPattern=FillPattern.Solid, extent={{-2.0095,-8.4441},{2.0095,8.4441}}),Rectangle(visible=true, origin={2.0095,-31.5559}, fillPattern=FillPattern.Solid, extent={{-2.0095,-8.4441},{2.0095,8.4441}}),Rectangle(visible=true, origin={-30.0,70.0}, lineColor={0,85,127}, fillColor={255,255,255}, fillPattern=FillPattern.Solid, lineThickness=2, extent={{-25.0,-10.0},{25.0,10.0}})}));
// SIMPLE STATES instantiation
SimpleState State0;
SimpleState State1;
InitialState Initial0;
/* M@ debug variables */
Integer numberOfActiveStates;
end StateMachine0_Region0;
// library: SIMPLE STATE
record SimpleState
annotation(Diagram(coordinateSystem(extent={{-148.5,-105.0},{148.5,105.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10})), Icon(coordinateSystem(extent={{-100.0,-100.0},{100.0,100.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10}), graphics={Rectangle(visible=true, origin={-0.0,-0.1675}, lineColor={0,85,127}, fillColor={104,182,221}, fillPattern=FillPattern.HorizontalCylinder, lineThickness=10, extent={{-64.6031,-34.6638},{64.6031,34.6638}}, radius=40)}));
// lib properties SIMPLE STATE
Boolean active(fixed=true); // indicates if the state is active.
Real timeAtActivation(fixed=true); // time when the state is entered.
Real stime; // stime means "state time". It is is a local timer. It starts when the state is entered and is equal to zero if the state is not active.
Boolean selfTransitionActivated(fixed=true);
end SimpleState;
// library: INITIAL STATE
record InitialState
annotation(Diagram(coordinateSystem(extent={{-148.5,-105.0},{148.5,105.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10})), Icon(coordinateSystem(extent={{-100.0,-100.0},{100.0,100.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10}), graphics={Rectangle(visible=true, origin={-0.0,0.0}, lineColor={0,85,127}, fillColor={104,182,221}, fillPattern=FillPattern.HorizontalCylinder, lineThickness=10, extent={{-34.8134,-34.6638},{34.8134,34.6638}}, radius=40)}));
// lib properties INITIAL STATE
Boolean active; // indicates if the state is active.
Real timeAtActivation(fixed=true); // time when the state is entered.
Real stime; // stime means "state time". It is is a local timer. It starts when the state is entered and is equal to zero if the state is not active.
Boolean selfTransitionActivated(fixed=true);
end InitialState;
// library: FINAL STATE
record FinalState
annotation(Diagram(coordinateSystem(extent={{-148.5,-105.0},{148.5,105.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10})), Icon(coordinateSystem(extent={{-100.0,-100.0},{100.0,100.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10}), graphics={Rectangle(visible=true, origin={0.0,0.0}, lineColor={0,85,127}, fillColor={255,255,255}, fillPattern=FillPattern.HorizontalCylinder, lineThickness=10, extent={{-34.8134,-34.6638},{34.8134,34.6638}}, radius=40),Rectangle(visible=true, origin={0.0,0.0}, fillPattern=FillPattern.HorizontalCylinder, lineThickness=10, extent={{-17.2767,-17.2024},{17.2767,17.2024}}, radius=40)}));
// lib properties FINAL STATE
Boolean active; // indicates if the state is active.
Real timeAtActivation(fixed=true); // time when the state is entered.
Real stime; // stime means "state time". It is is a local timer. It starts when the state is entered and is equal to zero if the state is not active.
Boolean selfTransitionActivated(fixed=true);
end FinalState;
end SystemModel1_StateMachine_StateMachine0;
// STATE MACHNE instantiation
SystemModel1_StateMachine_StateMachine0 StateMachine0;
algorithm
algorithm
/*** start behaviour code of state machine "StateMachine0" ***/
algorithm
/* initial state machine "StateMachine0" activation */
StateMachine0.startBehaviour:=true;
when StateMachine0.startBehaviour then
StateMachine0.active:=true;
StateMachine0.Region0.Initial0.active:=true;
end when;
when {StateMachine0.active, StateMachine0.selfTransitionActivated} then
StateMachine0.timeAtActivation := time;
StateMachine0.selfTransitionActivated := false;
end when;
if StateMachine0.active then
StateMachine0.stime := time - StateMachine0.timeAtActivation;
end if;
if not StateMachine0.active then
StateMachine0.stime := 0;
end if;
/*** start behaviour code of region "StateMachine0" ***/
when {StateMachine0.Region0.Initial0.active, StateMachine0.Region0.Initial0.selfTransitionActivated} then
StateMachine0.Region0.Initial0.timeAtActivation := time;
StateMachine0.Region0.Initial0.selfTransitionActivated := false;
end when;
if StateMachine0.Region0.Initial0.active then
StateMachine0.Region0.Initial0.stime := time - StateMachine0.Region0.Initial0.timeAtActivation;
end if;
if not StateMachine0.Region0.Initial0.active then
StateMachine0.Region0.Initial0.stime := 0;
end if;
when {StateMachine0.Region0.State0.active, StateMachine0.Region0.State0.selfTransitionActivated} then
StateMachine0.Region0.State0.timeAtActivation := time;
StateMachine0.Region0.State0.selfTransitionActivated := false;
end when;
when {StateMachine0.Region0.State1.active, StateMachine0.Region0.State1.selfTransitionActivated} then
StateMachine0.Region0.State1.timeAtActivation := time;
StateMachine0.Region0.State1.selfTransitionActivated := false;
end when;
if StateMachine0.Region0.State0.active then
StateMachine0.Region0.State0.stime := time - StateMachine0.Region0.State0.timeAtActivation;
end if;
if not StateMachine0.Region0.State0.active then
StateMachine0.Region0.State0.stime := 0;
end if;
if StateMachine0.Region0.State1.active then
StateMachine0.Region0.State1.stime := time - StateMachine0.Region0.State1.timeAtActivation;
end if;
if not StateMachine0.Region0.State1.active then
StateMachine0.Region0.State1.stime := 0;
end if;
/*start transition code*/
if (StateMachine0.Region0.Initial0.active) then
StateMachine0.Region0.Initial0.active := false;
StateMachine0.Region0.State0.active := true;
//state "StateMachine0.Region0.State0": entry behavior
realVar := 2;
end if;
/*test the composite state is still active*/
if(StateMachine0.active ) then
if pre(StateMachine0.Region0.State0.active) then
if (StateMachine0.Region0.State0.stime > (10)) then
StateMachine0.Region0.State0.active := false;
StateMachine0.Region0.State1.active := true;
//state "StateMachine0.Region0.State1": entry behavior
realVar := 3;
end if;
elseif pre(StateMachine0.Region0.State1.active) then
if (StateMachine0.Region0.State1.stime > (20)) then
StateMachine0.Region0.State1.active := false;
StateMachine0.Region0.State0.active := true;
//state "StateMachine0.Region0.State0": entry behavior
realVar := 2;
end if;
end if;
end if;
/*end transition code*/
/*start do Code*/
/*end do Code*/
/*** end behaviour code of region "Region0" ***/
/*start terminate code for state machine "StateMachine0"*/
if (not StateMachine0.active) then
/* M@ start terminate code of region "StateMachine0" ***/
StateMachine0.Region0.Initial0.active := false;
StateMachine0.Region0.State0.active := false;
StateMachine0.Region0.State1.active := false;
/* M@ end terminate code of region "Region0" ***/
end if;
/*end terminate code for state machine "StateMachine0"*/
/*** end behaviour code of state machine "StateMachine0" ***/
/* M@ reset debug variabels */
StateMachine0.Region0.numberOfActiveStates := 0;
/* M@ start debug code of region "----StateMachine0" ***/
if StateMachine0.Region0.State0.active then
StateMachine0.Region0.numberOfActiveStates := StateMachine0.Region0.numberOfActiveStates + 1;
end if;
if StateMachine0.Region0.State1.active then
StateMachine0.Region0.numberOfActiveStates := StateMachine0.Region0.numberOfActiveStates + 1;
end if;
if StateMachine0.Region0.Initial0.active then
StateMachine0.Region0.numberOfActiveStates := StateMachine0.Region0.numberOfActiveStates + 1;
end if;
/* M@ validation code start*/
if StateMachine0.active then
assert(not (StateMachine0.Region0.numberOfActiveStates < 1), "StateMachine0.Region0 has no active states although the parent state is active!");
assert(not (StateMachine0.Region0.numberOfActiveStates > 1), "StateMachine0.Region0 has multiple active states which are mutually exclusive!");
end if;
if not StateMachine0.active then
assert(StateMachine0.Region0.numberOfActiveStates == 0, "StateMachine0.Region0 has active states although the parent state is not active!");
end if;
/* M@ validation code start*/
/* M@ end debug code of region "Region0" ***/
end SystemModel1;