| Description of pid_isatd |
| AutotunerPID Toolkit |
 |
pid_isatd
PURPOSE 
Discrete time ISA-PID (implemented as a Matlab S-function).
SYNOPSIS 
function [sys,x0,str,ts] = pid_isatd(t,x,u,flag,Ts,umin,umax,As,hystLevel)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
This function is called by:
SUBFUNCTIONS 
- function [sys,x0,str,ts,stato] = mdlInitializeSizes(Ts)
- function [sys,stato] = mdlOutputs(t,x,u,stato,Ts,umin,umax,As,hystLevel)
SOURCE CODE 
0001 function [sys,x0,str,ts] = pid_isatd(t,x,u,flag,Ts,umin,umax,As,hystLevel)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 persistent stato;
0022
0023 CVBlock = 'ManValue';
0024 switch flag,
0025 case 0,
0026 [sys,x0,str,ts,stato] = mdlInitializeSizes(Ts);
0027 case 3,
0028 [sys,stato] = mdlOutputs(t,x,u,stato,Ts,umin,umax,As,hystLevel);
0029 case { 1, 2, 4, 9 }
0030 sys=[];
0031 otherwise
0032 error(['Unhandled flag = ', num2str(flag)]);
0033 end
0034
0035
0036
0037
0038
0039
0040
0041 function [sys,x0,str,ts,stato] = mdlInitializeSizes(Ts)
0042
0043 sizes = simsizes;
0044
0045 sizes.NumContStates = 0;
0046 sizes.NumDiscStates = 0;
0047 sizes.NumOutputs = 1;
0048 sizes.NumInputs = 4;
0049 sizes.DirFeedthrough = 1;
0050 sizes.NumSampleTimes = 1;
0051
0052 sys = simsizes(sizes);
0053
0054 x0 = [];
0055 str = [];
0056 ts = [Ts 0];
0057 stato = [0 0 0 0 0];
0058
0059
0060
0061
0062
0063
0064 function [sys,stato] = mdlOutputs(t,x,u,stato,Ts,umin,umax,As,hystLevel)
0065 global CVVALUE
0066 global IDENTIFICATION_METHOD
0067 global TUNING_METHOD
0068 global PIDPARAMETERS
0069
0070
0071 sp = u(1);
0072 pv = u(2);
0073
0074
0075 auto = u(3);
0076 autotune = u(4);
0077
0078
0079 K = PIDPARAMETERS(1);
0080 Ti = PIDPARAMETERS(2);
0081 Td = PIDPARAMETERS(3);
0082 N = PIDPARAMETERS(4);
0083 b = PIDPARAMETERS(5);
0084
0085
0086
0087 ui = stato(1);
0088 ud = stato(2);
0089
0090
0091 pvold = stato(3);
0092 cvold = stato(4);
0093 atold = stato(5);
0094
0095
0096
0097 if Ti
0098 a1 = K*Ts/Ti;
0099 else
0100
0101 a1 = 0;
0102 end
0103 b1 = Td/(Td + N*Ts);
0104 b2 = K*Td*N/(Td + N*Ts);
0105
0106
0107 up = K*(b*sp - pv);
0108
0109 ud = b1*ud - b2*(pv-pvold);
0110
0111 if ~autotune & atold
0112
0113 ui = cvold - up - ud;
0114 end
0115
0116 if autotune
0117 if strcmp(IDENTIFICATION_METHOD,'STEP')
0118
0119 cv = CVVALUE+As;
0120 elseif strcmp(IDENTIFICATION_METHOD,'RELAY')
0121 if ~atold
0122 cv = CVVALUE+As;
0123 else
0124 if pv >= sp+hystLevel
0125 cv = CVVALUE-As;
0126 elseif pv <= sp-hystLevel
0127 cv = CVVALUE+As;
0128 else
0129 cv = cvold;
0130 end
0131 end
0132 end
0133 else
0134 if ~auto
0135
0136 cv = CVVALUE;
0137 else
0138
0139 cv = up + ui + ud;
0140 end
0141
0142 if cv > umax
0143
0144
0145 cv = umax;
0146 elseif cv < umin
0147
0148 cv = umin;
0149 else
0150
0151 if auto
0152 ui = ui + a1*(sp-pv);
0153 else
0154 ui = cv - up - ud;
0155 end
0156 end
0157
0158 CVVALUE = cv;
0159 end
0160
0161
0162 stato = [ui ud pv cv autotune];
0163
0164 sys = cv;
0165
| pid_autotuner | | pid_structure |  |
Generated on Wed 17-Mar-2004 09:29:44 by m2html © 2003
|
|