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 | * Author: Tiago Osório |
---|
16 | * $Id: PIDIncr.mso 306 2007-07-05 01:34:37Z arge $ |
---|
17 | *-------------------------------------------------------------------*# |
---|
18 | using "types"; |
---|
19 | |
---|
20 | Model MParameters |
---|
21 | |
---|
22 | ATTRIBUTES |
---|
23 | Pallete = false; |
---|
24 | Brief = "Model of Parameters to be used with incremental PIDs."; |
---|
25 | |
---|
26 | VARIABLES |
---|
27 | |
---|
28 | alpha as positive (Brief="Derivative term filter constant", Default=1); |
---|
29 | beta as positive (Brief="Proportional term setPoint change filter"); |
---|
30 | bias as control_signal (Brief="Previous scaled bias", Default=0.5); |
---|
31 | derivTime as time_sec (Brief="Derivative time constant"); |
---|
32 | intTime as time_sec (Brief="Integral time constant"); |
---|
33 | gain as positive (Brief="Controller gain", Default=0.5); |
---|
34 | gamma as positive (Brief="Derivative term SP change filter"); |
---|
35 | tau as time_sec (Brief="Input filter time constant"); |
---|
36 | tauSet as time_sec (Brief="Input filter time constant"); |
---|
37 | |
---|
38 | end |
---|
39 | |
---|
40 | Model MOptions |
---|
41 | |
---|
42 | ATTRIBUTES |
---|
43 | Pallete = false; |
---|
44 | Brief = "Model of Options to be used with incremental PIDs."; |
---|
45 | |
---|
46 | VARIABLES |
---|
47 | |
---|
48 | action as Real (Brief="Controller action: (-1) Direct,(1) Reverse", Default=-1); |
---|
49 | autoMan as Real (Brief="Controller option: (0) Automatic, (1) Manual", Default=0); |
---|
50 | clip as Real (Brief="Controller option: (1) output clipped, (0) output unclipped", Default=1); |
---|
51 | |
---|
52 | end |
---|
53 | |
---|
54 | Model MPorts |
---|
55 | |
---|
56 | ATTRIBUTES |
---|
57 | Pallete = false; |
---|
58 | Brief = "Model of Ports to be used with incremental PIDs."; |
---|
59 | |
---|
60 | VARIABLES |
---|
61 | |
---|
62 | input as control_signal (Brief="Previous scaled input signal", Default=0.5); |
---|
63 | output as control_signal (Brief="Scaled output signal", Default=0.5); |
---|
64 | setPoint as control_signal (Brief="Scaled setPoint",Default=0.5); |
---|
65 | |
---|
66 | end |
---|
67 | |
---|
68 | Model MInternal_Variables |
---|
69 | |
---|
70 | ATTRIBUTES |
---|
71 | Pallete = false; |
---|
72 | Brief = "Model of Internal Variables to be used with incremental PIDs."; |
---|
73 | |
---|
74 | VARIABLES |
---|
75 | |
---|
76 | dderivTerm as control_signal (Brief="Derivative term",Unit='1/s', Default=0); |
---|
77 | dFilt as control_signal (Brief="Derivative term filtered", Default=0.5,Unit='1/s'); |
---|
78 | error as control_signal (Brief="Error definition for proportional term",Unit='1/s'); |
---|
79 | errorD as control_signal (Brief="Error definition for derivative term",Unit='1/s'); |
---|
80 | errorI as control_signal (Brief="Error definition for integral term"); |
---|
81 | inputFilt as control_signal (Brief="Filtered input"); |
---|
82 | dintTerm as control_signal (Brief="Integral term", Default=0,Unit='1/s'); |
---|
83 | doutp as control_signal (Brief="Sum of proportional, integral and derivative terms",Unit='1/s'); |
---|
84 | outps as control_signal (Brief="Variable outp scaled between -1 and 1"); |
---|
85 | outp as control_signal (Brief="Variable outp"); |
---|
86 | dpropTerm as control_signal (Brief="Proportional term", Default=0,Unit='1/s'); |
---|
87 | setPointFilt as control_signal (Brief="Filtered setPoint", Default=0); |
---|
88 | |
---|
89 | end |
---|
90 | |
---|
91 | Model PIDIncr |
---|
92 | |
---|
93 | ATTRIBUTES |
---|
94 | Pallete = true; |
---|
95 | Icon = "icon/PIDIncr"; |
---|
96 | Brief = "Model of incremental PIDs."; |
---|
97 | Info = |
---|
98 | " |
---|
99 | - Inputs |
---|
100 | * - a scaled processs variable. |
---|
101 | * - a scaled bias. |
---|
102 | * - a scaled setpoint. |
---|
103 | |
---|
104 | - Outputs |
---|
105 | * - a scaled output. |
---|
106 | "; |
---|
107 | |
---|
108 | PARAMETERS |
---|
109 | |
---|
110 | PID_Select as Switcher (Brief="Type of PID Incremental", Valid=["Ideal","Parallel","Series","Ideal_AWBT","Parallel_AWBT","Series_AWBT","Ideal_AW","Parallel_AW","Series_AW"], Default = "Ideal"); |
---|
111 | |
---|
112 | VARIABLES |
---|
113 | Parameters as MParameters; |
---|
114 | Options as MOptions; |
---|
115 | Internal as MInternal_Variables; |
---|
116 | Ports as MPorts; |
---|
117 | AWFactor as Real (Brief="Integral term multiplier used in anti-reset windup"); |
---|
118 | |
---|
119 | EQUATIONS |
---|
120 | |
---|
121 | if (Parameters.tau equal 0) then |
---|
122 | "Input first order filter" |
---|
123 | (Parameters.tau + 1e-3*'s')*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt; |
---|
124 | else |
---|
125 | "Input first order filter" |
---|
126 | Parameters.tau*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt; |
---|
127 | end |
---|
128 | |
---|
129 | if (Parameters.tauSet equal 0) then |
---|
130 | "setPoint first order filter" |
---|
131 | (Parameters.tauSet + 1e-3*'s')*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt; |
---|
132 | else |
---|
133 | "setPoint first order filter" |
---|
134 | Parameters.tauSet*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt; |
---|
135 | end |
---|
136 | |
---|
137 | if Options.autoMan equal 1 then |
---|
138 | "Error definition for proportional term" |
---|
139 | Internal.error*'s' = Internal.inputFilt*(Parameters.beta-1.0); |
---|
140 | "Error definition for derivative term" |
---|
141 | Internal.errorD*'s'= Internal.inputFilt*(Parameters.gamma-1.0); |
---|
142 | "Error definition for integral term" |
---|
143 | Internal.errorI= 0; |
---|
144 | else |
---|
145 | "Error definition for proportional term" |
---|
146 | Internal.error = Parameters.beta*diff(Internal.setPointFilt) - diff(Internal.inputFilt); |
---|
147 | "Error definition for derivative term" |
---|
148 | Internal.errorD = Parameters.gamma*diff(Internal.setPointFilt) - diff(Internal.inputFilt); |
---|
149 | "Error definition for integral term" |
---|
150 | Internal.errorI = Internal.setPointFilt-Internal.inputFilt; |
---|
151 | end |
---|
152 | |
---|
153 | "Calculate proportional term" |
---|
154 | Internal.dpropTerm=Internal.error; |
---|
155 | |
---|
156 | if (Parameters.derivTime equal 0) then |
---|
157 | "Derivative term filter" |
---|
158 | Parameters.alpha*(Parameters.derivTime + 1e-3*'s')*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt; |
---|
159 | else |
---|
160 | "Derivative term filter" |
---|
161 | Parameters.alpha*(Parameters.derivTime)*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt; |
---|
162 | end |
---|
163 | |
---|
164 | "Calculate derivative term" |
---|
165 | Internal.dderivTerm = Parameters.derivTime*diff(Internal.dFilt); |
---|
166 | |
---|
167 | "Unscaled output" |
---|
168 | diff(Internal.outp)=Internal.doutp; |
---|
169 | |
---|
170 | "Scale outp" |
---|
171 | Internal.outps=2*Internal.outp-1; |
---|
172 | |
---|
173 | if Options.clip equal 1 then |
---|
174 | if abs(Internal.outps)>1 then |
---|
175 | "Calculate clipped output when it´s saturated" |
---|
176 | Ports.output=(sign(Internal.outps)*1+1)/2; |
---|
177 | else |
---|
178 | "Calculate clipped output when it´s not saturated" |
---|
179 | Ports.output=Internal.outp; |
---|
180 | end |
---|
181 | else |
---|
182 | "Calculate unclipped output" |
---|
183 | Ports.output=Internal.outp; |
---|
184 | end |
---|
185 | |
---|
186 | switch PID_Select |
---|
187 | |
---|
188 | case "Ideal": |
---|
189 | |
---|
190 | "Calculate integral term" |
---|
191 | Parameters.intTime*Internal.dintTerm = Internal.errorI; |
---|
192 | |
---|
193 | "Sum of proportional, integral and derivative terms" |
---|
194 | Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
195 | |
---|
196 | "Calculate AWFactor - Not in use in this mode" |
---|
197 | AWFactor=1; |
---|
198 | |
---|
199 | case "Parallel": |
---|
200 | |
---|
201 | "Calculate integral term" |
---|
202 | Parameters.intTime*Internal.dintTerm = Internal.errorI; |
---|
203 | |
---|
204 | "Sum of proportional, integral and derivative terms" |
---|
205 | Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
206 | |
---|
207 | "Calculate AWFactor - Not in use in this mode" |
---|
208 | AWFactor=1; |
---|
209 | |
---|
210 | case "Series": |
---|
211 | |
---|
212 | "Calculate integral term" |
---|
213 | Parameters.intTime*Internal.dintTerm = Internal.errorI; |
---|
214 | |
---|
215 | "Sum of proportional, integral and derivative terms" |
---|
216 | Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s'); |
---|
217 | |
---|
218 | "Calculate AWFactor - Not in use in this mode" |
---|
219 | AWFactor=1; |
---|
220 | |
---|
221 | case "Ideal_AWBT": |
---|
222 | |
---|
223 | "Calculate integral term with anti-windup and bumpless transfer" |
---|
224 | Options.action*Parameters.gain*(Parameters.intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp; |
---|
225 | |
---|
226 | "Sum of proportional, integral and derivative terms" |
---|
227 | Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
228 | |
---|
229 | "Calculate AWFactor - Not in use in this mode" |
---|
230 | AWFactor=1; |
---|
231 | |
---|
232 | case "Parallel_AWBT": |
---|
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 + Internal.dderivTerm); |
---|
239 | |
---|
240 | "Calculate AWFactor - Not in use in this mode" |
---|
241 | AWFactor=1; |
---|
242 | |
---|
243 | case "Series_AWBT": |
---|
244 | |
---|
245 | "Calculate integral term with anti-windup and bumpless transfer" |
---|
246 | Options.action*Parameters.gain*(Parameters.intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp; |
---|
247 | |
---|
248 | "Sum of proportional, integral and derivative terms" |
---|
249 | Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s'); |
---|
250 | |
---|
251 | "Calculate AWFactor - Not in use in this mode" |
---|
252 | AWFactor=1; |
---|
253 | |
---|
254 | case "Ideal_AW": |
---|
255 | |
---|
256 | "Calculate integral term with anti-windup" |
---|
257 | Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI; |
---|
258 | |
---|
259 | "Sum of proportional, integral and derivative terms" |
---|
260 | Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
261 | |
---|
262 | if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then |
---|
263 | "Calculate AWFactor" |
---|
264 | AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102); |
---|
265 | else |
---|
266 | "Calculate AWFactor" |
---|
267 | AWFactor=1; |
---|
268 | end |
---|
269 | |
---|
270 | case "Parallel_AW": |
---|
271 | |
---|
272 | "Calculate integral term with anti-windup" |
---|
273 | Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI; |
---|
274 | |
---|
275 | "Sum of proportional, integral and derivative terms" |
---|
276 | Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
277 | |
---|
278 | if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then |
---|
279 | "Calculate AWFactor" |
---|
280 | AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102); |
---|
281 | else |
---|
282 | "Calculate AWFactor" |
---|
283 | AWFactor=1; |
---|
284 | end |
---|
285 | |
---|
286 | case "Series_AW": |
---|
287 | |
---|
288 | "Calculate integral term with anti-windup" |
---|
289 | Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI; |
---|
290 | |
---|
291 | "Sum of proportional, integral and derivative terms" |
---|
292 | Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s'); |
---|
293 | |
---|
294 | if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then |
---|
295 | "Calculate AWFactor" |
---|
296 | AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102); |
---|
297 | else |
---|
298 | "Calculate AWFactor" |
---|
299 | AWFactor=1; |
---|
300 | end |
---|
301 | |
---|
302 | end |
---|
303 | |
---|
304 | INITIAL |
---|
305 | Ports.output = Parameters.bias; |
---|
306 | diff(Internal.dFilt) = 0/'s^2'; |
---|
307 | diff(Internal.inputFilt)=0/'s'; |
---|
308 | diff(Internal.setPointFilt)=0/'s'; |
---|
309 | |
---|
310 | end |
---|
311 | |
---|
312 | |
---|