[558] | 1 | using "types"; |
---|
| 2 | |
---|
| 3 | Model PI_simple |
---|
[686] | 4 | |
---|
[558] | 5 | ATTRIBUTES |
---|
| 6 | Pallete = true; |
---|
[592] | 7 | Icon = "icon/PI"; |
---|
[558] | 8 | |
---|
[686] | 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); |
---|
[558] | 13 | |
---|
| 14 | MinInput as control_signal(Default=-1000); |
---|
| 15 | MaxInput as control_signal(Default=1000); |
---|
| 16 | |
---|
[686] | 17 | VARIABLES |
---|
| 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 | |
---|
| 27 | EQUATIONS |
---|
[558] | 28 | |
---|
[686] | 29 | "Calculate integral term" |
---|
[558] | 30 | Ki*diff(intTerm) = setPoint - input; |
---|
| 31 | |
---|
[686] | 32 | "Sum of proportional, integral and derivative terms" |
---|
[558] | 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; |
---|
| 50 | end |
---|
| 51 | |
---|
| 52 | Model PI |
---|
[686] | 53 | |
---|
[558] | 54 | ATTRIBUTES |
---|
| 55 | Pallete = true; |
---|
[592] | 56 | Icon = "icon/PI"; |
---|
[558] | 57 | |
---|
[686] | 58 | PARAMETERS |
---|
| 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); |
---|
[558] | 68 | |
---|
[686] | 69 | VARIABLES |
---|
[558] | 70 | |
---|
[686] | 71 | in Input as control_signal (Brief="Previous scaled input signal", Default=0.5, PosX=0, PosY=0.5, Hidden=true); |
---|
| 72 | out 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); |
---|
[558] | 74 | |
---|
[686] | 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); |
---|
[558] | 83 | |
---|
[686] | 84 | EQUATIONS |
---|
[558] | 85 | |
---|
| 86 | input*(MaxInput-MinInput) = Input-MinInput; |
---|
| 87 | setPoint*(MaxInput-MinInput) = SetPoint-MinInput; |
---|
| 88 | |
---|
[686] | 89 | switch Mode |
---|
| 90 | case "Automatic": |
---|
[558] | 91 | "Error definition" |
---|
| 92 | error = beta*setPoint - input; |
---|
[686] | 93 | case "Manual": |
---|
[558] | 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; |
---|
| 130 | end |
---|