Changeset 684 for branches/gui/eml/controllers
 Timestamp:
 Nov 20, 2008, 3:37:32 PM (15 years ago)
 Location:
 branches/gui/eml/controllers
 Files:

 2 added
 1 deleted
 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/gui/eml/controllers/PIDIncr.mso
r560 r684 18 18 using "types"; 19 19 20 Model MPorts21 22 ATTRIBUTES23 Pallete = false;24 Brief = "Model of Ports to be used with incremental PIDs.";25 26 VARIABLES27 28 input as control_signal (Brief="Previous scaled input signal", Default=0.5);29 output as control_signal (Brief="Scaled output signal", Default=0.5);30 setPoint as control_signal (Brief="Scaled setPoint",Default=0.5);31 32 end33 34 Model MInternal_Variables35 36 ATTRIBUTES37 Pallete = false;38 Brief = "Model of Internal Variables to be used with incremental PIDs.";39 40 VARIABLES41 42 dderivTerm as control_signal (Brief="Derivative term",Unit='1/s', Default=0);43 dFilt as control_signal (Brief="Derivative term filtered", Default=0.5,Unit='1/s');44 error as control_signal (Brief="Error definition for proportional term",Unit='1/s');45 errorD as control_signal (Brief="Error definition for derivative term",Unit='1/s');46 errorI as control_signal (Brief="Error definition for integral term");47 inputFilt as control_signal (Brief="Filtered input");48 dintTerm as control_signal (Brief="Integral term", Default=0,Unit='1/s');49 doutp as control_signal (Brief="Sum of proportional, integral and derivative terms",Unit='1/s');50 outps as control_signal (Brief="Variable outp scaled between 1 and 1");51 outp as control_signal (Brief="Variable outp");52 dpropTerm as control_signal (Brief="Proportional term", Default=0,Unit='1/s');53 setPointFilt as control_signal (Brief="Filtered setPoint", Default=0);54 55 end56 57 20 Model PIDIncr 58 21 59 22 ATTRIBUTES 60 23 Pallete = true; 61 Icon = "icon/PID Incr";24 Icon = "icon/PIDincr"; 62 25 Brief = "Model of incremental PIDs."; 63 26 Info = … … 71 34 "; 72 35 73 PARAMETERS 74 75 PID_Select as Switcher (Brief="Type of PID Incremental", Valid=["Ideal","Parallel","Series","Ideal_AWBT","Parallel_AWBT","Series_AWBT","Ideal_AW","Parallel_AW","Series_AW"], Default = "Ideal"); 76 Action as Switcher (Brief="Controller action", Valid=["Direct","Reverse"], Default = "Reverse"); 77 Mode as Switcher (Brief="Controller mode", Valid=["Automatic","Manual"], Default = "Automatic"); 78 Clip as Switcher (Brief="Controller mode", Valid=["Clipped","Unclipped"], Default = "Clipped"); 79 80 alpha as positive (Brief="Derivative term filter constant", Default=1); 81 beta as positive (Brief="Proportional term setPoint change filter"); 82 bias as control_signal (Brief="Previous scaled bias", Default=0.5); 83 derivTime as time_sec (Brief="Derivative time constant"); 84 intTime as time_sec (Brief="Integral time constant"); 85 gain as positive (Brief="Controller gain", Default=0.5); 86 gamma as positive (Brief="Derivative term SP change filter"); 87 tau as time_sec (Brief="Input filter time constant"); 88 tauSet as time_sec (Brief="Input filter time constant"); 89 90 VARIABLES 91 Internal as MInternal_Variables; 92 Ports as MPorts; 93 AWFactor as Real(Brief="Integral term multiplier used in antireset windup", Hidden=true); 94 action as Real(Hidden=true); 95 96 EQUATIONS 36 PARAMETERS 37 38 PID_Select as Switcher (Brief="Type of PID Incremental", Valid=["Ideal","Parallel","Series","Ideal_AWBT","Parallel_AWBT","Series_AWBT","Ideal_AW","Parallel_AW","Series_AW"], Default = "Ideal"); 39 Action as Switcher (Brief="Controller action", Valid=["Direct","Reverse"], Default = "Reverse"); 40 Mode as Switcher (Brief="Controller mode", Valid=["Automatic","Manual"], Default = "Automatic"); 41 Clip as Switcher (Brief="Controller mode", Valid=["Clipped","Unclipped"], Default = "Clipped"); 42 43 alpha as positive (Brief="Derivative term filter constant", Default=1); 44 beta as positive (Brief="Proportional term setPoint change filter"); 45 bias as control_signal (Brief="Previous scaled bias", Default=0.5); 46 derivTime as time_sec (Brief="Derivative time constant"); 47 intTime as time_sec (Brief="Integral time constant"); 48 gain as positive (Brief="Controller gain", Default=0.5); 49 gamma as positive (Brief="Derivative term SP change filter"); 50 tau as time_sec (Brief="Input filter time constant"); 51 tauSet as time_sec (Brief="Input filter time constant"); 52 MinInput as control_signal (Default=1000); 53 MaxInput as control_signal (Default=1000); 54 MinOutput as control_signal (Default=1000); 55 MaxOutput as control_signal (Default=1000); 56 57 VARIABLES 58 59 in Input as control_signal (Protected=true, PosX=0, PosY=0.5); 60 out Output as control_signal (Protected=true, PosX=0.54, PosY=1); 61 SetPoint as control_signal; 62 63 #++++++++++++++++++++ PID Internal Variables ++++++++++++++++++++++++++++++++ 64 PID_dderivTerm as control_signal (Brief="Derivative term",Unit='1/s', Default=0, Hidden=true); 65 PID_dFilt as control_signal (Brief="Derivative term filtered", Default=0.5,Unit='1/s', Hidden=true); 66 PID_error as control_signal (Brief="Error definition for proportional term",Unit='1/s', Hidden=true); 67 PID_errorD as control_signal (Brief="Error definition for derivative term",Unit='1/s', Hidden=true); 68 PID_errorI as control_signal (Brief="Error definition for integral term", Hidden=true); 69 PID_inputFilt as control_signal (Brief="Filtered input", Hidden=true); 70 PID_dintTerm as control_signal (Brief="Integral term", Default=0,Unit='1/s', Hidden=true); 71 PID_doutp as control_signal (Brief="Sum of proportional, integral and derivative terms",Unit='1/s', Hidden=true); 72 PID_outps as control_signal (Brief="Variable outp scaled between 1 and 1", Hidden=true); 73 PID_outp as control_signal (Brief="Variable outp", Hidden=true); 74 PID_dpropTerm as control_signal (Brief="Proportional term", Default=0,Unit='1/s', Hidden=true); 75 PID_setPointFilt as control_signal (Brief="Filtered setPoint", Default=0, Hidden=true); 76 PID_input as control_signal (Brief="Previous scaled input signal", Default=0.5, Hidden=true); 77 PID_output as control_signal (Brief="Scaled output signal", Default=0.5, Hidden=true); 78 PID_setPoint as control_signal (Brief="Scaled setPoint",Default=0.5, Hidden=true); 79 PID_AWFactor as Real (Brief="Integral term multiplier used in antireset windup", Hidden=true); 80 PID_action as Real (Hidden=true); 81 #++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++ 82 83 EQUATIONS 84 85 "Input " 86 PID_input*(MaxInput  MinInput) = Input  MinInput; 87 88 "Output " 89 Output = PID_output*(MaxOutputMinOutput) +MinOutput; 90 91 "Set Point " 92 PID_setPoint*(MaxInput  MinInput) = SetPoint  MinInput; 97 93 98 94 if (tau < 1e6) then 99 95 "Input first order filter" 100 (tau + 1e3*'s')*diff( Internal.inputFilt)= Ports.input  Internal.inputFilt;96 (tau + 1e3*'s')*diff(PID_inputFilt)= PID_input  PID_inputFilt; 101 97 else 102 98 "Input first order filter" 103 tau*diff( Internal.inputFilt)= Ports.input  Internal.inputFilt;99 tau*diff(PID_inputFilt)= PID_input  PID_inputFilt; 104 100 end 105 101 106 102 if (tauSet < 1e6) then 107 103 "setPoint first order filter" 108 (tauSet + 1e3*'s')*diff( Internal.setPointFilt)= Ports.setPoint  Internal.setPointFilt;104 (tauSet + 1e3*'s')*diff(PID_setPointFilt)= PID_setPoint  PID_setPointFilt; 109 105 else 110 106 "setPoint first order filter" 111 tauSet*diff( Internal.setPointFilt)= Ports.setPoint  Internal.setPointFilt;107 tauSet*diff(PID_setPointFilt)= PID_setPoint  PID_setPointFilt; 112 108 end 113 109 … … 115 111 case "Manual": 116 112 "Error definition for proportional term" 117 Internal.error*'s' = Internal.inputFilt*(beta1.0);113 PID_error*'s' = PID_inputFilt*(beta1.0); 118 114 "Error definition for derivative term" 119 Internal.errorD*'s'= Internal.inputFilt*(gamma1.0);115 PID_errorD*'s'= PID_inputFilt*(gamma1.0); 120 116 "Error definition for integral term" 121 Internal.errorI= 0;117 PID_errorI= 0; 122 118 case "Automatic": 123 119 "Error definition for proportional term" 124 Internal.error = beta*diff(Internal.setPointFilt)  diff(Internal.inputFilt);120 PID_error = beta*diff(PID_setPointFilt)  diff(PID_inputFilt); 125 121 "Error definition for derivative term" 126 Internal.errorD = gamma*diff(Internal.setPointFilt)  diff(Internal.inputFilt);122 PID_errorD = gamma*diff(PID_setPointFilt)  diff(PID_inputFilt); 127 123 "Error definition for integral term" 128 Internal.errorI = Internal.setPointFiltInternal.inputFilt;124 PID_errorI = PID_setPointFiltPID_inputFilt; 129 125 end 130 126 131 127 "Calculate proportional term" 132 Internal.dpropTerm=Internal.error;128 PID_dpropTerm=PID_error; 133 129 134 130 if (derivTime equal 0) then 135 131 "Derivative term filter" 136 alpha*(derivTime + 1e3*'s')*diff( Internal.dFilt) = Internal.errorD  Internal.dFilt;132 alpha*(derivTime + 1e3*'s')*diff(PID_dFilt) = PID_errorD  PID_dFilt; 137 133 else 138 134 "Derivative term filter" 139 alpha*(derivTime)*diff( Internal.dFilt) = Internal.errorD  Internal.dFilt;135 alpha*(derivTime)*diff(PID_dFilt) = PID_errorD  PID_dFilt; 140 136 end 141 137 142 138 "Calculate derivative term" 143 Internal.dderivTerm = derivTime*diff(Internal.dFilt);139 PID_dderivTerm = derivTime*diff(PID_dFilt); 144 140 145 141 "Unscaled output" 146 diff( Internal.outp)=Internal.doutp;142 diff(PID_outp)=PID_doutp; 147 143 148 144 "Scale outp" 149 Internal.outps=2*Internal.outp1;145 PID_outps=2*PID_outp1; 150 146 151 147 switch Clip 152 148 case "Clipped": 153 #if abs( Internal.outps)>1 then149 #if abs(PID_outps)>1 then 154 150 # "Calculate clipped output when it's saturated" 155 # Ports.output=(sign( Internal.outps)*1+1)/2;151 # Ports.output=(sign(PID_outps)*1+1)/2; 156 152 #else 157 153 # "Calculate clipped output when it's not saturated" 158 # Ports.output= Internal.outps;154 # Ports.output=PID_outps; 159 155 #end 160 P orts.output = max([0, Internal.outp]);156 PID_output = max([0, PID_outp]); 161 157 case "Unclipped": 162 158 "Calculate unclipped output" 163 P orts.output=Internal.outp;159 PID_output=PID_outp; 164 160 end 165 161 166 162 switch Action 167 163 case "Direct": 168 action = 1.0;164 PID_action = 1.0; 169 165 case "Reverse": 170 action = 1.0;166 PID_action = 1.0; 171 167 end 172 168 … … 176 172 177 173 "Calculate integral term" 178 intTime* Internal.dintTerm = Internal.errorI;179 180 "Sum of proportional, integral and derivative terms" 181 Internal.doutp = action*gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);174 intTime*PID_dintTerm = PID_errorI; 175 176 "Sum of proportional, integral and derivative terms" 177 PID_doutp = PID_action*gain*(PID_dpropTerm + PID_dintTerm + PID_dderivTerm); 182 178 183 179 "Calculate AWFactor  Not in use in this mode" 184 AWFactor=1;180 PID_AWFactor=1; 185 181 186 182 case "Parallel": 187 183 188 184 "Calculate integral term" 189 intTime* Internal.dintTerm = Internal.errorI;190 191 "Sum of proportional, integral and derivative terms" 192 Internal.doutp = action*(gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);185 intTime*PID_dintTerm = PID_errorI; 186 187 "Sum of proportional, integral and derivative terms" 188 PID_doutp = PID_action*(gain*PID_dpropTerm + PID_dintTerm + PID_dderivTerm); 193 189 194 190 "Calculate AWFactor  Not in use in this mode" 195 AWFactor=1;191 PID_AWFactor=1; 196 192 197 193 case "Series": 198 194 199 195 "Calculate integral term" 200 intTime* Internal.dintTerm = Internal.errorI;201 202 "Sum of proportional, integral and derivative terms" 203 Internal.doutp = action*(gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');196 intTime*PID_dintTerm = PID_errorI; 197 198 "Sum of proportional, integral and derivative terms" 199 PID_doutp = PID_action*(gain*(PID_dpropTerm + PID_dintTerm)*(1/'s' + PID_dderivTerm)*'s'); 204 200 205 201 "Calculate AWFactor  Not in use in this mode" 206 AWFactor=1;202 PID_AWFactor=1; 207 203 208 204 case "Ideal_AWBT": 209 205 210 206 "Calculate integral term with antiwindup and bumpless transfer" 211 action*gain*(intTime*Internal.dintTermInternal.errorI) = Ports.outputInternal.outp;212 213 "Sum of proportional, integral and derivative terms" 214 Internal.doutp = action*gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);207 PID_action*gain*(intTime*PID_dintTermPID_errorI) = PID_outputPID_outp; 208 209 "Sum of proportional, integral and derivative terms" 210 PID_doutp = PID_action*gain*(PID_dpropTerm + PID_dintTerm + PID_dderivTerm); 215 211 216 212 "Calculate AWFactor  Not in use in this mode" 217 AWFactor=1;213 PID_AWFactor=1; 218 214 219 215 case "Parallel_AWBT": 220 216 221 217 "Calculate integral term with antiwindup and bumpless transfer" 222 action*gain*(intTime*Internal.dintTermInternal.errorI) = Ports.outputInternal.outp;223 224 "Sum of proportional, integral and derivative terms" 225 Internal.doutp = action*(gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);218 PID_action*gain*(intTime*PID_dintTermPID_errorI) = PID_outputPID_outp; 219 220 "Sum of proportional, integral and derivative terms" 221 PID_doutp = PID_action*(gain*PID_dpropTerm + PID_dintTerm + PID_dderivTerm); 226 222 227 223 "Calculate AWFactor  Not in use in this mode" 228 AWFactor=1;224 PID_AWFactor=1; 229 225 230 226 case "Series_AWBT": 231 227 232 228 "Calculate integral term with antiwindup and bumpless transfer" 233 action*gain*(intTime*Internal.dintTermInternal.errorI) = Ports.outputInternal.outp;234 235 "Sum of proportional, integral and derivative terms" 236 Internal.doutp = action*(gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');229 PID_action*gain*(intTime*PID_dintTermPID_errorI) = PID_outputPID_outp; 230 231 "Sum of proportional, integral and derivative terms" 232 PID_doutp = PID_action*(gain*(PID_dpropTerm + PID_dintTerm)*(1/'s' + PID_dderivTerm)*'s'); 237 233 238 234 "Calculate AWFactor  Not in use in this mode" 239 AWFactor=1;235 PID_AWFactor=1; 240 236 241 237 case "Ideal_AW": 242 238 243 239 "Calculate integral term with antiwindup" 244 intTime* Internal.dintTerm = AWFactor*Internal.errorI;245 246 "Sum of proportional, integral and derivative terms" 247 Internal.doutp = action*gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);248 249 if abs( Internal.outps)>1 and (action*sign(Internal.outps)*Internal.errorI)>0 then250 "Calculate AWFactor" 251 AWFactor=tanh(sign(Internal.outps)*Internal.outps*100102);252 else 253 "Calculate AWFactor" 254 AWFactor=1;240 intTime*PID_dintTerm = PID_AWFactor*PID_errorI; 241 242 "Sum of proportional, integral and derivative terms" 243 PID_doutp = PID_action*gain*(PID_dpropTerm + PID_dintTerm + PID_dderivTerm); 244 245 if abs(PID_outps)>1 and (PID_action*sign(PID_outps)*PID_errorI)>0 then 246 "Calculate AWFactor" 247 PID_AWFactor=tanh(sign(PID_outps)*PID_outps*100102); 248 else 249 "Calculate AWFactor" 250 PID_AWFactor=1; 255 251 end 256 252 … … 258 254 259 255 "Calculate integral term with antiwindup" 260 intTime* Internal.dintTerm = AWFactor*Internal.errorI;261 262 "Sum of proportional, integral and derivative terms" 263 Internal.doutp = action*(gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);264 265 if abs( Internal.outps)>1 and (action*sign(Internal.outps)*Internal.errorI)>0 then266 "Calculate AWFactor" 267 AWFactor=tanh(sign(Internal.outps)*Internal.outps*100102);268 else 269 "Calculate AWFactor" 270 AWFactor=1;256 intTime*PID_dintTerm = PID_AWFactor*PID_errorI; 257 258 "Sum of proportional, integral and derivative terms" 259 PID_doutp = PID_action*(gain*PID_dpropTerm + PID_dintTerm + PID_dderivTerm); 260 261 if abs(PID_outps)>1 and (PID_action*sign(PID_outps)*PID_errorI)>0 then 262 "Calculate AWFactor" 263 PID_AWFactor=tanh(sign(PID_outps)*PID_outps*100102); 264 else 265 "Calculate AWFactor" 266 PID_AWFactor=1; 271 267 end 272 268 … … 274 270 275 271 "Calculate integral term with antiwindup" 276 intTime* Internal.dintTerm = AWFactor*Internal.errorI;277 278 "Sum of proportional, integral and derivative terms" 279 Internal.doutp = action*(gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');280 281 if abs( Internal.outps)>1 and (action*sign(Internal.outps)*Internal.errorI)>0 then282 "Calculate AWFactor" 283 AWFactor=tanh(sign(Internal.outps)*Internal.outps*100102);284 else 285 "Calculate AWFactor" 286 AWFactor=1;272 intTime*PID_dintTerm = PID_AWFactor*PID_errorI; 273 274 "Sum of proportional, integral and derivative terms" 275 PID_doutp = PID_action*(gain*(PID_dpropTerm + PID_dintTerm)*(1/'s' + PID_dderivTerm)*'s'); 276 277 if abs(PID_outps)>1 and (PID_action*sign(PID_outps)*PID_errorI)>0 then 278 "Calculate AWFactor" 279 PID_AWFactor=tanh(sign(PID_outps)*PID_outps*100102); 280 else 281 "Calculate AWFactor" 282 PID_AWFactor=1; 287 283 end 288 284 … … 290 286 291 287 INITIAL 292 P orts.output = bias;293 diff( Internal.dFilt) = 0/'s^2';294 diff( Internal.inputFilt)=0/'s';295 diff( Internal.setPointFilt)=0/'s';288 PID_output = bias; 289 diff(PID_dFilt) = 0/'s^2'; 290 diff(PID_inputFilt)=0/'s'; 291 diff(PID_setPointFilt)=0/'s'; 296 292 297 293 end
Note: See TracChangeset
for help on using the changeset viewer.