基于RBF网络整定的PID控制
function RBF_PID()%Adaptive PID control based on RBF Identification
%缺点:采样时间不能很长,学习效果不如BP
clc
clear all
close all
%%%%%%%%%%%%%%%%%%%%initial vallue and set the parameter of system %%%%%%%%
Lr=0.25; %RBF learn efficiency
alfa=0.05; belte=0.01; %inertia form of learn
Lrpid=; %采用梯度法的PId的学习效率
input_n=3; %set the construct of RBF net
hidden_n=7; %the number of hidden
output_n=1;
h=0.001;tmax=2; %simulation time and step length
Kpid_1=; %PDi
M=0; Kpid0=; %PDI控制当M=1是仅PID控制
Ci=0.5*rand(input_n,hidden_n);Bi=0.5*rand(hidden_n,1);W=0.5*rand(hidden_n,output_n); %初始值的选取很关键,随机的优势大于都为一的情况
%%%%%%%%%%%%%%%%%%%%%%loop needed value%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y_1=0;u_1=0; input=; W_1=W;W_2=W; W_3=W;
Bi_1=Bi;Bi_2=Bi;Bi_3=Bi;Ci_1=Ci;Ci_2=Ci;Ci_3=Ci;
Xc=; er_1=0;er_2=0;
%yacobin
for k=1:1:tmax/h
%%%%%%%%%%%%%%%%%%%%%be controled model%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rin=1.0*(sin(2*pi*k*h));
yout=(-0.1*y_1+u_1)/(1+y_1^2);
er=rin-yout;
%%%%%%%soling the output of RBF,and regulation the related parameters%%%%%%
for j=1:1:hidden_n
H(j)=exp(-norm(input-Ci(:,j))^2/(2*Bi(j)*Bi(j)));%transfer function
end
ymout=H*W;err=yout-ymout; %RBF output
dW=Lr*err*H.';
W=W_1+dW+alfa*(W_1-W_2)+belte*(W_2-W_3); %weight adjustment
for j=1:1:hidden_n
dBi(j)=err*W(j)*H(j)*(Bi(j)^-3)*norm(input-Ci(:,j))^2;
end
Bi=Bi_1+ Lr*dBi.'+alfa*(Bi_1-Bi_2)+belte*(Bi_2-Bi_3); %扩展常熟调整
for i=1:1:input_n
for j=1:1:hidden_n
dCi(i,j)=err*W(j)*H(j)*(input(i)-Ci(i,j))*(Bi(j)^-2);
end
end
Ci=Ci_1+Lr*dCi+alfa*(Ci_1-Ci_2)+belte*(Ci_2-Ci_3); % center value adjustment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Jacobin calculation%%%%%%%%%%%%%%%%%%%%%%%%%%
%对象的输出对控制输入变化的灵敏度信息,通过神经网络的辨识来获得,用于稍后的Kp,Ki,Kd的调整梯度计算
ydu=0;
forj=1:1:6
ydu=ydu+W(j)*H(j)*(-input(1)+Ci(1,j))/Bi(j)^2;
end
Kpid=Kpid_1+ er*ydu*(Lrpid.*Xc); Kpid(find(Kpid)<0)=0;
switch M;
case 0;
case 1
Kpid=Kpid0;
end;% choose whether the RBF played role
dU=Kpid.'*Xc;
u=u_1+dU;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%parameter update%%%%%%%%%%%%%%%%%%%%%%%%%
u_1=u;input=;y_1=yout; %!!!输入项可更改。。但dU bu 不行
W_3=W_2;W_2=W_1; W_1=W;Bi_3=Bi_2;Bi_2=Bi_1;Bi_1=Bi;Ci_3=Ci_2;Ci_2=Ci_1;Ci_1=Ci;
Xc=;%PDI
er_2=er_1;er_1=er; Kpid_1=Kpid;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%output save%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
time(k)=h*k; %record the time
RR(k)=rin; YY(k)=yout; YYm(k)=ymout;
end
plot(time,RR,'b',time,YY,'r',time,YYm,'-.');grid on
页:
[1]