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