Changeset 558 for branches/gui/eml


Ignore:
Timestamp:
Jul 21, 2008, 5:41:41 PM (14 years ago)
Author:
Rafael de Pelegrini Soares
Message:

Added some simple PI controllers and another signal models

Location:
branches/gui/eml
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/eml/controllers/PIDIncr.mso

    r555 r558  
    165165        switch Action
    166166        case "Direct":
     167                action = -1.0;
     168        case "Reverse":
    167169                action = 1.0;
    168         case "Reverse":
    169                 action = -1.0;
    170170        end
    171171
     
    295295       
    296296end
    297 
    298 
    299 Model PID_gui as PIDIncr
    300         ATTRIBUTES
    301         Pallete         = true;
    302         Icon            = "icon/PIDIncr";
    303 
    304         PARAMETERS
    305         MinInput as control_signal;
    306         MaxInput as control_signal;
    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=1, PosY=0.5);
    311         SetPoint as control_signal;
    312        
    313         EQUATIONS
    314         Ports.input*(MaxInput - MinInput) = Input - MinInput;
    315         Ports.output = Output;
    316         Ports.setPoint*(MaxInput - MinInput) = SetPoint - MinInput;
    317 end
  • branches/gui/eml/controllers/PIDs.mso

    r354 r558  
    1818using "types";
    1919
    20 Model MParameters
    21 
    22 ATTRIBUTES
    23         Pallete         = false;
    24         Brief           = "Model of Parameters to be used with PIDs.";
    25        
    26         VARIABLES
    27        
    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 end
    39 
    40 Model MOptions 
    41 
    42 ATTRIBUTES
    43         Pallete         = false;
    44         Brief           = "Model of Options to be used with PIDs.";
    45        
    46         VARIABLES       
    47        
    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 end
    53 
    5420Model MPorts
    5521
     
    9157
    9258ATTRIBUTES
    93         Pallete         = true;
     59        Pallete         = false;
    9460        Icon            = "icon/PID";
    9561        Brief           = "Model of PIDs.";
     
    10571       
    10672        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
    11289        Internal           as MInternal_Variables;
    11390        Ports              as MPorts;
    11491        AWFactor     as Real     (Brief="Integral term multiplier used in anti-reset windup");
     92        action       as Real(Protected=true);
    11593       
    11694        INITIAL
     
    122100        EQUATIONS
    123101
    124         if (Parameters.tau equal 0) then
     102        if (tau equal 0) then
    125103                "Input first order filter"
    126                 (Parameters.tau + 1e-3*'s')*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;
     104                (tau + 1e-3*'s')*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;
    127105        else
    128106                "Input first order filter"
    129                 Parameters.tau*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;     
    130         end
    131 
    132         if (Parameters.tauSet equal 0) then
     107                tau*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;
     108        end
     109
     110        if (tauSet equal 0) then
    133111                "setPoint first order filter"
    134                 (Parameters.tauSet + 1e-3*'s')*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
     112                (tauSet + 1e-3*'s')*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
    135113        else
    136114                "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":
    141120                "Error definition for proportional term"
    142                 Internal.error = Internal.inputFilt*(Parameters.beta-1.0);
     121                Internal.error = Internal.inputFilt*(beta-1.0);
    143122                "Error definition for derivative term"
    144                 Internal.errorD= Internal.inputFilt*(Parameters.gamma-1.0);
     123                Internal.errorD= Internal.inputFilt*(gamma-1.0);
    145124                "Error definition for integral term"           
    146125                Internal.errorI= 0;
    147         else
     126        case "Automatic":
    148127                "Error definition for proportional term"                       
    149                 Internal.error = Parameters.beta*Internal.setPointFilt - Internal.inputFilt;
     128                Internal.error = beta*Internal.setPointFilt - Internal.inputFilt;
    150129                "Error definition for derivative term"
    151                 Internal.errorD = Parameters.gamma*Internal.setPointFilt - Internal.inputFilt;
     130                Internal.errorD = gamma*Internal.setPointFilt - Internal.inputFilt;
    152131                "Error definition for integral term"
    153132                Internal.errorI = Internal.setPointFilt-Internal.inputFilt;
     
    157136        Internal.propTerm=Internal.error;
    158137       
    159         if (Parameters.derivTime equal 0) then
     138        if (derivTime equal 0) then
    160139                "Derivative term filter"       
    161                 Parameters.alpha*(Parameters.derivTime + 1e-3*'s')*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
     140                alpha*(derivTime + 1e-3*'s')*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
    162141        else
    163142                "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;
    165144        end
    166145
    167146        "Calculate derivative term"
    168         Internal.derivTerm = Parameters.derivTime*diff(Internal.dFilt);
     147        Internal.derivTerm = derivTime*diff(Internal.dFilt);
    169148       
    170149        "Scale outp"
    171150        Internal.outps=2*Internal.outp-1;
    172151       
    173         if Options.clip equal 1 then
     152        switch Clip
     153        case "Clipped":
    174154                if abs(Internal.outps)>1 then
    175155                        "Calculate clipped output when it´s saturated"
     
    179159                        Ports.output=Internal.outp;
    180160                end
    181         else
     161        case "Unclipped":
    182162                "Calculate unclipped output"
    183163                Ports.output=Internal.outp;
    184164        end
    185165
     166        switch Action
     167        case "Direct":
     168                action = -1.0;
     169        case "Reverse":
     170                action = 1.0;
     171        end
     172
     173
    186174switch PID_Select
    187175       
     
    189177       
    190178        "Calculate integral term with anti-windup"
    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 then
     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 then
    197185                "Calculate AWFactor"
    198186                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
     
    205193       
    206194        "Calculate integral term with anti-windup"
    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 then
     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 then
    213201                "Calculate AWFactor"
    214202                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
     
    222210
    223211        "Calculate integral term with anti-windup"     
    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 then
     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 then
    230218                "Calculate AWFactor"           
    231219                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
     
    238226       
    239227        "Calculate integral term"       
    240         Parameters.intTime*diff(Internal.intTerm) = Internal.errorI;
     228        intTime*diff(Internal.intTerm) = Internal.errorI;
    241229       
    242230        "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);
    244232
    245233        "Calculate AWFactor - Not in use in this mode"
     
    249237       
    250238        "Calculate integral term"       
    251         Parameters.intTime*diff(Internal.intTerm) = Internal.errorI;
     239        intTime*diff(Internal.intTerm) = Internal.errorI;
    252240       
    253241        "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);
    255243
    256244        "Calculate AWFactor - Not in use in this mode"
     
    260248       
    261249        "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));
    266254       
    267255        "Calculate AWFactor - Not in use in this mode"
     
    271259       
    272260        "Calculate integral term with anti-windup and bumpless transfer"       
    273         Options.action*Parameters.gain*(Parameters.intTime*diff(Internal.intTerm)-Internal.errorI) = Ports.output-Internal.outp;       
     261        action*gain*(intTime*diff(Internal.intTerm)-Internal.errorI) = Ports.output-Internal.outp;     
    274262       
    275263        "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);
    277265       
    278266        "Calculate AWFactor - Not in use in this mode"
     
    282270       
    283271        "Calculate integral term with anti-windup and bumpless transfer"       
    284         Options.action*Parameters.gain*(Parameters.intTime*diff(Internal.intTerm)-Internal.errorI) = Ports.output-Internal.outp;       
     272        action*gain*(intTime*diff(Internal.intTerm)-Internal.errorI) = Ports.output-Internal.outp;     
    285273       
    286274        "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);
    288276       
    289277        "Calculate AWFactor - Not in use in this mode"
     
    293281       
    294282        "Calculate integral term with anti-windup and bumpless transfer"
    295         Options.action*Parameters.gain*(Parameters.intTime*diff(Internal.intTerm)-Internal.errorI) = Ports.output-Internal.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.output-Internal.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       
     291end
     292
     293end
     294
     295
     296Model 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
     306in      Input as control_signal(Protected=true, PosX=0, PosY=0.5);
     307out     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;
     314end
     315
     316Model 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");
     330in      u as control_signal(Brief="Input signal", PosX=0, PosY=0.5);
     331out     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;
     336end
     337
     338
     339Model 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
     350out     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
     358end
     359
     360Model ConstantSignal
     361        ATTRIBUTES
     362        Pallete         = true;
     363        Icon            = "icon/PIDIncr";
     364
     365        PARAMETERS
     366        Value as control_signal;
     367       
     368        VARIABLES
     369out     OutSignal as control_signal(PosX=1, PosY=0.5);
     370
     371        EQUATIONS
     372        OutSignal = Value;
     373end
  • branches/gui/eml/controllers/multiply.mso

    r354 r558  
    3535       
    3636        VARIABLES
    37         input1 as Real (Brief="input signal 1");
    38         input2 as Real (Brief="input signal 2");
    39         output as Real (Brief="output signal");
     37in      input1 as control_signal (Brief="input signal 1", PosX=0, PosY=0.75);
     38in      input2 as control_signal (Brief="input signal 2", PosX=0, PosY=0.25);
     39out     output as control_signal (Brief="output signal", PosX=1, PosY=0.5);
    4040       
    4141        EQUATIONS
  • branches/gui/eml/pressure_changers/valve.mso

    r372 r558  
    212212        end
    213213end
     214
     215
     216Model valve_flow
     217        ATTRIBUTES
     218        Pallete         = true;
     219        Icon            = "icon/Valve";
     220        Brief           = "Model of a very simple valve - used in distillation column models.";
     221        Info            =
     222"== Assumptions ==
     223* no flashing liquid in the valve;
     224* the flow in the valve is adiabatic;
     225* dynamics in the valve are neglected;
     226* linear flow type.
     227       
     228== Specify ==
     229* the inlet stream
     230* the plug position (x) OR outlet temperature (Outlet.T) OR outlet pressure (Outlet.P)
     231       
     232        OR             
     233       
     234* the inlet stream excluding its flow (Inlet.F)
     235* the outlet pressure (Outlet.P) OR outlet flow (Outlet.F)
     236* the plug position (x)
     237";
     238
     239        PARAMETERS
     240outer PP as Plugin(Type="PP");
     241outer NComp as Integer;
     242
     243        MinFlow as flow_mol(Default=0);
     244        MaxFlow as flow_mol(Default=1000);
     245       
     246        VARIABLES
     247in      Inlet   as stream       (Brief = "Inlet stream", PosX=0, PosY=0.7365, Symbol="_{in}");
     248out     Outlet  as streamPH     (Brief = "Outlet stream", PosX=1, PosY=0.7365, Symbol="_{out}");
     249in      FlowFraction as fraction (Brief="Flow Signal", PosX=0.5, PosY=0);
     250       
     251        EQUATIONS
     252        "Overall Molar Balance"
     253        Inlet.F = Outlet.F;
     254       
     255        "Componente Molar Balance"
     256        Inlet.z = Outlet.z;
     257       
     258        "Energy Balance"
     259        Inlet.h = Outlet.h;
     260
     261        "Pressure"
     262        Outlet.P  = Inlet.P;
     263
     264        "Flow"
     265        Outlet.F = MinFlow + FlowFraction*(MaxFlow-MinFlow);
     266end
     267
Note: See TracChangeset for help on using the changeset viewer.