-
Notifications
You must be signed in to change notification settings - Fork 0
/
ELAFish.base.controllers.msl
290 lines (234 loc) · 8.21 KB
/
ELAFish.base.controllers.msl
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
// -----------------------------------------------------------------------
// HEMMIS - Ghent University, BIOMATH - Université Laval, modelEAU
// Implementation: Hans Vangheluwe, Peter Vanrolleghem, Henk Vanhooren,
// Jurgen Meirlaen,Frederik Decouttere, Youri Amerlinck
// Frederik De Laender, Ludiwine Clouzot.
// Description: MSL-USER/ELAFish/Base/Controllers
// -----------------------------------------------------------------------
#ifndef ELAFISH_BASE_CONTROLLERS
#define ELAFISH_BASE_CONTROLLERS
CLASS P
(* class = "controller" *)
"P controller"
// The value of the manipulated variabele changes proportional to the value
// of the error signal.
SPECIALISES
PhysicalDAEModelType :=
{:
comments <- "A model for a proportional controller";
interface <-
{
OBJ y_M (* terminal = "in_1" *) "Sensor measured output" :
Real := {: causality <- "CIN" :};
OBJ u (* terminal = "out_1" *) "Controlled variable" :
Real := {: causality <- "COUT" :};
};
parameters <-
{
OBJ u0 "No error action" : Real := {: value <- 50 :};
OBJ y_S "Setpoint value for controlled variable" :
Real := {: value <- 2 :};
OBJ K_P "Factor of proportionality" :
Real := {: value <- 25 :};
};
independent <-
{
OBJ t "Time": Time ;
};
state <-
{
};
equations <-
{
interface.u = parameters.K_P *
(parameters.y_S - interface.y_M) +
parameters.u0 ;
};
:};
CLASS PI
(* class = "controller" *)
"PI controller"
// The value of the manipulated variabele changes proportional to the value
// of the error signal and to the value of the integral of the error function
// in time.
SPECIALISES
PhysicalDAEModelType :=
{:
comments <- "A model for a proportional-integral controller";
interface <-
{
OBJ y_M (* terminal = "in_1" *) "Sensor measured output" :
Real := {: causality <- "CIN" :};
OBJ u (* terminal = "out_1" *) "Controlled variable" :
Real := {: causality <- "COUT" :};
};
parameters <-
{
OBJ u0 "No error action" : Real := {: value <- 50 :};
OBJ y_S "Setpoint value for controlled variable" :
Real := {: value <- 2 :};
OBJ K_P "Factor of proportionality" :
Real := {: value <- 25 :};
OBJ T_I "Integral time" : Time := {: value <- 0.1 :};
};
independent <-
{
OBJ t "Time": Time ;
};
state <-
{
OBJ e "Error" : PhysicalQuantityType ;
OBJ Integ_e "Integral of error" : PhysicalQuantityType ;
};
equations <-
{
{state.e = parameters.y_S - interface.y_M;};
{DERIV(state.Integ_e,[independent.t]) = state.e;};
{interface.u = parameters.K_P *
(state.e + (1 / parameters.T_I) * state.Integ_e) +
parameters.u0;};
};
:};
CLASS PID
(* class = "controller" *)
"PID controller"
SPECIALISES
PhysicalDAEModelType :=
{:
comments <- "A model for a proportional-integral-derivative controller";
interface <-
{
OBJ y_M (* terminal = "in_1" *) "Sensor measured output" :
Real := {: causality <- "CIN" :};
OBJ u (* terminal = "out_1" *) "Controlled variable" :
Real := {: causality <- "COUT" :};
};
parameters <-
{
OBJ K_P "Factor of proportionality" : Real := {: value <- 11.31977725 :};
OBJ T_I "Integral time" : Time := {: value <- 0.5062161847 :};
OBJ T_D "Derivative time" : Time := {: value <- 0.2531080923 :};
OBJ y_S "Setpoint value for controlled variable" : Real := {: value <- 2 :};
OBJ u0 "No error action" : Real := {: value <- 50 :};
};
independent <-
{
OBJ t "Time": Time
};
state <-
{
OBJ Integ_e "Integral of error": PhysicalQuantityType ;
OBJ e "Error" : PhysicalQuantityType ;
OBJ help (* hidden = "1" *) " Previous time help variable" : Time;
OBJ Deriv_e "Derivative of error" : Real;
OBJ Prev_t (* hidden = "1" *) : Time;
};
equations <-
{
state.e = parameters.y_S - interface.y_M;
state.help = independent.t;
state.Deriv_e = IF (state.help == 0)
THEN 0
ELSE (previous(state.e) - state.e) / (previous(state.help) - state.help);
DERIV(state.Integ_e, [independent.t]) = state.e ;
interface.u = parameters.u0 +
parameters.K_P * (
state.e +
parameters.T_D * state.Deriv_e +
state.Integ_e / parameters.T_I);
};
:};
CLASS ConstantRatio
(* class = "controller" *)
"Ratio controller"
// The value of the manipulated variabele is a ratio of the measured value
SPECIALISES
PhysicalDAEModelType :=
{:
comments <- "A model for a ratio controller";
interface <-
{
OBJ y_M (* terminal = "in_1" *) "Sensor measured output" :
Real := {: causality <- "CIN" :};
OBJ u (* terminal = "out_1" *) "Controlled variable" :
Real := {: causality <- "COUT" :};
};
parameters <-
{
OBJ ConstantRatio "Ratio between measured value and controller output" :
Real := {: value <- 1 :};
};
equations <-
{
interface.u = parameters.ConstantRatio * interface.y_M;
};
:};
CLASS OnOff
(* class = "controller" *)
"On-off controller"
// Purpose:
// Switch output between two values.
//
// Description:
// The relay block allows the output to switch between two specified values.
// When the relay is on, it remains on until the input drops below the
// specified value of 'Input for off'. When the relay is off, it remains off
// until the input exceeds the specified value of 'Input for on'.
// Selecting an 'Input for on' value greater than the 'Input for off' value
// models hysteresis, whereas selecting equal values models a switch with a
// threshold at that value. The model for an ideal on/off controller is a
// simplification of this model. Note that an ideal on/off controller can
// cause oscillations of the error signal. An 'Input for on' value which is
// smaller than the 'Input for off' value is not allowed.
SPECIALISES
PhysicalDAEModelType :=
{:
comments <- "A model for an on-off controller";
interface <-
{
OBJ y_M (* terminal = "in_1" *) "Sensor measured output" :
Real := {: causality <- "CIN" :};
OBJ u (* terminal = "out_1" *) "Controlled variable" :
Real := {: causality <- "COUT" :};
};
parameters <-
{
OBJ y_S "Setpoint value for controlled variable" :
Real := {: value <- 2 :};
OBJ e_Off "Input for off" : Real := {: value <- -0.5;
interval <- {: lowerBound <- MIN_INF; upperBound <-0 ; :};
:};
OBJ e_On "Input for on" : Real := {: value <- 0.5;
interval <- {: lowerBound <- 0; upperBound <- PLUS_INF; :};
:};
OBJ u_Off "Output when off" : Real := {: value <- 10 :};
OBJ u_On "Output when on" : Real := {: value <- 20 :};
// e1 <= e2
};
independent <-
{
OBJ t "Time": Time ;
};
state <-
{
OBJ e "Error" : PhysicalQuantityType ;
OBJ help_u (* hidden = "1" *) "Previous u help variable" : Real;
OBJ help_t (* hidden = "1" *) "Previous t help variable" : Real;
};
equations <-
{
{state.e = parameters.y_S - interface.y_M;};
state.help_u = interface.u;
state.help_t = independent.t;
interface.u = IF(state.e < parameters.e_Off)
THEN parameters.u_Off
ELSE
IF (state.e > parameters.e_On)
THEN parameters.u_On
ELSE
IF (previous(state.help_t) >= independent.t)
THEN parameters.u_On
ELSE previous(state.help_u) ;
};
:};
#endif // ELAFISH_BASE_CONTROLLERS