Changeset 684 for branches


Ignore:
Timestamp:
Nov 20, 2008, 3:37:32 PM (14 years ago)
Author:
gerson bicca
Message:

updated PIDincr model

Location:
branches/gui
Files:
3 added
1 deleted
1 edited

Legend:

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

    r560 r684  
    1818using "types";
    1919
    20 Model MPorts
    21 
    22 ATTRIBUTES
    23         Pallete         = false;
    24         Brief           = "Model of Ports to be used with incremental 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 incremental PIDs.";
    39        
    40         VARIABLES
    41 
    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 end
    56 
    5720Model PIDIncr
    5821
    5922ATTRIBUTES
    6023        Pallete         = true;
    61         Icon            = "icon/PIDIncr";
     24        Icon            = "icon/PIDincr";
    6225        Brief           = "Model of incremental PIDs.";
    6326        Info            =
     
    7134";
    7235       
    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 anti-reset windup", Hidden=true);
    94         action       as Real(Hidden=true);
    95        
    96         EQUATIONS
     36PARAMETERS
     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
     57VARIABLES
     58
     59in              Input           as control_signal       (Protected=true, PosX=0, PosY=0.5);
     60out     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 anti-reset windup", Hidden=true);
     80        PID_action                      as Real                                 (Hidden=true);
     81#++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++
     82
     83EQUATIONS
     84
     85"Input "
     86        PID_input*(MaxInput - MinInput) = Input - MinInput;
     87
     88"Output "
     89        Output = PID_output*(MaxOutput-MinOutput) +MinOutput;
     90       
     91"Set Point "
     92        PID_setPoint*(MaxInput - MinInput) = SetPoint - MinInput;
    9793
    9894        if (tau < 1e-6) then
    9995                "Input first order filter"
    100                 (tau + 1e-3*'s')*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;
     96                (tau + 1e-3*'s')*diff(PID_inputFilt)= PID_input - PID_inputFilt;
    10197        else
    10298                "Input first order filter"
    103                 tau*diff(Internal.inputFilt)= Ports.input - Internal.inputFilt;
     99                tau*diff(PID_inputFilt)= PID_input - PID_inputFilt;     
    104100        end
    105101
    106102        if (tauSet < 1e-6) then
    107103                "setPoint first order filter"
    108                 (tauSet + 1e-3*'s')*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
     104                (tauSet + 1e-3*'s')*diff(PID_setPointFilt)= PID_setPoint - PID_setPointFilt;
    109105        else
    110106                "setPoint first order filter"
    111                 tauSet*diff(Internal.setPointFilt)= Ports.setPoint - Internal.setPointFilt;
     107                tauSet*diff(PID_setPointFilt)= PID_setPoint - PID_setPointFilt;
    112108        end
    113109
     
    115111        case "Manual":
    116112                "Error definition for proportional term"
    117                 Internal.error*'s' = Internal.inputFilt*(beta-1.0);
     113                PID_error*'s' = PID_inputFilt*(beta-1.0);
    118114                "Error definition for derivative term"
    119                 Internal.errorD*'s'= Internal.inputFilt*(gamma-1.0);
     115                PID_errorD*'s'= PID_inputFilt*(gamma-1.0);
    120116                "Error definition for integral term"           
    121                 Internal.errorI= 0;
     117                PID_errorI= 0;
    122118        case "Automatic":
    123119                "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);
    125121                "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);
    127123                "Error definition for integral term"
    128                 Internal.errorI = Internal.setPointFilt-Internal.inputFilt;     
     124                PID_errorI = PID_setPointFilt-PID_inputFilt;   
    129125        end
    130126       
    131127        "Calculate proportional term"
    132         Internal.dpropTerm=Internal.error; 
     128        PID_dpropTerm=PID_error; 
    133129       
    134130        if (derivTime equal 0) then
    135131                "Derivative term filter"       
    136                 alpha*(derivTime + 1e-3*'s')*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
     132                alpha*(derivTime + 1e-3*'s')*diff(PID_dFilt) = PID_errorD - PID_dFilt;
    137133        else
    138134                "Derivative term filter"       
    139                 alpha*(derivTime)*diff(Internal.dFilt) = Internal.errorD - Internal.dFilt;
     135                alpha*(derivTime)*diff(PID_dFilt) = PID_errorD - PID_dFilt;
    140136        end
    141137
    142138        "Calculate derivative term"
    143         Internal.dderivTerm = derivTime*diff(Internal.dFilt);
     139        PID_dderivTerm = derivTime*diff(PID_dFilt);
    144140       
    145141    "Unscaled output"
    146         diff(Internal.outp)=Internal.doutp;
     142        diff(PID_outp)=PID_doutp;
    147143
    148144        "Scale outp"
    149         Internal.outps=2*Internal.outp-1;
     145        PID_outps=2*PID_outp-1;
    150146
    151147        switch Clip
    152148        case "Clipped":
    153                 #if abs(Internal.outps)>1 then
     149                #if abs(PID_outps)>1 then
    154150                #       "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;
    156152                #else
    157153                #       "Calculate clipped output when it's not saturated"
    158                 #       Ports.output=Internal.outps;
     154                #       Ports.output=PID_outps;
    159155                #end
    160                 Ports.output = max([0, Internal.outp]);
     156                PID_output = max([0, PID_outp]);
    161157        case "Unclipped":
    162158                "Calculate unclipped output"
    163                 Ports.output=Internal.outp;
     159                PID_output=PID_outp;
    164160        end
    165161       
    166162        switch Action
    167163        case "Direct":
    168                 action = -1.0;
     164                PID_action = -1.0;
    169165        case "Reverse":
    170                 action = 1.0;
     166                PID_action = 1.0;
    171167        end
    172168
     
    176172       
    177173        "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);
    182178
    183179        "Calculate AWFactor - Not in use in this mode"
    184         AWFactor=1;
     180        PID_AWFactor=1;
    185181       
    186182case "Parallel":
    187183       
    188184        "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);
    193189
    194190"Calculate AWFactor - Not in use in this mode"
    195         AWFactor=1;
     191        PID_AWFactor=1;
    196192       
    197193case "Series":
    198194       
    199195        "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');
    204200       
    205201        "Calculate AWFactor - Not in use in this mode"
    206         AWFactor=1;
     202        PID_AWFactor=1;
    207203       
    208204case "Ideal_AWBT":
    209205       
    210206        "Calculate integral term with anti-windup and bumpless transfer"
    211         action*gain*(intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.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_dintTerm-PID_errorI) = PID_output-PID_outp;
     208
     209        "Sum of proportional, integral and derivative terms"
     210        PID_doutp = PID_action*gain*(PID_dpropTerm + PID_dintTerm + PID_dderivTerm);
    215211
    216212        "Calculate AWFactor - Not in use in this mode"
    217         AWFactor=1;
     213        PID_AWFactor=1;
    218214       
    219215case "Parallel_AWBT":
    220216       
    221217        "Calculate integral term with anti-windup and bumpless transfer"
    222         action*gain*(intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.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_dintTerm-PID_errorI) = PID_output-PID_outp;
     219       
     220        "Sum of proportional, integral and derivative terms"
     221        PID_doutp = PID_action*(gain*PID_dpropTerm + PID_dintTerm + PID_dderivTerm);
    226222
    227223"Calculate AWFactor - Not in use in this mode"
    228         AWFactor=1;
     224        PID_AWFactor=1;
    229225
    230226case "Series_AWBT":
    231227       
    232228        "Calculate integral term with anti-windup and bumpless transfer"
    233         action*gain*(intTime*Internal.dintTerm-Internal.errorI) = Ports.output-Internal.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_dintTerm-PID_errorI) = PID_output-PID_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');
    237233
    238234"Calculate AWFactor - Not in use in this mode"
    239         AWFactor=1;
     235        PID_AWFactor=1;
    240236       
    241237case "Ideal_AW":
    242238       
    243239        "Calculate integral term with anti-windup"
    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 then
    250                 "Calculate AWFactor"
    251                 AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
    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*100-102);
     248        else
     249                "Calculate AWFactor"
     250                PID_AWFactor=1;
    255251        end
    256252
     
    258254       
    259255        "Calculate integral term with anti-windup"
    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 then
    266                 "Calculate AWFactor"
    267                 AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
    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*100-102);
     264        else
     265                "Calculate AWFactor"
     266                PID_AWFactor=1;
    271267        end
    272268
     
    274270       
    275271        "Calculate integral term with anti-windup"
    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 then
    282                 "Calculate AWFactor"
    283                 AWFactor=-tanh(sign(Internal.outps)*Internal.outps*100-102);
    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*100-102);
     280        else
     281                "Calculate AWFactor"
     282                PID_AWFactor=1;
    287283        end
    288284
     
    290286
    291287        INITIAL
    292         Ports.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';
    296292       
    297293end
Note: See TracChangeset for help on using the changeset viewer.