Changeset 558 for branches/gui/eml/controllers/PIDs.mso
 Timestamp:
 Jul 21, 2008, 5:41:41 PM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/gui/eml/controllers/PIDs.mso
r354 r558 18 18 using "types"; 19 19 20 Model MParameters21 22 ATTRIBUTES23 Pallete = false;24 Brief = "Model of Parameters to be used with PIDs.";25 26 VARIABLES27 28 alpha as positive (Brief="Derivative term filter constant", Default=1);29 beta as positive (Brief="Proportional term setPoint change filter");30 bias as control_signal (Brief="Previous scaled bias", Default=0.5);31 derivTime as time_sec (Brief="Derivative time constant");32 intTime as time_sec (Brief="Integral time constant");33 gain as positive (Brief="Controller gain", Default=0.5);34 gamma as positive (Brief="Derivative term SP change filter");35 tau as time_sec (Brief="Input filter time constant");36 tauSet as time_sec (Brief="Input filter time constant");37 38 end39 40 Model MOptions41 42 ATTRIBUTES43 Pallete = false;44 Brief = "Model of Options to be used with PIDs.";45 46 VARIABLES47 48 action as Real (Brief="Controller action: (1) Direct,(1) Reverse", Default=1);49 autoMan as Real (Brief="Controller option: (0) Automatic, (1) Manual", Default=0);50 clip as Real (Brief="Controller option: (1) output clipped, (0) output unclipped", Default=1);51 52 end53 54 20 Model MPorts 55 21 … … 91 57 92 58 ATTRIBUTES 93 Pallete = true;59 Pallete = false; 94 60 Icon = "icon/PID"; 95 61 Brief = "Model of PIDs."; … … 105 71 106 72 PARAMETERS 107 PID_Select as Switcher (Brief="Type of PID", Valid=["Ideal","Parallel","Series","Ideal_AWBT","Parallel_AWBT","Series_AWBT","Ideal_AW","Parallel_AW","Series_AW"], Default = "Ideal"); 108 109 VARIABLES 110 Parameters as MParameters; 111 Options as MOptions; 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 112 89 Internal as MInternal_Variables; 113 90 Ports as MPorts; 114 91 AWFactor as Real (Brief="Integral term multiplier used in antireset windup"); 92 action as Real(Protected=true); 115 93 116 94 INITIAL … … 122 100 EQUATIONS 123 101 124 if ( Parameters.tau equal 0) then102 if (tau equal 0) then 125 103 "Input first order filter" 126 ( Parameters.tau + 1e3*'s')*diff(Internal.inputFilt)= Ports.input  Internal.inputFilt;104 (tau + 1e3*'s')*diff(Internal.inputFilt)= Ports.input  Internal.inputFilt; 127 105 else 128 106 "Input first order filter" 129 Parameters.tau*diff(Internal.inputFilt)= Ports.input  Internal.inputFilt;130 end 131 132 if ( Parameters.tauSet equal 0) then107 tau*diff(Internal.inputFilt)= Ports.input  Internal.inputFilt; 108 end 109 110 if (tauSet equal 0) then 133 111 "setPoint first order filter" 134 ( Parameters.tauSet + 1e3*'s')*diff(Internal.setPointFilt)= Ports.setPoint  Internal.setPointFilt;112 (tauSet + 1e3*'s')*diff(Internal.setPointFilt)= Ports.setPoint  Internal.setPointFilt; 135 113 else 136 114 "setPoint first order filter" 137 Parameters.tauSet*diff(Internal.setPointFilt)= Ports.setPoint  Internal.setPointFilt; 138 end 139 140 if Options.autoMan equal 1 then 115 tauSet*diff(Internal.setPointFilt)= Ports.setPoint  Internal.setPointFilt; 116 end 117 118 switch Mode 119 case "Manual": 141 120 "Error definition for proportional term" 142 Internal.error = Internal.inputFilt*( Parameters.beta1.0);121 Internal.error = Internal.inputFilt*(beta1.0); 143 122 "Error definition for derivative term" 144 Internal.errorD= Internal.inputFilt*( Parameters.gamma1.0);123 Internal.errorD= Internal.inputFilt*(gamma1.0); 145 124 "Error definition for integral term" 146 125 Internal.errorI= 0; 147 else126 case "Automatic": 148 127 "Error definition for proportional term" 149 Internal.error = Parameters.beta*Internal.setPointFilt  Internal.inputFilt;128 Internal.error = beta*Internal.setPointFilt  Internal.inputFilt; 150 129 "Error definition for derivative term" 151 Internal.errorD = Parameters.gamma*Internal.setPointFilt  Internal.inputFilt;130 Internal.errorD = gamma*Internal.setPointFilt  Internal.inputFilt; 152 131 "Error definition for integral term" 153 132 Internal.errorI = Internal.setPointFiltInternal.inputFilt; … … 157 136 Internal.propTerm=Internal.error; 158 137 159 if ( Parameters.derivTime equal 0) then138 if (derivTime equal 0) then 160 139 "Derivative term filter" 161 Parameters.alpha*(Parameters.derivTime + 1e3*'s')*diff(Internal.dFilt) = Internal.errorD  Internal.dFilt;140 alpha*(derivTime + 1e3*'s')*diff(Internal.dFilt) = Internal.errorD  Internal.dFilt; 162 141 else 163 142 "Derivative term filter" 164 Parameters.alpha*(Parameters.derivTime)*diff(Internal.dFilt) = Internal.errorD  Internal.dFilt;143 alpha*(derivTime)*diff(Internal.dFilt) = Internal.errorD  Internal.dFilt; 165 144 end 166 145 167 146 "Calculate derivative term" 168 Internal.derivTerm = Parameters.derivTime*diff(Internal.dFilt);147 Internal.derivTerm = derivTime*diff(Internal.dFilt); 169 148 170 149 "Scale outp" 171 150 Internal.outps=2*Internal.outp1; 172 151 173 if Options.clip equal 1 then 152 switch Clip 153 case "Clipped": 174 154 if abs(Internal.outps)>1 then 175 155 "Calculate clipped output when it´s saturated" … … 179 159 Ports.output=Internal.outp; 180 160 end 181 else161 case "Unclipped": 182 162 "Calculate unclipped output" 183 163 Ports.output=Internal.outp; 184 164 end 185 165 166 switch Action 167 case "Direct": 168 action = 1.0; 169 case "Reverse": 170 action = 1.0; 171 end 172 173 186 174 switch PID_Select 187 175 … … 189 177 190 178 "Calculate integral term with antiwindup" 191 Parameters.intTime*diff(Internal.intTerm) = AWFactor*Internal.errorI;192 193 "Sum of proportional, integral and derivative terms" 194 Internal.outp = Parameters.bias + Options.action*Parameters.gain*(Internal.propTerm + Internal.intTerm + Internal.derivTerm);195 196 if abs(Internal.outps)>1 and ( Options.action*sign(Internal.outps)*Internal.errorI)>0 then179 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 then 197 185 "Calculate AWFactor" 198 186 AWFactor=tanh(sign(Internal.outps)*Internal.outps*100102); … … 205 193 206 194 "Calculate integral term with antiwindup" 207 Parameters.intTime*diff(Internal.intTerm) = AWFactor*Internal.errorI;208 209 "Sum of proportional, integral and derivative terms" 210 Internal.outp = Parameters.bias + Options.action*(Parameters.gain*Internal.propTerm + Internal.intTerm + Internal.derivTerm);211 212 if abs(Internal.outps)>1 and ( Options.action*sign(Internal.outps)*Internal.errorI)>0 then195 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 then 213 201 "Calculate AWFactor" 214 202 AWFactor=tanh(sign(Internal.outps)*Internal.outps*100102); … … 222 210 223 211 "Calculate integral term with antiwindup" 224 Parameters.intTime*diff(Internal.intTerm) = AWFactor*Internal.errorI;225 226 "Sum of proportional, integral and derivative terms" 227 Internal.outp = Parameters.bias + Options.action*(Parameters.gain*(Internal.propTerm + Internal.intTerm)*(1 + Internal.derivTerm));228 229 if abs(Internal.outps)>1 and ( Options.action*sign(Internal.outps)*Internal.errorI)>0 then212 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 then 230 218 "Calculate AWFactor" 231 219 AWFactor=tanh(sign(Internal.outps)*Internal.outps*100102); … … 238 226 239 227 "Calculate integral term" 240 Parameters.intTime*diff(Internal.intTerm) = Internal.errorI;228 intTime*diff(Internal.intTerm) = Internal.errorI; 241 229 242 230 "Sum of proportional, integral and derivative terms" 243 Internal.outp = Parameters.bias + Options.action*Parameters.gain*(Internal.propTerm + Internal.intTerm + Internal.derivTerm);231 Internal.outp = bias + action*gain*(Internal.propTerm + Internal.intTerm + Internal.derivTerm); 244 232 245 233 "Calculate AWFactor  Not in use in this mode" … … 249 237 250 238 "Calculate integral term" 251 Parameters.intTime*diff(Internal.intTerm) = Internal.errorI;239 intTime*diff(Internal.intTerm) = Internal.errorI; 252 240 253 241 "Sum of proportional, integral and derivative terms" 254 Internal.outp = Parameters.bias + Options.action*(Parameters.gain*Internal.propTerm + Internal.intTerm + Internal.derivTerm);242 Internal.outp = bias + action*(gain*Internal.propTerm + Internal.intTerm + Internal.derivTerm); 255 243 256 244 "Calculate AWFactor  Not in use in this mode" … … 260 248 261 249 "Calculate integral term" 262 Parameters.intTime*diff(Internal.intTerm) = Internal.errorI;263 264 "Sum of proportional, integral and derivative terms" 265 Internal.outp = Parameters.bias + Options.action*(Parameters.gain*(Internal.propTerm + Internal.intTerm)*(1 + Internal.derivTerm));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)); 266 254 267 255 "Calculate AWFactor  Not in use in this mode" … … 271 259 272 260 "Calculate integral term with antiwindup and bumpless transfer" 273 Options.action*Parameters.gain*(Parameters.intTime*diff(Internal.intTerm)Internal.errorI) = Ports.outputInternal.outp;261 action*gain*(intTime*diff(Internal.intTerm)Internal.errorI) = Ports.outputInternal.outp; 274 262 275 263 "Sum of proportional, integral and derivative terms" 276 Internal.outp = Parameters.bias + Options.action*Parameters.gain*(Internal.propTerm + Internal.intTerm + Internal.derivTerm);264 Internal.outp = bias + action*gain*(Internal.propTerm + Internal.intTerm + Internal.derivTerm); 277 265 278 266 "Calculate AWFactor  Not in use in this mode" … … 282 270 283 271 "Calculate integral term with antiwindup and bumpless transfer" 284 Options.action*Parameters.gain*(Parameters.intTime*diff(Internal.intTerm)Internal.errorI) = Ports.outputInternal.outp;272 action*gain*(intTime*diff(Internal.intTerm)Internal.errorI) = Ports.outputInternal.outp; 285 273 286 274 "Sum of proportional, integral and derivative terms" 287 Internal.outp = Parameters.bias + Options.action*(Parameters.gain*Internal.propTerm + Internal.intTerm + Internal.derivTerm);275 Internal.outp = bias + action*(gain*Internal.propTerm + Internal.intTerm + Internal.derivTerm); 288 276 289 277 "Calculate AWFactor  Not in use in this mode" … … 293 281 294 282 "Calculate integral term with antiwindup and bumpless transfer" 295 Options.action*Parameters.gain*(Parameters.intTime*diff(Internal.intTerm)Internal.errorI) = Ports.outputInternal.outp; 296 297 "Sum of proportional, integral and derivative terms" 298 Internal.outp = Parameters.bias + Options.action*(Parameters.gain*(Internal.propTerm + Internal.intTerm)*(1 + Internal.derivTerm)); 299 300 "Calculate AWFactor  Not in use in this mode" 301 AWFactor=1; 302 303 end 304 305 end 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 ATTRIBUTES 298 Pallete = true; 299 Icon = "icon/PIDIncr"; 300 301 PARAMETERS 302 MinInput as control_signal(Default=1000); 303 MaxInput as control_signal(Default=1000); 304 305 VARIABLES 306 in Input as control_signal(Protected=true, PosX=0, PosY=0.5); 307 out Output as control_signal(Protected=true, PosX=1, PosY=0.5); 308 SetPoint as control_signal; 309 310 EQUATIONS 311 Ports.input*(MaxInput  MinInput) = Input  MinInput; 312 Ports.output = Output; 313 Ports.setPoint*(MaxInput  MinInput) = SetPoint  MinInput; 314 end 315 316 Model FirstOrder 317 ATTRIBUTES 318 Pallete = true; 319 Icon = "icon/PIDIncr"; 320 321 PARAMETERS 322 tau as Real (Brief="Time Constant", Unit = 's', Default=4); 323 A as Real (Unit='1/s'); 324 B as Real (Unit='1/s'); 325 C as Real; 326 D as Real(Default=0); 327 328 VARIABLES 329 x as control_signal(Brief="State"); 330 in u as control_signal(Brief="Input signal", PosX=0, PosY=0.5); 331 out y as control_signal(Brief="Output signal", PosX=1, PosY=0.5); 332 333 EQUATIONS 334 diff(x) = A*x + B*u; 335 y = C*x + D*u; 336 end 337 338 339 Model StepSignal 340 ATTRIBUTES 341 Pallete = true; 342 Icon = "icon/PIDIncr"; 343 344 PARAMETERS 345 StepTime as positive(Unit='s'); 346 StartValue as control_signal; 347 FinalValue as control_signal; 348 349 VARIABLES 350 out OutSignal as control_signal(PosX=1, PosY=0.5); 351 352 EQUATIONS 353 if(time < StepTime) then 354 OutSignal = StartValue; 355 else 356 OutSignal = FinalValue; 357 end 358 end 359 360 Model ConstantSignal 361 ATTRIBUTES 362 Pallete = true; 363 Icon = "icon/PIDIncr"; 364 365 PARAMETERS 366 Value as control_signal; 367 368 VARIABLES 369 out OutSignal as control_signal(PosX=1, PosY=0.5); 370 371 EQUATIONS 372 OutSignal = Value; 373 end
Note: See TracChangeset
for help on using the changeset viewer.