1 | #*------------------------------------------------------------------- |
---|
2 | * Model of incremental PIDs |
---|
3 | *-------------------------------------------------------------------- |
---|
4 | * - Inputs |
---|
5 | * - a scaled processs variable |
---|
6 | * - a scaled bias |
---|
7 | * - a scaled setpoint |
---|
8 | * |
---|
9 | * - Outputs |
---|
10 | * - a scaled output |
---|
11 | * |
---|
12 | * - Assumptions |
---|
13 | * |
---|
14 | * |
---|
15 | *-------------------------------------------------------------------- |
---|
16 | * Author: Tiago Osório |
---|
17 | * $Id: PIDIncr.mso 1 2006-06-20 17:33:53Z rafael $ |
---|
18 | *-------------------------------------------------------------------*# |
---|
19 | using "types"; |
---|
20 | |
---|
21 | Model MParameters |
---|
22 | |
---|
23 | VARIABLES |
---|
24 | |
---|
25 | alpha as positive (Brief="Derivative term filter constant", Default=1); |
---|
26 | beta as positive (Brief="Proportional term setPoint change filter"); |
---|
27 | bias as control_signal (Brief="Previous scaled bias", Default=0.5); |
---|
28 | derivTime as time_sec (Brief="Derivative time constant"); |
---|
29 | intTime as time_sec (Brief="Integral time constant"); |
---|
30 | gain as positive (Brief="Controller gain", Default=0.5); |
---|
31 | gamma as positive (Brief="Derivative term SP change filter"); |
---|
32 | tau as time_sec (Brief="Input filter time constant"); |
---|
33 | tauSet as time_sec (Brief="Input filter time constant"); |
---|
34 | |
---|
35 | end |
---|
36 | |
---|
37 | Model MOptions |
---|
38 | |
---|
39 | VARIABLES |
---|
40 | |
---|
41 | action as Real (Brief="Controller action: (-1) Direct,(1) Reverse", Default=-1); |
---|
42 | autoMan as Real (Brief="Controller option: (0) Automatic, (1) Manual", Default=0); |
---|
43 | clip as Real (Brief="Controller option: (1) output clipped, (0) output unclipped", Default=1); |
---|
44 | |
---|
45 | end |
---|
46 | |
---|
47 | Model MPorts |
---|
48 | |
---|
49 | VARIABLES |
---|
50 | |
---|
51 | input as control_signal (Brief="Previous scaled input signal", Default=0.5); |
---|
52 | output as control_signal (Brief="Scaled output signal", Default=0.5); |
---|
53 | setPoint as control_signal (Brief="Scaled setPoint",Default=0.5); |
---|
54 | |
---|
55 | end |
---|
56 | |
---|
57 | Model MInternal_Variables |
---|
58 | |
---|
59 | VARIABLES |
---|
60 | |
---|
61 | dderivTerm as control_signal (Brief="Derivative term",Unit="1/s", Default=0); |
---|
62 | dFilt as control_signal (Brief="Derivative term filtered", Default=0.5,Unit="1/s"); |
---|
63 | error as control_signal (Brief="Error definition for proportional term",Unit="1/s"); |
---|
64 | errorD as control_signal (Brief="Error definition for derivative term",Unit="1/s"); |
---|
65 | errorI as control_signal (Brief="Error definition for integral term"); |
---|
66 | inputFilt as control_signal (Brief="Filtered input"); |
---|
67 | dintTerm as control_signal (Brief="Integral term", Default=0,Unit="1/s"); |
---|
68 | doutp as control_signal (Brief="Sum of proportional, integral and derivative terms",Unit="1/s"); |
---|
69 | outps as control_signal (Brief="Variable outp scaled between -1 and 1"); |
---|
70 | outp as control_signal (Brief="Variable outp"); |
---|
71 | dpropTerm as control_signal (Brief="Proportional term", Default=0,Unit="1/s"); |
---|
72 | setPointFilt as control_signal (Brief="Filtered setPoint", Default=0); |
---|
73 | |
---|
74 | end |
---|
75 | |
---|
76 | Model PIDIncr_basic |
---|
77 | |
---|
78 | VARIABLES |
---|
79 | Parameters as MParameters; |
---|
80 | Options as MOptions; |
---|
81 | Internal as MInternal_Variables; |
---|
82 | Ports as MPorts; |
---|
83 | |
---|
84 | EQUATIONS |
---|
85 | |
---|
86 | if (Parameters.tau equal 0) then |
---|
87 | "Input first order filter" |
---|
88 | (Parameters.tau + 1e-3*"s")*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt; |
---|
89 | else |
---|
90 | "Input first order filter" |
---|
91 | Parameters.tau*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt; |
---|
92 | end |
---|
93 | |
---|
94 | if (Parameters.tauSet equal 0) then |
---|
95 | "setPoint first order filter" |
---|
96 | (Parameters.tauSet + 1e-3*"s")*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt; |
---|
97 | else |
---|
98 | "setPoint first order filter" |
---|
99 | Parameters.tauSet*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt; |
---|
100 | end |
---|
101 | |
---|
102 | if Options.autoMan equal 1 then |
---|
103 | "Error definition for proportional term" |
---|
104 | Internal.error*"s" = Internal.inputFilt*(Parameters.beta-1.0); |
---|
105 | "Error definition for derivative term" |
---|
106 | Internal.errorD*"s"= Internal.inputFilt*(Parameters.gamma-1.0); |
---|
107 | "Error definition for integral term" |
---|
108 | Internal.errorI= 0; |
---|
109 | else |
---|
110 | "Error definition for proportional term" |
---|
111 | Internal.error = Parameters.beta*diff(Internal.setPointFilt) - diff(Internal.inputFilt); |
---|
112 | "Error definition for derivative term" |
---|
113 | Internal.errorD = Parameters.gamma*diff(Internal.setPointFilt) - diff(Internal.inputFilt); |
---|
114 | "Error definition for integral term" |
---|
115 | Internal.errorI = Internal.setPointFilt-Internal.inputFilt; |
---|
116 | end |
---|
117 | |
---|
118 | "Calculate proportional term" |
---|
119 | Internal.dpropTerm=Internal.error; |
---|
120 | |
---|
121 | if (Parameters.derivTime equal 0) then |
---|
122 | "Derivative term filter" |
---|
123 | Parameters.alpha*(Parameters.derivTime + 1e-3*"s")*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt; |
---|
124 | else |
---|
125 | "Derivative term filter" |
---|
126 | Parameters.alpha*(Parameters.derivTime)*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt; |
---|
127 | end |
---|
128 | |
---|
129 | "Calculate derivative term" |
---|
130 | Internal.dderivTerm = Parameters.derivTime*diff(Internal.dFilt); |
---|
131 | |
---|
132 | "Unscaled output" |
---|
133 | diff(Internal.outp)=Internal.doutp; |
---|
134 | |
---|
135 | "Scale outp" |
---|
136 | Internal.outps=2*Internal.outp-1; |
---|
137 | |
---|
138 | if Options.clip equal 1 then |
---|
139 | if abs(Internal.outps)>1 then |
---|
140 | "Calculate clipped output when it´s saturated" |
---|
141 | Ports.output=(sign(Internal.outps)*1+1)/2; |
---|
142 | else |
---|
143 | "Calculate clipped output when it´s not saturated" |
---|
144 | Ports.output=Internal.outp; |
---|
145 | end |
---|
146 | else |
---|
147 | "Calculate unclipped output" |
---|
148 | Ports.output=Internal.outp; |
---|
149 | end |
---|
150 | |
---|
151 | INITIAL |
---|
152 | Ports.output = Parameters.bias; |
---|
153 | diff(Internal.dFilt) = 0*"1/s^2"; |
---|
154 | diff(Internal.inputFilt)=0*"1/s"; |
---|
155 | diff(Internal.setPointFilt)=0*"1/s"; |
---|
156 | end |
---|
157 | |
---|
158 | Model PIDIncr_Ideal as PIDIncr_basic |
---|
159 | |
---|
160 | EQUATIONS |
---|
161 | |
---|
162 | "Calculate integral term" |
---|
163 | Parameters.intTime*Internal.dintTerm = Internal.errorI; |
---|
164 | |
---|
165 | "Sum of proportional, integral and derivative terms" |
---|
166 | Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
167 | |
---|
168 | end |
---|
169 | |
---|
170 | Model PIDIncr_Parallel 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_Series 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)*(1*"1/s" + Internal.dderivTerm)*"s"); |
---|
191 | |
---|
192 | end |
---|
193 | |
---|
194 | Model PIDIncr_Ideal_AWBT as PIDIncr_basic |
---|
195 | |
---|
196 | EQUATIONS |
---|
197 | |
---|
198 | "Calculate integral term with anti-windup and bumpless transfer" |
---|
199 | Options.action*Parameters.gain*(Parameters.intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp; |
---|
200 | |
---|
201 | "Sum of proportional, integral and derivative terms" |
---|
202 | Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
203 | |
---|
204 | end |
---|
205 | |
---|
206 | Model PIDIncr_Parallel_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_Series_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)*(1*"1/s" + Internal.dderivTerm)*"s"); |
---|
227 | |
---|
228 | end |
---|
229 | |
---|
230 | Model PIDIncr_Ideal_AW as PIDIncr_basic |
---|
231 | |
---|
232 | VARIABLES |
---|
233 | AWFactor as Real (Brief="Integral term multiplier used in anti-reset windup"); |
---|
234 | |
---|
235 | EQUATIONS |
---|
236 | |
---|
237 | "Calculate integral term with anti-windup" |
---|
238 | Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI; |
---|
239 | |
---|
240 | "Sum of proportional, integral and derivative terms" |
---|
241 | Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
242 | |
---|
243 | |
---|
244 | if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then |
---|
245 | "Calculate AWFactor" |
---|
246 | AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102); |
---|
247 | else |
---|
248 | "Calculate AWFactor" |
---|
249 | AWFactor=1; |
---|
250 | end |
---|
251 | |
---|
252 | end |
---|
253 | |
---|
254 | Model PIDIncr_Parallel_AW as PIDIncr_basic |
---|
255 | |
---|
256 | VARIABLES |
---|
257 | AWFactor as Real (Brief="Integral term multiplier used in anti-reset windup"); |
---|
258 | |
---|
259 | EQUATIONS |
---|
260 | |
---|
261 | "Calculate integral term with anti-windup" |
---|
262 | Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI; |
---|
263 | |
---|
264 | "Sum of proportional, integral and derivative terms" |
---|
265 | Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm); |
---|
266 | |
---|
267 | if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then |
---|
268 | "Calculate AWFactor" |
---|
269 | AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102); |
---|
270 | else |
---|
271 | "Calculate AWFactor" |
---|
272 | AWFactor=1; |
---|
273 | end |
---|
274 | |
---|
275 | end |
---|
276 | |
---|
277 | Model PIDIncr_Series_AW as PIDIncr_basic |
---|
278 | |
---|
279 | VARIABLES |
---|
280 | AWFactor as Real (Brief="Integral term multiplier used in anti-reset windup"); |
---|
281 | |
---|
282 | EQUATIONS |
---|
283 | |
---|
284 | "Calculate integral term with anti-windup" |
---|
285 | Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI; |
---|
286 | |
---|
287 | "Sum of proportional, integral and derivative terms" |
---|
288 | Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1*"1/s" + Internal.dderivTerm)*"s"); |
---|
289 | |
---|
290 | if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then |
---|
291 | "Calculate AWFactor" |
---|
292 | AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102); |
---|
293 | else |
---|
294 | "Calculate AWFactor" |
---|
295 | AWFactor=1; |
---|
296 | end |
---|
297 | |
---|
298 | end |
---|
299 | |
---|