Ignore:
Timestamp:
Jul 18, 2008, 4:01:13 PM (14 years ago)
Author:
Rafael de Pelegrini Soares
Message:

Updating the models to be usable by the gui

File:
1 edited

Legend:

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

    r354 r555  
    1818using "types";
    1919
    20 Model MParameters
    21 
    22 ATTRIBUTES
    23         Pallete         = false;
    24         Brief           = "Model of Parameters to be used with incremental 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 incremental 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
     
    10874       
    10975        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");
    11089       
    11190        VARIABLES
    112         Parameters         as MParameters;
    113         Options            as MOptions;
    11491        Internal           as MInternal_Variables;
    11592        Ports              as MPorts;
    116         AWFactor     as Real     (Brief="Integral term multiplier used in anti-reset windup");
     93        AWFactor     as Real(Brief="Integral term multiplier used in anti-reset windup", Hidden=true);
     94        action       as Real(Hidden=true);
    11795       
    11896        EQUATIONS
    11997
    120         if (Parameters.tau equal 0) then
     98        if (tau equal 0) then
    12199                "Input first order filter"
    122                 (Parameters.tau + 1e-3*'s')*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;
     100                (tau + 1e-3*'s')*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;
    123101        else
    124102                "Input first order filter"
    125                 Parameters.tau*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;     
    126         end
    127 
    128         if (Parameters.tauSet equal 0) then
     103                tau*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;
     104        end
     105
     106        if (tauSet equal 0) then
    129107                "setPoint first order filter"
    130                 (Parameters.tauSet + 1e-3*'s')*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
     108                (tauSet + 1e-3*'s')*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
    131109        else
    132110                "setPoint first order filter"
    133                 Parameters.tauSet*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
    134         end
    135 
    136         if Options.autoMan equal 1 then
     111                tauSet*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
     112        end
     113
     114        switch Mode
     115        case "Manual":
    137116                "Error definition for proportional term"
    138                 Internal.error*'s' = Internal.inputFilt*(Parameters.beta-1.0);
     117                Internal.error*'s' = Internal.inputFilt*(beta-1.0);
    139118                "Error definition for derivative term"
    140                 Internal.errorD*'s'= Internal.inputFilt*(Parameters.gamma-1.0);
     119                Internal.errorD*'s'= Internal.inputFilt*(gamma-1.0);
    141120                "Error definition for integral term"           
    142121                Internal.errorI= 0;
    143         else
     122        case "Automatic":
    144123                "Error definition for proportional term"                       
    145                 Internal.error = Parameters.beta*diff(Internal.setPointFilt) - diff(Internal.inputFilt);
     124                Internal.error = beta*diff(Internal.setPointFilt) - diff(Internal.inputFilt);
    146125                "Error definition for derivative term"
    147                 Internal.errorD = Parameters.gamma*diff(Internal.setPointFilt) - diff(Internal.inputFilt);
     126                Internal.errorD = gamma*diff(Internal.setPointFilt) - diff(Internal.inputFilt);
    148127                "Error definition for integral term"
    149128                Internal.errorI = Internal.setPointFilt-Internal.inputFilt;     
     
    153132        Internal.dpropTerm=Internal.error; 
    154133       
    155         if (Parameters.derivTime equal 0) then
     134        if (derivTime equal 0) then
    156135                "Derivative term filter"       
    157                 Parameters.alpha*(Parameters.derivTime + 1e-3*'s')*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
     136                alpha*(derivTime + 1e-3*'s')*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
    158137        else
    159138                "Derivative term filter"       
    160                 Parameters.alpha*(Parameters.derivTime)*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
     139                alpha*(derivTime)*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
    161140        end
    162141
    163142        "Calculate derivative term"
    164         Internal.dderivTerm = Parameters.derivTime*diff(Internal.dFilt);
     143        Internal.dderivTerm = derivTime*diff(Internal.dFilt);
    165144       
    166145    "Unscaled output"
     
    170149        Internal.outps=2*Internal.outp-1;
    171150
    172         if Options.clip equal 1 then
     151        switch Clip
     152        case "Clipped":
    173153                if abs(Internal.outps)>1 then
    174154                        "Calculate clipped output when it´s saturated"
     
    178158                        Ports.output=Internal.outp;
    179159                end
    180         else
     160        case "Unclipped":
    181161                "Calculate unclipped output"
    182162                Ports.output=Internal.outp;
    183163        end
     164       
     165        switch Action
     166        case "Direct":
     167                action = 1.0;
     168        case "Reverse":
     169                action = -1.0;
     170        end
    184171
    185172switch PID_Select
     
    188175       
    189176        "Calculate integral term"
    190         Parameters.intTime*Internal.dintTerm = Internal.errorI;
    191        
    192         "Sum of proportional, integral and derivative terms"
    193         Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
     177        intTime*Internal.dintTerm = Internal.errorI;
     178       
     179        "Sum of proportional, integral and derivative terms"
     180        Internal.doutp = action*gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
    194181
    195182        "Calculate AWFactor - Not in use in this mode"
     
    199186       
    200187        "Calculate integral term"
    201         Parameters.intTime*Internal.dintTerm = Internal.errorI;
    202        
    203         "Sum of proportional, integral and derivative terms"
    204         Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
     188        intTime*Internal.dintTerm = Internal.errorI;   
     189       
     190        "Sum of proportional, integral and derivative terms"
     191        Internal.doutp = action*(gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
    205192
    206193"Calculate AWFactor - Not in use in this mode"
     
    210197       
    211198        "Calculate integral term"
    212         Parameters.intTime*Internal.dintTerm = Internal.errorI;
    213        
    214         "Sum of proportional, integral and derivative terms"
    215         Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');
     199        intTime*Internal.dintTerm = Internal.errorI;   
     200       
     201        "Sum of proportional, integral and derivative terms"
     202        Internal.doutp = action*(gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');
    216203       
    217204        "Calculate AWFactor - Not in use in this mode"
     
    221208       
    222209        "Calculate integral term with anti-windup and bumpless transfer"
    223         Options.action*Parameters.gain*(Parameters.intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp;
    224 
    225         "Sum of proportional, integral and derivative terms"
    226         Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
     210        action*gain*(intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp;
     211
     212        "Sum of proportional, integral and derivative terms"
     213        Internal.doutp = action*gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
    227214
    228215        "Calculate AWFactor - Not in use in this mode"
     
    232219       
    233220        "Calculate integral term with anti-windup and bumpless transfer"
    234         Options.action*Parameters.gain*(Parameters.intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp;
    235        
    236         "Sum of proportional, integral and derivative terms"
    237         Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
     221        action*gain*(intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp;
     222       
     223        "Sum of proportional, integral and derivative terms"
     224        Internal.doutp = action*(gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
    238225
    239226"Calculate AWFactor - Not in use in this mode"
     
    243230       
    244231        "Calculate integral term with anti-windup and bumpless transfer"
    245         Options.action*Parameters.gain*(Parameters.intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp;
    246 
    247         "Sum of proportional, integral and derivative terms"
    248         Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');
     232        action*gain*(intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.outp;
     233
     234        "Sum of proportional, integral and derivative terms"
     235        Internal.doutp = action*(gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');
    249236
    250237"Calculate AWFactor - Not in use in this mode"
     
    254241       
    255242        "Calculate integral term with anti-windup"
    256         Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI;
    257        
    258         "Sum of proportional, integral and derivative terms"
    259         Internal.doutp = Options.action*Parameters.gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
    260        
    261         if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then
     243        intTime*Internal.dintTerm = AWFactor*Internal.errorI;
     244       
     245        "Sum of proportional, integral and derivative terms"
     246        Internal.doutp = action*gain*(Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
     247       
     248        if abs(Internal.outps)>1 and (action*sign(Internal.outps)*Internal.errorI)>0 then
    262249                "Calculate AWFactor"
    263250                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
     
    270257       
    271258        "Calculate integral term with anti-windup"
    272         Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI;
    273        
    274         "Sum of proportional, integral and derivative terms"
    275         Internal.doutp = Options.action*(Parameters.gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
    276        
    277         if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then
     259        intTime*Internal.dintTerm = AWFactor*Internal.errorI;
     260       
     261        "Sum of proportional, integral and derivative terms"
     262        Internal.doutp = action*(gain*Internal.dpropTerm + Internal.dintTerm + Internal.dderivTerm);
     263       
     264        if abs(Internal.outps)>1 and (action*sign(Internal.outps)*Internal.errorI)>0 then
    278265                "Calculate AWFactor"
    279266                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
     
    286273       
    287274        "Calculate integral term with anti-windup"
    288         Parameters.intTime*Internal.dintTerm = AWFactor*Internal.errorI;
    289        
    290         "Sum of proportional, integral and derivative terms"
    291         Internal.doutp = Options.action*(Parameters.gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');
    292        
    293         if abs(Internal.outps)>1 and (Options.action*sign(Internal.outps)*Internal.errorI)>0 then
     275        intTime*Internal.dintTerm = AWFactor*Internal.errorI;
     276       
     277        "Sum of proportional, integral and derivative terms"
     278        Internal.doutp = action*(gain*(Internal.dpropTerm + Internal.dintTerm)*(1/'s' + Internal.dderivTerm)*'s');
     279       
     280        if abs(Internal.outps)>1 and (action*sign(Internal.outps)*Internal.errorI)>0 then
    294281                "Calculate AWFactor"
    295282                AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
     
    302289
    303290        INITIAL
    304         Ports.output = Parameters.bias;
     291        Ports.output = bias;   
    305292        diff(Internal.dFilt) = 0/'s^2';
    306293        diff(Internal.inputFilt)=0/'s';
     
    310297
    311298
     299Model 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
     309in      Input as control_signal(Protected=true, PosX=0, PosY=0.5);
     310out     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;
     317end
Note: See TracChangeset for help on using the changeset viewer.