Changeset 683 for branches/gui/eml/controllers/PIDs.mso
 Timestamp:
 Nov 19, 2008, 7:21:38 PM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

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