[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); |
---|
[870] | 11 | Ki as Real (Brief="Integral time constant", Unit='s'); |
---|
[686] | 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 |
---|
[870] | 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); |
---|
[686] | 20 | |
---|
[870] | 21 | input as Real (Brief="Scaled input variable", Hidden=true); |
---|
| 22 | setPoint as Real (Brief="Scaled set point", Hidden=true); |
---|
[686] | 23 | intTerm as Real (Brief="Integral term", Default=0, Protected=true); |
---|
[870] | 24 | outps as Real (Brief="Variable outp scaled between 0 and 1", Hidden=true); |
---|
[686] | 25 | |
---|
[870] | 26 | SetPoint as Real (Brief="Scaled setPoint", Lower=0, Upper=1, Default=0.5); |
---|
| 27 | |
---|
[686] | 28 | EQUATIONS |
---|
[558] | 29 | |
---|
[686] | 30 | "Calculate integral term" |
---|
[558] | 31 | Ki*diff(intTerm) = setPoint - input; |
---|
| 32 | |
---|
[686] | 33 | "Sum of proportional, integral and derivative terms" |
---|
[558] | 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 | |
---|
[870] | 49 | INITIAL |
---|
[558] | 50 | intTerm = 0; |
---|
[870] | 51 | |
---|
[558] | 52 | end |
---|
| 53 | |
---|
| 54 | Model PI |
---|
[686] | 55 | |
---|
[558] | 56 | ATTRIBUTES |
---|
| 57 | Pallete = true; |
---|
[592] | 58 | Icon = "icon/PI"; |
---|
[558] | 59 | |
---|
[686] | 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); |
---|
[558] | 70 | |
---|
[686] | 71 | VARIABLES |
---|
[558] | 72 | |
---|
[871] | 73 | in Input as control_signal (Brief="Previous scaled input signal", Default=0.5, PosX=0, PosY=0.5, Protected=true); |
---|
| 74 | out Output as control_signal (Brief="Scaled output signal", Default=0, PosX=0.54, PosY=1, Protected=true); |
---|
[686] | 75 | SetPoint as Real (Brief="Scaled setPoint", Lower=0, Upper=1, Default=0.5); |
---|
[558] | 76 | |
---|
[686] | 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); |
---|
[558] | 85 | |
---|
[686] | 86 | EQUATIONS |
---|
[558] | 87 | |
---|
| 88 | input*(MaxInput-MinInput) = Input-MinInput; |
---|
| 89 | setPoint*(MaxInput-MinInput) = SetPoint-MinInput; |
---|
| 90 | |
---|
[686] | 91 | switch Mode |
---|
| 92 | case "Automatic": |
---|
[558] | 93 | "Error definition" |
---|
| 94 | error = beta*setPoint - input; |
---|
[686] | 95 | case "Manual": |
---|
[558] | 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 |
---|