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

Last change on this file since 962 was 909, checked in by Argimiro Resende Secchi, 13 years ago

Starting checking new EML.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.7 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 909 2010-02-19 21:08:11Z arge $
17*-------------------------------------------------------------------*#
18using "types";
19
20Model PIDIncr
21
22ATTRIBUTES
23        Pallete         = true;
24        Icon            = "icon/PIDincr";
25        Brief           = "Model of incremental PIDs.";
26        Info            =
27"== Inputs ==
28* scaled processs variable.
29* scaled bias.
30* scaled setpoint.
31
32== Outputs ==
33* a scaled output.
34";
35       
36PARAMETERS
37       
38        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");
39        Action          as Switcher     (Brief="Controller action", Valid=["Direct","Reverse"], Default = "Reverse");
40        Mode            as Switcher     (Brief="Controller mode", Valid=["Automatic","Manual"], Default = "Automatic");
41        Clip            as Switcher     (Brief="Controller mode", Valid=["Clipped","Unclipped"], Default = "Clipped");
42       
43        alpha           as positive             (Brief="Derivative term filter constant", Default=1);
44        beta            as positive             (Brief="Proportional term setPoint change filter");
45        bias            as control_signal       (Brief="Previous scaled bias", Default=0.5);
46        derivTime       as time_sec             (Brief="Derivative time constant");
47        intTime         as time_sec             (Brief="Integral time constant");
48        gain            as positive             (Brief="Controller gain", Default=0.5);
49        gamma           as positive             (Brief="Derivative term SP change filter");
50        tau             as time_sec             (Brief="Input filter time constant");
51        tauSet          as time_sec             (Brief="Input filter time constant");
52        MinInput        as control_signal       (Default=0);
53        MaxInput        as control_signal       (Default=1000);
54        MinOutput       as control_signal       (Default=0);
55        MaxOutput       as control_signal       (Default=1);
56
57VARIABLES
58
59in      Input           as control_signal       (Protected=true, PosX=0, PosY=0.5);
60out     Output          as control_signal       (Protected=true, PosX=0.54, PosY=1);
61        SetPoint        as control_signal;
62       
63#++++++++++++++++++++ PID Internal Variables ++++++++++++++++++++++++++++++++
64        PID_dderivTerm          as control_signal       (Brief="Derivative term",Unit='1/s', Default=0, Hidden=true);
65        PID_dFilt               as control_signal       (Brief="Derivative term filtered", Default=0.5,Unit='1/s', Hidden=true);
66        PID_error               as control_signal       (Brief="Error definition for proportional term",Unit='1/s', Hidden=true);
67        PID_errorD              as control_signal       (Brief="Error definition for derivative term",Unit='1/s', Hidden=true);
68        PID_errorI              as control_signal       (Brief="Error definition for integral term", Hidden=true);
69        PID_inputFilt           as control_signal       (Brief="Filtered input", Hidden=true);
70        PID_dintTerm            as control_signal       (Brief="Integral term", Default=0,Unit='1/s', Hidden=true);
71        PID_doutp               as control_signal       (Brief="Sum of proportional, integral and derivative terms",Unit='1/s', Hidden=true);
72        PID_outps               as control_signal       (Brief="Variable outp scaled between -1 and 1", Hidden=true, Default=0.5);
73        PID_outp                as control_signal       (Brief="Variable outp", Hidden=true);
74        PID_dpropTerm           as control_signal       (Brief="Proportional term", Default=0,Unit='1/s', Hidden=true);
75        PID_setPointFilt        as control_signal       (Brief="Filtered setPoint", Default=0, Hidden=true);
76        PID_input               as control_signal       (Brief="Previous scaled input signal", Default=0.5, Hidden=true);
77        PID_output              as control_signal       (Brief="Scaled output signal", Default=0.5, Hidden=true);
78        PID_setPoint            as control_signal       (Brief="Scaled setPoint",Default=0.5, Hidden=true);
79        PID_AWFactor            as Real                         (Brief="Integral term multiplier used in anti-reset windup", Hidden=true);
80        PID_action              as Real                         (Hidden=true);
81#++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++
82
83EQUATIONS
84
85"Input "
86        PID_input*(MaxInput - MinInput) = Input - MinInput;
87
88"Output "
89        Output = PID_output*(MaxOutput - MinOutput) + MinOutput;
90       
91"Set Point "
92        PID_setPoint*(MaxInput - MinInput) = SetPoint - MinInput;
93
94        if (tau < 1e-3*'s') then
95                "Input first order filter"
96                (tau + 1e-3*'s')*diff(PID_inputFilt)= PID_input - PID_inputFilt;
97        else
98                "Input first order filter"
99                tau*diff(PID_inputFilt)= PID_input - PID_inputFilt;     
100        end
101
102        if (tauSet < 1e-3*'s') then
103                "setPoint first order filter"
104                (tauSet + 1e-3*'s')*diff(PID_setPointFilt)= PID_setPoint - PID_setPointFilt;
105        else
106                "setPoint first order filter"
107                tauSet*diff(PID_setPointFilt)= PID_setPoint - PID_setPointFilt;
108        end
109
110        switch Mode
111        case "Manual":
112                "Error definition for proportional term"
113                PID_error*'s' = PID_inputFilt*(beta-1.0);
114                "Error definition for derivative term"
115                PID_errorD*'s'= PID_inputFilt*(gamma-1.0);
116                "Error definition for integral term"           
117                PID_errorI= 0;
118        case "Automatic":
119                "Error definition for proportional term"                       
120                PID_error = beta*diff(PID_setPointFilt) - diff(PID_inputFilt);
121                "Error definition for derivative term"
122                PID_errorD = gamma*diff(PID_setPointFilt) - diff(PID_inputFilt);
123                "Error definition for integral term"
124                PID_errorI = PID_setPointFilt-PID_inputFilt;   
125        end
126       
127        "Calculate proportional term"
128        PID_dpropTerm=PID_error; 
129       
130        if (derivTime < 1e-3*'s') then
131                "Derivative term filter"       
132                alpha*(derivTime + 1e-3*'s')*diff(PID_dFilt) = PID_errorD - PID_dFilt;
133        else
134                "Derivative term filter"       
135                alpha*(derivTime)*diff(PID_dFilt) = PID_errorD - PID_dFilt;
136        end
137
138        "Calculate derivative term"
139        PID_dderivTerm = derivTime*diff(PID_dFilt);
140       
141    "Unscaled output"
142        diff(PID_outp)=PID_doutp;
143
144        "Scale outp"
145        PID_outps=2*PID_outp-1;
146
147        switch Clip
148        case "Clipped":
149                if abs(PID_outps)>1 then
150                        "Calculate clipped output when saturated"
151                        PID_output=(sign(PID_outps)+1)/2;
152                else
153                        "Calculate clipped output when not saturated"
154                        PID_output=PID_outp;
155                end
156                #PID_output = max([0, PID_outp]);
157        case "Unclipped":
158                "Calculate unclipped output"
159                PID_output=PID_outp;
160        end
161       
162        switch Action
163        case "Direct":
164                PID_action = -1.0;
165        case "Reverse":
166                PID_action = 1.0;
167        end
168
169switch PID_Select
170       
171case "Ideal":
172       
173        "Calculate integral term"
174        intTime*PID_dintTerm = PID_errorI;
175       
176        "Sum of proportional, integral and derivative terms"
177        PID_doutp = PID_action*gain*(PID_dpropTerm + PID_dintTerm + PID_dderivTerm);
178
179        "Calculate AWFactor - Not in use in this mode"
180        PID_AWFactor=1;
181       
182case "Parallel":
183       
184        "Calculate integral term"
185        intTime*PID_dintTerm = PID_errorI;     
186       
187        "Sum of proportional, integral and derivative terms"
188        PID_doutp = PID_action*(gain*PID_dpropTerm + PID_dintTerm + PID_dderivTerm);
189
190"Calculate AWFactor - Not in use in this mode"
191        PID_AWFactor=1;
192       
193case "Series":
194       
195        "Calculate integral term"
196        intTime*PID_dintTerm = PID_errorI;     
197       
198        "Sum of proportional, integral and derivative terms"
199        PID_doutp = PID_action*(gain*(PID_dpropTerm + PID_dintTerm)*(1/'s' + PID_dderivTerm)*'s');
200       
201        "Calculate AWFactor - Not in use in this mode"
202        PID_AWFactor=1;
203       
204case "Ideal_AWBT":
205       
206        "Calculate integral term with anti-windup and bumpless transfer"
207        PID_action*gain*(intTime*PID_dintTerm-PID_errorI) = PID_output-PID_outp;
208
209        "Sum of proportional, integral and derivative terms"
210        PID_doutp = PID_action*gain*(PID_dpropTerm + PID_dintTerm + PID_dderivTerm);
211
212        "Calculate AWFactor - Not in use in this mode"
213        PID_AWFactor=1;
214       
215case "Parallel_AWBT":
216       
217        "Calculate integral term with anti-windup and bumpless transfer"
218        PID_action*gain*(intTime*PID_dintTerm-PID_errorI) = PID_output-PID_outp;
219       
220        "Sum of proportional, integral and derivative terms"
221        PID_doutp = PID_action*(gain*PID_dpropTerm + PID_dintTerm + PID_dderivTerm);
222
223"Calculate AWFactor - Not in use in this mode"
224        PID_AWFactor=1;
225
226case "Series_AWBT":
227       
228        "Calculate integral term with anti-windup and bumpless transfer"
229        PID_action*gain*(intTime*PID_dintTerm-PID_errorI) = PID_output-PID_outp;
230
231        "Sum of proportional, integral and derivative terms"
232        PID_doutp = PID_action*(gain*(PID_dpropTerm + PID_dintTerm)*(1/'s' + PID_dderivTerm)*'s');
233
234"Calculate AWFactor - Not in use in this mode"
235        PID_AWFactor=1;
236       
237case "Ideal_AW":
238       
239        "Calculate integral term with anti-windup"
240        intTime*PID_dintTerm = PID_AWFactor*PID_errorI;
241       
242        "Sum of proportional, integral and derivative terms"
243        PID_doutp = PID_action*gain*(PID_dpropTerm + PID_dintTerm + PID_dderivTerm);
244       
245        if abs(PID_outps)>1 and (PID_action*sign(PID_outps)*PID_errorI)>0 then
246                "Calculate AWFactor"
247                PID_AWFactor=-tanh(sign(PID_outps)*PID_outps*100-102);
248        else
249                "Calculate AWFactor"
250                PID_AWFactor=1;
251        end
252
253case "Parallel_AW":
254       
255        "Calculate integral term with anti-windup"
256        intTime*PID_dintTerm = PID_AWFactor*PID_errorI;
257       
258        "Sum of proportional, integral and derivative terms"
259        PID_doutp = PID_action*(gain*PID_dpropTerm + PID_dintTerm + PID_dderivTerm);
260       
261        if abs(PID_outps)>1 and (PID_action*sign(PID_outps)*PID_errorI)>0 then
262                "Calculate AWFactor"
263                PID_AWFactor=-tanh(sign(PID_outps)*PID_outps*100-102);
264        else
265                "Calculate AWFactor"
266                PID_AWFactor=1;
267        end
268
269case "Series_AW":
270       
271        "Calculate integral term with anti-windup"
272        intTime*PID_dintTerm = PID_AWFactor*PID_errorI;
273       
274        "Sum of proportional, integral and derivative terms"
275        PID_doutp = PID_action*(gain*(PID_dpropTerm + PID_dintTerm)*(1/'s' + PID_dderivTerm)*'s');
276       
277        if abs(PID_outps)>1 and (PID_action*sign(PID_outps)*PID_errorI)>0 then
278                "Calculate AWFactor"
279                PID_AWFactor=-tanh(sign(PID_outps)*PID_outps*100-102);
280        else
281                "Calculate AWFactor"
282                PID_AWFactor=1;
283        end
284
285end
286
287        INITIAL
288        PID_output = bias;     
289        diff(PID_dFilt) = 0/'s^2';
290        diff(PID_inputFilt)=0/'s';
291        diff(PID_setPointFilt)=0/'s';
292       
293end
Note: See TracBrowser for help on using the repository browser.