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