基于Hebb的单神经元自适应PID控制——问题求助
function [sys,x0,str,ts] = sj_PID1(t,x,u,flag)switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 2,
sys=mdlUpdate(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
case 9,
sys=mdlTerminate(t,x,u);
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 3;
sizes.NumOutputs = 1;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [0;0;0;];
str = [];
ts = [-1 0];
function sys=mdlDerivatives(t,x,u)
sys = [];
function sys=mdlUpdate(t,x,u)
x(3)=x(2);
x(2)=x(1);
x(1)=u;
q1=x(1);
q2=x(1)-x(2);
q3=x(1)-2*x(2)+x(3);
sys =[q1;q2;q3];
function sys=mdlOutputs(t,x,u)
persistent wkpl_1 wkil_1 wkdl_1 ul_1
xiteP=700;
xiteI=10;
xiteD=60;
if t==0
wkpl_1=rand;
wkil_1=rand;
wkdl_1=rand;
ul_1=0;
end
% %有监督的Hebb学习算法的权值调整规则
wkil=wkil_1+xiteI*x(1)*ul_1*x(1);%I
wkpl=wkpl_1+xiteP*x(1)*ul_1*x(2);%P
wkdl=wkdl_1+xiteD*x(1)*ul_1*x(3);%D
waddl=abs(wkpl)+abs(wkil)+abs(wkdl);
wlll=wkpl/waddl;
wl22=wkil/waddl;
wl33=wkdl/waddl;
wl=[wlll,wl22,wl33];
kl=7;
ul=kl*wl*x; %增量型
wkpl_1=wkpl;
wkdl_1=wkdl;
wkil_1=wkil;
ul_1=ul+ul_1;
sys=ul;
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 0.01;% Example, set the next hit to be one second later.
sys = t + sampleTime;
function sys=mdlTerminate(t,x,u)
sys = [];