1 | #*------------------------------------------------------------------- |
---|
2 | * EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC. |
---|
3 | * |
---|
4 | * This LIBRARY is free software; you can distribute it and/or modify |
---|
5 | * it under the therms of the ALSOC FREE LICENSE as available at |
---|
6 | * http://www.enq.ufrgs.br/alsoc. |
---|
7 | * |
---|
8 | * EMSO Copyright (C) 2004 - 2007 ALSOC, original code |
---|
9 | * from http://www.rps.eng.br Copyright (C) 2002-2004. |
---|
10 | * All rights reserved. |
---|
11 | * |
---|
12 | * EMSO is distributed under the therms of the ALSOC LICENSE as |
---|
13 | * available at http://www.enq.ufrgs.br/alsoc. |
---|
14 | * |
---|
15 | *------------------------------------------------------------------- |
---|
16 | * Model of incremental PIDs |
---|
17 | *-------------------------------------------------------------------- |
---|
18 | * - Inputs |
---|
19 | * - a scaled processs variable |
---|
20 | * - a scaled bias |
---|
21 | * - a scaled setpoint |
---|
22 | * |
---|
23 | * - Outputs |
---|
24 | * - a scaled output |
---|
25 | * |
---|
26 | * |
---|
27 | *-------------------------------------------------------------------- |
---|
28 | * Author: Tiago Osório |
---|
29 | * $Id: PIDIncr.mso 74 2006-12-08 18:43:02Z paula $ |
---|
30 | *-------------------------------------------------------------------*# |
---|
31 | using "types"; |
---|
32 | |
---|
33 | Model MParameters |
---|
34 | |
---|
35 | VARIABLES |
---|
36 | |
---|
37 | alpha as positive (Brief="Derivative term filter constant", Default=1); |
---|
38 | beta as positive (Brief="Proportional term setPoint change filter"); |
---|
39 | bias as control_signal (Brief="Previous scaled bias", Default=0.5); |
---|
40 | derivTime as time_sec (Brief="Derivative time constant"); |
---|
41 | intTime as time_sec (Brief="Integral time constant"); |
---|
42 | gain as positive (Brief="Controller gain", Default=0.5); |
---|
43 | gamma as positive (Brief="Derivative term SP change filter"); |
---|
44 | tau as time_sec (Brief="Input filter time constant"); |
---|
45 | tauSet as time_sec (Brief="Input filter time constant"); |
---|
46 | |
---|
47 | end |
---|
48 | |
---|
49 | Model MOptions |
---|
50 | |
---|
51 | VARIABLES |
---|
52 | |
---|
53 | action as Real (Brief="Controller action: (-1) Direct,(1) Reverse", Default=-1); |
---|
54 | autoMan as Real (Brief="Controller option: (0) Automatic, (1) Manual", Default=0); |
---|
55 | clip as Real (Brief="Controller option: (1) output clipped, (0) output unclipped", Default=1); |
---|
56 | |
---|
57 | end |
---|
58 | |
---|
59 | Model MPorts |
---|
60 | |
---|
61 | VARIABLES |
---|
62 | |
---|
63 | input as control_signal (Brief="Previous scaled input signal", Default=0.5); |
---|
64 | output as control_signal (Brief="Scaled output signal", Default=0.5); |
---|
65 | setPoint as control_signal (Brief="Scaled setPoint",Default=0.5); |
---|
66 | |
---|
67 | end |
---|
68 | |
---|
69 | Model MInternal_Variables |
---|
70 | |
---|
71 | VARIABLES |
---|
72 | |
---|
73 | dderivTerm as control_signal (Brief="Derivative term",Unit="1/s", Default=0); |
---|
74 | dFilt as control_signal (Brief="Derivative term filtered", Default=0.5,Unit="1/s"); |
---|
75 | error as control_signal (Brief="Error definition for proportional term",Unit="1/s"); |
---|
76 | errorD as control_signal (Brief="Error definition for derivative term",Unit="1/s"); |
---|
77 | errorI as control_signal (Brief="Error definition for integral term"); |
---|
78 | inputFilt as control_signal (Brief="Filtered input"); |
---|
79 | dintTerm as control_signal (Brief="Integral term", Default=0,Unit="1/s"); |
---|
80 | doutp as control_signal (Brief="Sum of proportional, integral and derivative terms",Unit="1/s"); |
---|
81 | outps as control_signal (Brief="Variable outp scaled between -1 and 1"); |
---|
82 | outp as control_signal (Brief="Variable outp"); |
---|
83 | dpropTerm as control_signal (Brief="Proportional term", Default=0,Unit="1/s"); |
---|
84 | setPointFilt as control_signal (Brief="Filtered setPoint", Default=0); |
---|
85 | |
---|
86 | end |
---|
87 | |
---|
88 | Model PIDIncr_basic |
---|
89 | |
---|
90 | VARIABLES |
---|
91 | Parameters as MParameters; |
---|
92 | Options as MOptions; |
---|
93 | Internal as MInternal_Variables; |
---|
94 | Ports as MPorts; |
---|
95 | |
---|
96 | EQUATIONS |
---|
97 | |
---|
98 | if (Parameters.tau equal 0) then |
---|
99 | "Input first order filter" |
---|
100 | (Parameters.tau + 1e-3*"s")*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt; |
---|
101 | else |
---|
102 | "Input first order filter" |
---|
103 | Parameters.tau*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt; |
---|
104 | end |
---|
105 | |
---|
106 | if (Parameters.tauSet equal 0) then |
---|
107 | "setPoint first order filter" |
---|
108 | (Parameters.tauSet + 1e-3*"s")*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt; |
---|
109 | else |
---|
110 | "setPoint first order filter" |
---|
111 | Parameters.tauSet*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt; |
---|
112 | end |
---|
113 | |
---|
114 | if Options.autoMan equal 1 then |
---|
115 | "Error definition for proportional term" |
---|
116 | Internal.error*"s" = Internal.inputFilt*(Parameters.beta-1.0); |
---|
117 | "Error definition for derivative term" |
---|
118 | Internal.errorD*"s"= Internal.inputFilt*(Parameters.gamma-1.0); |
---|
119 | "Error definition for integral term" |
---|
120 | Internal.errorI= 0; |
---|
121 | else |
---|
122 | "Error definition for proportional term" |
---|
123 | Internal.error = Parameters.beta*diff(Internal.setPointFilt) - diff(Internal.inputFilt); |
---|
124 | "Error definition for derivative term" |
---|
125 | Internal.errorD = Parameters.gamma*diff(Internal.setPointFilt) - diff(Internal.inputFilt); |
---|
126 | "Error definition for integral term" |
---|
127 | Internal.errorI = Internal.setPointFilt-Internal.inputFilt; |
---|
128 | end |
---|
129 | |
---|
130 | "Calculate proportional term" |
---|
131 | Internal.dpropTerm=Internal.error; |
---|
132 | |
---|
133 | if (Parameters.derivTime equal 0) then |
---|
134 | "Derivative term filter" |
---|
135 | Parameters.alpha*(Parameters.derivTime + 1e-3*"s")*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt; |
---|
136 | else |
---|
137 | "Derivative term filter" |
---|
138 | Parameters.alpha*(Parameters.derivTime)*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt; |
---|
139 | end |
---|
140 | |
---|
141 | "Calculate derivative term" |
---|
142 | Internal.dderivTerm = Parameters.derivTime*diff(Internal.dFilt); |
---|
143 | |
---|
144 | "Unscaled output" |
---|
145 | diff(Internal.outp)=Internal.doutp; |
---|
146 | |
---|
147 | "Scale outp" |
---|
148 | Internal.outps=2*Internal.outp-1; |
---|
149 | |
---|
150 | if Options.clip equal 1 then |
---|
151 | if abs(Internal.outps)>1 then |
---|
152 | "Calculate clipped output when it´s saturated" |
---|
153 | Ports.output=(sign(Internal.outps)*1+1)/2; |
---|
154 | else |
---|
155 | "Calculate clipped output when it´s not saturated" |
---|
156 | Ports.output=Internal.outp; |
---|
157 | end |
---|
158 | else |
---|
159 | "Calculate unclipped output" |
---|
160 | Ports.output=Internal.outp; |
---|
161 | end |
---|
162 | |
---|
163 | INITIAL |
---|
164 | Ports.output = Parameters.bias; |
---|
165 | diff(Internal.dFilt) = 0*"1/s^2"; |
---|
166 | diff(Internal.inputFilt)=0*"1/s"; |
---|
167 | diff(Internal.setPointFilt)=0*"1/s"; |
---|
168 | end |
---|
169 | |
---|
170 | Model PIDIncr_Ideal as PIDIncr_basic |
---|
171 | |
---|
172 | EQUATIONS |
---|
173 | |
---|
174 | "Calculate integral term" |
---|
175 | Parameters.intTime*Internal.dintTerm = Internal.errorI; |
---|
176 | |
---|
177 | "Sum of proportional, integral and derivative terms" |
---|
178 | Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
179 | |
---|
180 | end |
---|
181 | |
---|
182 | Model PIDIncr_Parallel as PIDIncr_basic |
---|
183 | |
---|
184 | EQUATIONS |
---|
185 | |
---|
186 | "Calculate integral term" |
---|
187 | Parameters.intTime*Internal.dintTerm = Internal.errorI; |
---|
188 | |
---|
189 | "Sum of proportional, integral and derivative terms" |
---|
190 | Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
191 | |
---|
192 | end |
---|
193 | |
---|
194 | Model PIDIncr_Series as PIDIncr_basic |
---|
195 | |
---|
196 | EQUATIONS |
---|
197 | |
---|
198 | "Calculate integral term" |
---|
199 | Parameters.intTime*Internal.dintTerm = Internal.errorI; |
---|
200 | |
---|
201 | "Sum of proportional, integral and derivative terms" |
---|
202 | Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1*"1/s" + Internal.dderivTerm)*"s"); |
---|
203 | |
---|
204 | end |
---|
205 | |
---|
206 | Model PIDIncr_Ideal_AWBT as PIDIncr_basic |
---|
207 | |
---|
208 | EQUATIONS |
---|
209 | |
---|
210 | "Calculate integral term with anti-windup and bumpless transfer" |
---|
211 | Options.action*Parameters.gain*(Parameters.intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp; |
---|
212 | |
---|
213 | "Sum of proportional, integral and derivative terms" |
---|
214 | Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
215 | |
---|
216 | end |
---|
217 | |
---|
218 | Model PIDIncr_Parallel_AWBT as PIDIncr_basic |
---|
219 | |
---|
220 | EQUATIONS |
---|
221 | |
---|
222 | "Calculate integral term with anti-windup and bumpless transfer" |
---|
223 | Options.action*Parameters.gain*(Parameters.intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp; |
---|
224 | |
---|
225 | "Sum of proportional, integral and derivative terms" |
---|
226 | Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
227 | |
---|
228 | end |
---|
229 | |
---|
230 | Model PIDIncr_Series_AWBT as PIDIncr_basic |
---|
231 | |
---|
232 | EQUATIONS |
---|
233 | |
---|
234 | "Calculate integral term with anti-windup and bumpless transfer" |
---|
235 | Options.action*Parameters.gain*(Parameters.intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp; |
---|
236 | |
---|
237 | "Sum of proportional, integral and derivative terms" |
---|
238 | Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1*"1/s" + Internal.dderivTerm)*"s"); |
---|
239 | |
---|
240 | end |
---|
241 | |
---|
242 | Model PIDIncr_Ideal_AW as PIDIncr_basic |
---|
243 | |
---|
244 | VARIABLES |
---|
245 | AWFactor as Real (Brief="Integral term multiplier used in anti-reset windup"); |
---|
246 | |
---|
247 | EQUATIONS |
---|
248 | |
---|
249 | "Calculate integral term with anti-windup" |
---|
250 | Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI; |
---|
251 | |
---|
252 | "Sum of proportional, integral and derivative terms" |
---|
253 | Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
254 | |
---|
255 | |
---|
256 | if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then |
---|
257 | "Calculate AWFactor" |
---|
258 | AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102); |
---|
259 | else |
---|
260 | "Calculate AWFactor" |
---|
261 | AWFactor=1; |
---|
262 | end |
---|
263 | |
---|
264 | end |
---|
265 | |
---|
266 | Model PIDIncr_Parallel_AW as PIDIncr_basic |
---|
267 | |
---|
268 | VARIABLES |
---|
269 | AWFactor as Real (Brief="Integral term multiplier used in anti-reset windup"); |
---|
270 | |
---|
271 | EQUATIONS |
---|
272 | |
---|
273 | "Calculate integral term with anti-windup" |
---|
274 | Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI; |
---|
275 | |
---|
276 | "Sum of proportional, integral and derivative terms" |
---|
277 | Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
278 | |
---|
279 | if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then |
---|
280 | "Calculate AWFactor" |
---|
281 | AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102); |
---|
282 | else |
---|
283 | "Calculate AWFactor" |
---|
284 | AWFactor=1; |
---|
285 | end |
---|
286 | |
---|
287 | end |
---|
288 | |
---|
289 | Model PIDIncr_Series_AW as PIDIncr_basic |
---|
290 | |
---|
291 | VARIABLES |
---|
292 | AWFactor as Real (Brief="Integral term multiplier used in anti-reset windup"); |
---|
293 | |
---|
294 | EQUATIONS |
---|
295 | |
---|
296 | "Calculate integral term with anti-windup" |
---|
297 | Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI; |
---|
298 | |
---|
299 | "Sum of proportional, integral and derivative terms" |
---|
300 | Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1*"1/s" + Internal.dderivTerm)*"s"); |
---|
301 | |
---|
302 | if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then |
---|
303 | "Calculate AWFactor" |
---|
304 | AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102); |
---|
305 | else |
---|
306 | "Calculate AWFactor" |
---|
307 | AWFactor=1; |
---|
308 | end |
---|
309 | |
---|
310 | end |
---|
311 | |
---|