source: branches/newlanguage/eml/controllers/PIDs.mso @ 144

Last change on this file since 144 was 74, checked in by Paula Bettio Staudt, 16 years ago

Updated controllers files header

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.6 KB
Line 
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 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: PIDs.mso 74 2006-12-08 18:43:02Z paula $
30*-------------------------------------------------------------------*#
31using "types";
32
33Model 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
47end
48
49Model 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
57end
58
59Model 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
67end
68
69Model MInternal_Variables
70       
71        VARIABLES
72
73        derivTerm  as control_signal (Brief="Derivative term", Default=0);
74        dFilt      as control_signal (Brief="Derivative term filtered", Default=0.5);
75        error      as control_signal (Brief="Error definition for proportional term");
76        errorD     as control_signal (Brief="Error definition for derivative term");
77        errorI     as control_signal (Brief="Error definition for integral term");
78        inputFilt  as control_signal (Brief="Filtered input");
79        intTerm    as control_signal (Brief="Integral term", Default=0);
80        outp       as control_signal (Brief="Sum of proportional, integral and derivative terms");
81        outps      as control_signal (Brief="Variable outp scaled between -1 and 1");
82        propTerm   as control_signal (Brief="Proportional term", Default=0);
83        setPointFilt  as control_signal (Brief="Filtered setPoint", Default=0);
84
85end
86
87Model PID_basic
88
89        VARIABLES
90        Parameters         as MParameters;
91        Options            as MOptions;
92        Internal           as MInternal_Variables;
93        Ports              as MPorts;
94       
95        EQUATIONS
96
97        if (Parameters.tau equal 0) then
98                "Input first order filter"
99                (Parameters.tau + 1e-3*"s")*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;
100        else
101                "Input first order filter"
102                Parameters.tau*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;     
103        end
104
105        if (Parameters.tauSet equal 0) then
106                "setPoint first order filter"
107                (Parameters.tauSet + 1e-3*"s")*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
108        else
109                "setPoint first order filter"
110                Parameters.tauSet*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
111        end
112       
113        if Options.autoMan equal 1 then
114                "Error definition for proportional term"
115                Internal.error = Internal.inputFilt*(Parameters.beta-1.0);
116                "Error definition for derivative term"
117                Internal.errorD= Internal.inputFilt*(Parameters.gamma-1.0);
118                "Error definition for integral term"           
119                Internal.errorI= 0;
120        else
121                "Error definition for proportional term"                       
122                Internal.error = Parameters.beta*Internal.setPointFilt - Internal.inputFilt;
123                "Error definition for derivative term"
124                Internal.errorD = Parameters.gamma*Internal.setPointFilt - Internal.inputFilt;
125                "Error definition for integral term"
126                Internal.errorI = Internal.setPointFilt-Internal.inputFilt;
127        end
128       
129        "Calculate proportional term"
130        Internal.propTerm=Internal.error;
131       
132        if (Parameters.derivTime equal 0) then
133                "Derivative term filter"       
134                Parameters.alpha*(Parameters.derivTime + 1e-3*"s")*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
135        else
136                "Derivative term filter"       
137                Parameters.alpha*(Parameters.derivTime)*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
138        end
139
140        "Calculate derivative term"
141        Internal.derivTerm = Parameters.derivTime*diff(Internal.dFilt);
142       
143        "Scale outp"
144        Internal.outps=2*Internal.outp-1;
145       
146        if Options.clip equal 1 then
147                if abs(Internal.outps)>1 then
148                        "Calculate clipped output when it´s saturated"
149                        Ports.output=(sign(Internal.outps)*1+1)/2;
150                else
151                        "Calculate clipped output when it´s not saturated"
152                        Ports.output=Internal.outp;
153                end
154        else
155                "Calculate unclipped output"
156                Ports.output=Internal.outp;
157        end
158
159        INITIAL
160        Internal.intTerm = 0;
161        diff(Internal.dFilt) = 0*"1/s";
162        diff(Internal.inputFilt) = 0*"1/s";
163        diff(Internal.setPointFilt) = 0*"1/s";
164end
165
166
167Model PID_Ideal_AW as PID_basic
168       
169        VARIABLES
170        AWFactor     as Real     (Brief="Integral term multiplier used in anti-reset windup");
171
172        EQUATIONS
173       
174        "Calculate integral term with anti-windup"
175        Parameters.intTime*diff(Internal.intTerm) = AWFactor*Internal.errorI;
176       
177        "Sum of proportional, integral and derivative terms"
178        Internal.outp = Parameters.bias + Options.action*Parameters.gain*(Internal.propTerm + Internal.intTerm + Internal.derivTerm);
179
180        if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then
181                "Calculate AWFactor"
182                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
183        else
184                "Calculate AWFactor"
185                AWFactor=1;
186        end
187end
188
189Model PID_Parallel_AW as PID_basic
190       
191        VARIABLES
192        AWFactor     as Real     (Brief="Integral term multiplier used in anti-reset windup");
193
194        EQUATIONS
195       
196        "Calculate integral term with anti-windup"
197        Parameters.intTime*diff(Internal.intTerm) = AWFactor*Internal.errorI;
198       
199        "Sum of proportional, integral and derivative terms"
200        Internal.outp = Parameters.bias + Options.action*(Parameters.gain*Internal.propTerm + Internal.intTerm + Internal.derivTerm);
201
202        if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then
203                "Calculate AWFactor"
204                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
205        else
206                "Calculate AWFactor"
207                AWFactor=1;
208        end
209end
210
211Model PID_Series_AW as PID_basic
212       
213        VARIABLES
214        AWFactor     as Real     (Brief="Integral term multiplier used in anti-reset windup");
215       
216        EQUATIONS
217       
218        "Calculate integral term with anti-windup"     
219        Parameters.intTime*diff(Internal.intTerm) = AWFactor*Internal.errorI;
220       
221        "Sum of proportional, integral and derivative terms"
222        Internal.outp = Parameters.bias + Options.action*(Parameters.gain*(Internal.propTerm + Internal.intTerm)*(1 + Internal.derivTerm));
223
224        if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then
225                "Calculate AWFactor"           
226                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
227        else
228                "Calculate AWFactor"
229                AWFactor=1;
230        end
231end
232
233Model PID_Ideal as PID_basic
234       
235        EQUATIONS
236       
237        "Calculate integral term"       
238        Parameters.intTime*diff(Internal.intTerm) = Internal.errorI;
239       
240        "Sum of proportional, integral and derivative terms"   
241        Internal.outp = Parameters.bias + Options.action*Parameters.gain*(Internal.propTerm + Internal.intTerm + Internal.derivTerm);
242
243end
244
245Model PID_Parallel as PID_basic
246       
247        EQUATIONS
248       
249        "Calculate integral term"       
250        Parameters.intTime*diff(Internal.intTerm) = Internal.errorI;
251       
252        "Sum of proportional, integral and derivative terms"   
253        Internal.outp = Parameters.bias + Options.action*(Parameters.gain*Internal.propTerm + Internal.intTerm + Internal.derivTerm);
254
255end
256
257Model PID_Series as PID_basic
258       
259        EQUATIONS
260       
261        "Calculate integral term"       
262        Parameters.intTime*diff(Internal.intTerm) = Internal.errorI;
263       
264        "Sum of proportional, integral and derivative terms"
265        Internal.outp = Parameters.bias + Options.action*(Parameters.gain*(Internal.propTerm + Internal.intTerm)*(1 + Internal.derivTerm));
266
267end
268
269Model PID_Ideal_AWBT as PID_basic
270       
271        EQUATIONS
272       
273        "Calculate integral term with anti-windup and bumpless transfer"       
274        Options.action*Parameters.gain*(Parameters.intTime*diff(Internal.intTerm)-Internal.errorI) = Ports.output-Internal.outp;       
275       
276        "Sum of proportional, integral and derivative terms"   
277        Internal.outp = Parameters.bias + Options.action*Parameters.gain*(Internal.propTerm + Internal.intTerm + Internal.derivTerm);
278
279end
280
281Model PID_Parallel_AWBT as PID_basic
282       
283        EQUATIONS
284       
285        "Calculate integral term with anti-windup and bumpless transfer"       
286        Options.action*Parameters.gain*(Parameters.intTime*diff(Internal.intTerm)-Internal.errorI) = Ports.output-Internal.outp;       
287       
288        "Sum of proportional, integral and derivative terms"   
289        Internal.outp = Parameters.bias + Options.action*(Parameters.gain*Internal.propTerm + Internal.intTerm + Internal.derivTerm);
290
291end
292
293Model PID_Series_AWBT as PID_basic
294       
295        EQUATIONS
296       
297        "Calculate integral term with anti-windup and bumpless transfer"
298        Options.action*Parameters.gain*(Parameters.intTime*diff(Internal.intTerm)-Internal.errorI) = Ports.output-Internal.outp;       
299       
300        "Sum of proportional, integral and derivative terms"
301        Internal.outp = Parameters.bias + Options.action*(Parameters.gain*(Internal.propTerm + Internal.intTerm)*(1 + Internal.derivTerm));
302
303end
Note: See TracBrowser for help on using the repository browser.