source: branches/gui/eml/controllers/pi.mso @ 805

Last change on this file since 805 was 686, checked in by gerson bicca, 15 years ago

updated pi controller

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1using "types";
2       
3Model PI_simple
4       
5ATTRIBUTES
6        Pallete         = true;
7        Icon            = "icon/PI";
8
9PARAMETERS
10        Kp              as Real         (Brief="Controller gain", Default=0.5);
11        Ki                      as Real         (Brief="Integral time constant", Unit='s');
12        bias            as Real         (Brief="Previous scaled bias",Default=0.5);
13
14        MinInput   as control_signal(Default=-1000);
15        MaxInput   as control_signal(Default=1000);
16       
17VARIABLES
18        in              Input           as control_signal       (Brief="Previous scaled input signal", Default=0.5, PosX=0, PosY=0.5);
19        out     Output     as control_signal    (Brief="Scaled output signal", Default=0, PosX=0.54, PosY=1);
20        SetPoint                as Real                                 (Brief="Scaled setPoint", Lower=0, Upper=1, Default=0.5);
21       
22        input                   as Real    (Brief="Scaled input variable", Hidden=true);
23        setPoint                as Real    (Brief="Scaled set point", Hidden=true);
24        intTerm         as Real    (Brief="Integral term", Default=0, Protected=true);
25        outps                   as Real    (Brief="Variable outp scaled between 0 and 1", Hidden=true);
26       
27EQUATIONS
28
29"Calculate integral term"
30        Ki*diff(intTerm) = setPoint - input;
31       
32"Sum of proportional, integral and derivative terms"
33        outps = bias + Kp*(setPoint - input) + intTerm;
34       
35        input*(MaxInput-MinInput) = Input-MinInput;
36        setPoint*(MaxInput-MinInput) = SetPoint-MinInput;
37
38        if outps > 1 then
39                Output = 1;
40        else
41                if outps < 0 then
42                        Output = 0;
43                else
44                        Output = outps;
45                end
46        end
47
48        INITIAL
49        intTerm = 0;
50end
51
52Model PI
53       
54ATTRIBUTES
55        Pallete         = true;
56        Icon            = "icon/PI";
57
58PARAMETERS
59
60        Action                  as Switcher                     (Brief="Controller action", Valid=["Direct","Reverse"], Default = "Reverse");
61        Mode            as Switcher                     (Brief="Controller mode", Valid=["Automatic","Manual"], Default = "Automatic");
62        bias                    as positive                             (Brief="Previous scaled bias", Lower=0, Upper=1, Default=0.5);
63        beta                    as positive                             (Brief="Proportional term setPoint change filter", Default=1);
64        gain                    as positive                             (Brief="Controller gain", Lower=0, Upper=1, Default=0.5);
65        intTime         as Real                                 (Brief="Integral time constant", Unit='s');
66        MinInput        as control_signal       (Default=-1000);
67        MaxInput        as control_signal       (Default=1000);
68       
69VARIABLES
70
71in      Input                   as control_signal       (Brief="Previous scaled input signal", Default=0.5, PosX=0, PosY=0.5, Hidden=true);
72out     Output     as control_signal    (Brief="Scaled output signal", Default=0, PosX=0.7, PosY=1, Hidden=true);
73                SetPoint  as Real                               (Brief="Scaled setPoint", Lower=0, Upper=1, Default=0.5);
74       
75        propTerm        as Real                                 (Brief="Proportional term", Default=0, Protected=true);
76        intTerm         as Real                                 (Brief="Integral term", Default=0, Protected=true);
77        input                   as Real                                 (Brief="Scaled input variable", Hidden=true);
78        setPoint                as Real                                 (Brief="Scaled set point", Hidden=true);
79        action                  as Real                                 (Brief="Controller action: (-1) Direct,(1) Reverse", Default=-1, Hidden=true);
80        outp                    as control_signal       (Brief="Sum of proportional, integral and derivative terms", Hidden=true);
81        error                   as Real                                 (Brief="Error definition for proportional term", Hidden=true);
82        outps                   as Real                         (Brief="Variable outp scaled between -1 and 1", Hidden=true);
83       
84EQUATIONS
85       
86        input*(MaxInput-MinInput) = Input-MinInput;
87        setPoint*(MaxInput-MinInput) = SetPoint-MinInput;
88
89switch Mode
90        case "Automatic":
91                "Error definition"     
92                error = beta*setPoint - input;
93        case "Manual":
94                "Error definition"
95                error = input*(beta-1.0);
96        end
97
98        switch Action
99        case "Direct":
100                action = -1.0;
101        case "Reverse":
102                action = 1.0;
103        end
104
105        "Calculate proportional term"
106        propTerm=error;
107       
108        "Scale outp"
109        #outps=2*outp-1;
110        outps=outp;
111       
112        if outps > 1 then
113                Output = 1;
114        else
115                if outps < -1 then
116                        Output = -1;
117                else
118                        Output = outps;
119                end
120        end
121               
122        "Calculate integral term"
123        intTime*diff(intTerm) = setPoint - input;
124       
125        "Sum of proportional, integral and derivative terms"
126        outp = bias + action*gain*(propTerm + intTerm);
127
128        INITIAL
129        intTerm = 0;   
130end
Note: See TracBrowser for help on using the repository browser.