1 | #*------------------------------------------------------------------- |
---|
2 | * Model of 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: pids.mso 1 2006-06-20 17:33:53Z rafael $ |
---|
18 | *-------------------------------------------------------------------*# |
---|
19 | using "types"; |
---|
20 | |
---|
21 | Model PID_basic |
---|
22 | |
---|
23 | PARAMETERS |
---|
24 | bias as positive (Brief="Previous scaled bias", Lower=0, Upper=1, Default=0.5); |
---|
25 | alpha as positive (Brief="Derivative term filter constant", Default=1); |
---|
26 | beta as positive (Brief="Proportional term setPoint change filter"); |
---|
27 | gamma as positive (Brief="Derivative term SP change filter"); |
---|
28 | action as Real (Brief="Controller action: (-1) Direct,(1) Reverse", Default=-1); |
---|
29 | |
---|
30 | VARIABLES |
---|
31 | gain as positive (Brief="Controller gain", Lower=0, Upper=1, Default=0.5); |
---|
32 | derivTime as Real (Brief="Derivative time constant", Unit="s"); |
---|
33 | intTime as Real (Brief="Integral time constant", Unit="s"); |
---|
34 | autoMan as Real (Brief="Controller option: (0) Automatic, (1) Manual"); |
---|
35 | input as control_signal (Brief="Previous scaled input signal", Default=0.5); |
---|
36 | setPoint as Real (Brief="Scaled setPoint", Lower=0, Upper=1, Default=0.5); |
---|
37 | dFilt as Real (Brief="Derivative term filter constant", Default=0.5); |
---|
38 | derivTerm as Real (Brief="Derivative term", Default=0); |
---|
39 | propTerm as Real (Brief="Proportional term", Default=0); |
---|
40 | intTerm as Real (Brief="Integral term", Default=0); |
---|
41 | output as control_signal (Brief="Scaled output signal", Default=0); |
---|
42 | outp as control_signal (Brief="Sum of proportional, integral and derivative terms"); |
---|
43 | error as Real (Brief="Error definition for proportional term"); |
---|
44 | errorD as Real (Brief="Error definition for derivative term"); |
---|
45 | outps as Real (Brief="Variable outp scaled between -1 and 1"); |
---|
46 | clip as Real (Brief="Controller option: (1) output clipped, (0) output unclipped"); |
---|
47 | |
---|
48 | EQUATIONS |
---|
49 | |
---|
50 | |
---|
51 | if autoMan equal 0 then |
---|
52 | "Error definition" |
---|
53 | error = beta*setPoint - input; |
---|
54 | errorD= gamma*setPoint - input; |
---|
55 | else |
---|
56 | "Error definition" |
---|
57 | error = input*(beta-1.0); |
---|
58 | errorD= input*(gamma-1.0); |
---|
59 | end |
---|
60 | |
---|
61 | "Calculate proportional term" |
---|
62 | propTerm=error; |
---|
63 | |
---|
64 | if (derivTime equal 0) then |
---|
65 | "Derivative term filter" |
---|
66 | alpha*(derivTime + 1*"s")*diff(dFilt) = errorD - dFilt; |
---|
67 | else |
---|
68 | "Derivative term filter" |
---|
69 | alpha*(derivTime)*diff(dFilt) = errorD - dFilt; |
---|
70 | end |
---|
71 | |
---|
72 | "Calculate derivative term" |
---|
73 | derivTerm = derivTime*diff(dFilt); |
---|
74 | |
---|
75 | "Scale outp" |
---|
76 | outps=2*outp-1; |
---|
77 | |
---|
78 | if clip equal 1 then |
---|
79 | if abs(outps)>1 then |
---|
80 | "Calculate output" |
---|
81 | output=(sign(outps)*1+1)/2; |
---|
82 | else |
---|
83 | "Calculate output" |
---|
84 | output=outp; |
---|
85 | end |
---|
86 | else |
---|
87 | "Calculate output" |
---|
88 | output=outp; |
---|
89 | end |
---|
90 | |
---|
91 | INITIAL |
---|
92 | intTerm = 0; |
---|
93 | diff(dFilt) = 0*"1/s"; |
---|
94 | |
---|
95 | end |
---|
96 | |
---|
97 | |
---|
98 | Model PID_Ideal_AW as PID_basic |
---|
99 | |
---|
100 | VARIABLES |
---|
101 | AWFactor as Real (Brief="Integral term multiplier used in anti-reset windup"); |
---|
102 | |
---|
103 | EQUATIONS |
---|
104 | |
---|
105 | "Calculate integral term with anti-windup" |
---|
106 | intTime*diff(intTerm) = AWFactor*(setPoint - input); |
---|
107 | |
---|
108 | "Sum of proportional, integral and derivative terms" |
---|
109 | outp = bias + action*gain*(propTerm + intTerm + derivTerm); |
---|
110 | |
---|
111 | if abs(outps)>1 and (action*sign(outps)*(setPoint-input))>0 then |
---|
112 | "Calculate AWFactor" |
---|
113 | AWFactor=-tanh(sign(outps)*outps*100-102); |
---|
114 | else |
---|
115 | "Calculate AWFactor" |
---|
116 | AWFactor=1; |
---|
117 | end |
---|
118 | end |
---|
119 | |
---|
120 | Model PID_Parallel_AW as PID_basic |
---|
121 | |
---|
122 | VARIABLES |
---|
123 | AWFactor as Real (Brief="Integral term multiplier used in anti-reset windup"); |
---|
124 | |
---|
125 | EQUATIONS |
---|
126 | |
---|
127 | "Calculate integral term with anti-windup" |
---|
128 | intTime*diff(intTerm) = AWFactor*(setPoint - input); |
---|
129 | |
---|
130 | "Sum of proportional, integral and derivative terms" |
---|
131 | outp = bias + action*(gain*propTerm + intTerm + derivTerm); |
---|
132 | |
---|
133 | if abs(outps)>1 and (action*sign(outps)*(setPoint-input))>0 then |
---|
134 | "Calculate AWFactor" |
---|
135 | AWFactor=-tanh(sign(outps)*outps*100-102); |
---|
136 | else |
---|
137 | "Calculate AWFactor" |
---|
138 | AWFactor=1; |
---|
139 | end |
---|
140 | end |
---|
141 | |
---|
142 | Model PID_Series_AW as PID_basic |
---|
143 | |
---|
144 | VARIABLES |
---|
145 | AWFactor as Real (Brief="Integral term multiplier used in anti-reset windup"); |
---|
146 | |
---|
147 | EQUATIONS |
---|
148 | |
---|
149 | "Calculate integral term with anti-windup" |
---|
150 | intTime*diff(intTerm) = AWFactor*(setPoint - input); |
---|
151 | |
---|
152 | "Sum of proportional, integral and derivative terms" |
---|
153 | outp = bias + action*(gain*(propTerm + intTerm)*(1 + derivTerm)); |
---|
154 | |
---|
155 | if abs(outps)>1 and (action*sign(outps)*(setPoint-input))>0 then |
---|
156 | "Calculate AWFactor" |
---|
157 | AWFactor=-tanh(sign(outps)*outps*100-102); |
---|
158 | else |
---|
159 | "Calculate AWFactor" |
---|
160 | AWFactor=1; |
---|
161 | end |
---|
162 | end |
---|
163 | |
---|
164 | Model PID_Ideal as PID_basic |
---|
165 | |
---|
166 | EQUATIONS |
---|
167 | |
---|
168 | "Calculate integral term" |
---|
169 | intTime*diff(intTerm) = setPoint - input; |
---|
170 | |
---|
171 | "Sum of proportional, integral and derivative terms" |
---|
172 | outp = bias + action*gain*(propTerm + intTerm + derivTerm); |
---|
173 | |
---|
174 | end |
---|
175 | |
---|
176 | Model PID_Parallel as PID_basic |
---|
177 | |
---|
178 | EQUATIONS |
---|
179 | |
---|
180 | "Calculate integral term" |
---|
181 | intTime*diff(intTerm) = setPoint - input; |
---|
182 | |
---|
183 | "Sum of proportional, integral and derivative terms" |
---|
184 | outp = bias + action*(gain*propTerm + intTerm + derivTerm); |
---|
185 | |
---|
186 | end |
---|
187 | |
---|
188 | Model PID_Series as PID_basic |
---|
189 | |
---|
190 | EQUATIONS |
---|
191 | |
---|
192 | "Calculate integral term with anti-windup" |
---|
193 | intTime*diff(intTerm) = setPoint - input; |
---|
194 | |
---|
195 | "Sum of proportional, integral and derivative terms" |
---|
196 | outp = bias + action*(gain*(propTerm + intTerm)*(1 + derivTerm)); |
---|
197 | |
---|
198 | end |
---|
199 | |
---|
200 | Model PID_Ideal_AWBT as PID_basic |
---|
201 | |
---|
202 | EQUATIONS |
---|
203 | |
---|
204 | "Calculate integral term with anti-windup and bumpless transfer" |
---|
205 | action*gain*(intTime*diff(intTerm)-(setPoint-input)) = output-outp; |
---|
206 | |
---|
207 | "Sum of proportional, integral and derivative terms" |
---|
208 | outp = bias + action*gain*(propTerm + intTerm + derivTerm); |
---|
209 | |
---|
210 | end |
---|
211 | |
---|
212 | Model PID_Parallel_AWBT as PID_basic |
---|
213 | |
---|
214 | EQUATIONS |
---|
215 | |
---|
216 | "Calculate integral term with anti-windup and bumpless transfer" |
---|
217 | action*gain*(intTime*diff(intTerm)-(setPoint-input)) = output-outp; |
---|
218 | |
---|
219 | "Sum of proportional, integral and derivative terms" |
---|
220 | outp = bias + action*(gain*propTerm + intTerm + derivTerm); |
---|
221 | |
---|
222 | end |
---|
223 | |
---|
224 | Model PID_Series_AWBT as PID_basic |
---|
225 | |
---|
226 | EQUATIONS |
---|
227 | |
---|
228 | "Calculate integral term with anti-windup and bumpless transfer" |
---|
229 | action*gain*(intTime*diff(intTerm)-(setPoint-input)) = output-outp; |
---|
230 | |
---|
231 | "Sum of proportional, integral and derivative terms" |
---|
232 | outp = bias + action*(gain*(propTerm + intTerm)*(1 + derivTerm)); |
---|
233 | |
---|
234 | end |
---|