source: trunk/eml/controllers/PIDIncr.mso @ 442

Last change on this file since 442 was 354, checked in by Argimiro Resende Secchi, 16 years ago

Fixing more wiki notation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.2 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* Author: Tiago Osório
16* $Id: PIDIncr.mso 354 2007-08-30 17:17:16Z arge $
17*-------------------------------------------------------------------*#
18using "types";
19
20Model MParameters
21
22ATTRIBUTES
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       
38end
39
40Model MOptions 
41
42ATTRIBUTES
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
52end
53
54Model MPorts
55
56ATTRIBUTES
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
66end
67
68Model 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
89end
90
91Model PIDIncr
92
93ATTRIBUTES
94        Pallete         = true;
95        Icon            = "icon/PIDIncr";
96        Brief           = "Model of incremental PIDs.";
97        Info            =
98"== Inputs ==
99* scaled processs variable.
100* scaled bias.
101* scaled setpoint.
102
103== Outputs ==
104* a scaled output.
105";
106       
107        PARAMETERS
108       
109        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");
110       
111        VARIABLES
112        Parameters         as MParameters;
113        Options            as MOptions;
114        Internal           as MInternal_Variables;
115        Ports              as MPorts;
116        AWFactor     as Real     (Brief="Integral term multiplier used in anti-reset windup");
117       
118        EQUATIONS
119
120        if (Parameters.tau equal 0) then
121                "Input first order filter"
122                (Parameters.tau + 1e-3*'s')*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;
123        else
124                "Input first order filter"
125                Parameters.tau*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;     
126        end
127
128        if (Parameters.tauSet equal 0) then
129                "setPoint first order filter"
130                (Parameters.tauSet + 1e-3*'s')*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
131        else
132                "setPoint first order filter"
133                Parameters.tauSet*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
134        end
135
136        if Options.autoMan equal 1 then
137                "Error definition for proportional term"
138                Internal.error*'s' = Internal.inputFilt*(Parameters.beta-1.0);
139                "Error definition for derivative term"
140                Internal.errorD*'s'= Internal.inputFilt*(Parameters.gamma-1.0);
141                "Error definition for integral term"           
142                Internal.errorI= 0;
143        else
144                "Error definition for proportional term"                       
145                Internal.error = Parameters.beta*diff(Internal.setPointFilt) - diff(Internal.inputFilt);
146                "Error definition for derivative term"
147                Internal.errorD = Parameters.gamma*diff(Internal.setPointFilt) - diff(Internal.inputFilt);
148                "Error definition for integral term"
149                Internal.errorI = Internal.setPointFilt-Internal.inputFilt;     
150        end
151       
152        "Calculate proportional term"
153        Internal.dpropTerm=Internal.error; 
154       
155        if (Parameters.derivTime equal 0) then
156                "Derivative term filter"       
157                Parameters.alpha*(Parameters.derivTime + 1e-3*'s')*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
158        else
159                "Derivative term filter"       
160                Parameters.alpha*(Parameters.derivTime)*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
161        end
162
163        "Calculate derivative term"
164        Internal.dderivTerm = Parameters.derivTime*diff(Internal.dFilt);
165       
166    "Unscaled output"
167        diff(Internal.outp)=Internal.doutp;
168
169        "Scale outp"
170        Internal.outps=2*Internal.outp-1;
171
172        if Options.clip equal 1 then
173                if abs(Internal.outps)>1 then
174                        "Calculate clipped output when it´s saturated"
175                        Ports.output=(sign(Internal.outps)*1+1)/2;
176                else
177                        "Calculate clipped output when it´s not saturated"
178                        Ports.output=Internal.outp;
179                end
180        else
181                "Calculate unclipped output"
182                Ports.output=Internal.outp;
183        end
184
185switch PID_Select
186       
187case "Ideal":
188       
189        "Calculate integral term"
190        Parameters.intTime*Internal.dintTerm = Internal.errorI;
191       
192        "Sum of proportional, integral and derivative terms"
193        Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
194
195        "Calculate AWFactor - Not in use in this mode"
196        AWFactor=1;
197       
198case "Parallel":
199       
200        "Calculate integral term"
201        Parameters.intTime*Internal.dintTerm = Internal.errorI;
202       
203        "Sum of proportional, integral and derivative terms"
204        Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
205
206"Calculate AWFactor - Not in use in this mode"
207        AWFactor=1;
208       
209case "Series":
210       
211        "Calculate integral term"
212        Parameters.intTime*Internal.dintTerm = Internal.errorI;
213       
214        "Sum of proportional, integral and derivative terms"
215        Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');
216       
217        "Calculate AWFactor - Not in use in this mode"
218        AWFactor=1;
219       
220case "Ideal_AWBT":
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        "Calculate AWFactor - Not in use in this mode"
229        AWFactor=1;
230       
231case "Parallel_AWBT":
232       
233        "Calculate integral term with anti-windup and bumpless transfer"
234        Options.action*Parameters.gain*(Parameters.intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp;
235       
236        "Sum of proportional, integral and derivative terms"
237        Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
238
239"Calculate AWFactor - Not in use in this mode"
240        AWFactor=1;
241
242case "Series_AWBT":
243       
244        "Calculate integral term with anti-windup and bumpless transfer"
245        Options.action*Parameters.gain*(Parameters.intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp;
246
247        "Sum of proportional, integral and derivative terms"
248        Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');
249
250"Calculate AWFactor - Not in use in this mode"
251        AWFactor=1;
252       
253case "Ideal_AW":
254       
255        "Calculate integral term with anti-windup"
256        Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI;
257       
258        "Sum of proportional, integral and derivative terms"
259        Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
260       
261        if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then
262                "Calculate AWFactor"
263                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
264        else
265                "Calculate AWFactor"
266                AWFactor=1;
267        end
268
269case "Parallel_AW":
270       
271        "Calculate integral term with anti-windup"
272        Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI;
273       
274        "Sum of proportional, integral and derivative terms"
275        Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
276       
277        if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then
278                "Calculate AWFactor"
279                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
280        else
281                "Calculate AWFactor"
282                AWFactor=1;
283        end
284
285case "Series_AW":
286       
287        "Calculate integral term with anti-windup"
288        Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI;
289       
290        "Sum of proportional, integral and derivative terms"
291        Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');
292       
293        if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then
294                "Calculate AWFactor"
295                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
296        else
297                "Calculate AWFactor"
298                AWFactor=1;
299        end
300
301end
302
303        INITIAL
304        Ports.output = Parameters.bias;
305        diff(Internal.dFilt) = 0/'s^2';
306        diff(Internal.inputFilt)=0/'s';
307        diff(Internal.setPointFilt)=0/'s';
308       
309end
310
311
Note: See TracBrowser for help on using the repository browser.