2012-12-24基于BP神经网络整定的PID控制

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

基于BP神经网络整定的PID控制(2012-12-24)1.BP(BackPropagation)网络结构控制算法:()(1)()(1)()()2(1)(2)pidukukkekekkekkekekek。2.三层BP网络(上标(1)(2)(3)代表输入层、隐含层和输出层)(1)网络输入层(M)输入为(1),1,2,,jjOxjM。(2)网络隐含层(Q)输入为(2)(2)(1)0()MiijjjnetkwO,输出为(2)(2)()(),1,2,,iiOkfnetkiQ。其中24()tanh(),()()xxxxxxeefxxfxeeee。(3)网络输出层(l=3)输入为(3)(3)(2)0()()QlliiinetkwOk输出为(3)(3)()(),1,2,3;,,llpidOkgnetklkkk也即其中212()1+tanh(),()2()xxxxxegxxgxeeee。3.学习算法性能指标函数:2211()()()()22Ekrinkyoutkek按照梯度下降法得到网络输出层的学习算法为(3)(3)(3)(2)(3)(3)()()(1)()(1)lililililiEkwkwkOkwkw其中为学习速率,为惯性系数,(3)(3)(3)()()()sgn()()()illykukekgnetkukOk。隐含层的学习算法为(2)(2)(2)(1)()(1)()ijijijwkwkOk其中3(2)(2)(3)(3)1()(),1,2,,iillilfnetkwkiQ。4.控制算法(1)确定输入层节点数M、隐含层节点数Q,给出加权系数初值(2)(0)ijw和(3)(0)liw,设定和,此时k=1;(2)采样得到rin(k)、yout(k)、e(k);(3)计算神经网络各层的输入和输出;(4)计算PID输出u(k);(5)进行神经网络学习,在线调整加权系数(2)(0)ijw和(3)(0)liw;(6)置k=k+1,循环进行。5.仿真实例被控对象为0.12()(1)()(1),()1.2(10.8)1(1)kakyoutkyoutkukakeyoutk。神经网络结构为4-5-3(即输入层4个,隐含层5个,输出层3个),加权系数初值在[-0.5,0.5]上的随机数。输入指令有两种:①S=1,()1.0rink;②S=2,()sin(2)rinkt。仿真程序为:=============================================================%BPbasedPIDControlclearall;closeall;xite=0.25;%给学习速率η赋初值alfa=0.05;%给惯性系数α赋初值S=1;%Signaltype,1为阶跃,2为正弦IN=4;H=5;Out=3;%NNStructureifS==1%StepSignalwi=[-0.6394-0.2696-0.3756-0.7023;-0.8603-0.2013-0.5024-0.2596;-1.07490.5543-1.6820-0.5437;-0.3625-0.0724-0.6463-0.2859;0.14250.0279-0.5406-0.7660];%wi=0.50*rands(H,IN);%wij(2)wi_1=wi;wi_2=wi;wi_3=wi;wo=[0.75760.26160.5820-0.1416-0.1325;-0.11460.29490.83520.22050.4508;0.72010.45660.76720.49620.3632];%wo=0.50*rands(Out,H);%wli(3)wo_1=wo;wo_2=wo;wo_3=wo;endifS==2%SineSignalwi=[-0.28460.2193-0.5097-1.0668;-0.7484-0.1210-0.47080.0988;-0.71760.8297-1.60000.2049;-0.08580.1925-0.63460.0347;0.43580.2369-0.4564-0.1324];%wi=0.50*rands(H,IN);wi_1=wi;wi_2=wi;wi_3=wi;wo=[1.04380.54780.86820.14460.1537;0.17160.58111.12140.50670.7370;1.00630.74281.05340.78240.6494];%wo=0.50*rands(Out,H);wo_1=wo;wo_2=wo;wo_3=wo;endx=[0,0,0];u_1=0;u_2=0;u_3=0;u_4=0;u_5=0;y_1=0;y_2=0;y_3=0;Oh=zeros(H,1);%隐含层输出Oi(2)(k)=f(neti(2)(k))I=Oh;%输出层输入error_2=0;error_1=0;ts=0.001;fork=1:1:6000time(k)=k*ts;ifS==1rin(k)=1.0;elseifS==2rin(k)=sin(1*2*pi*k*ts);end%Unlinearmodela(k)=1.2*(1-0.8*exp(-0.1*k));yout(k)=a(k)*y_1/(1+y_1^2)+u_1;%yout(k-1)的初始值为y_1=0error(k)=rin(k)-yout(k);xi=[rin(k),yout(k),error(k),1];%输入x(1)=error(k)-error_1;x(2)=error(k);x(3)=error(k)-2*error_1+error_2;epid=[x(1);x(2);x(3)];I=xi*wi';%[1×4]×[4×5]=[1×5],加撇为转置forj=1:1:HOh(j)=(exp(I(j))-exp(-I(j)))/(exp(I(j))+exp(-I(j)));%MiddleLayerendK=wo*Oh;%[3×5]×[5×1]=[3×1],netl(3)(k)forl=1:1:OutK(l)=exp(K(l))/(exp(K(l))+exp(-K(l)));%Gettingkp,ki,kd,g(x)endkp(k)=K(1);ki(k)=K(2);kd(k)=K(3);%kp,ki,kd赋第一组值Kpid=[kp(k),ki(k),kd(k)];du(k)=Kpid*epid;u(k)=u_1+du(k);ifu(k)=10%限制输出范围u(k)=10;endifu(k)=-10u(k)=-10;enddyu(k)=sign((yout(k)-y_1)/(u(k)-u_1+0.0000001));%加0.0000001是为了防止分母为0%Outputlayerforj=1:1:OutdK(j)=2/(exp(K(j))+exp(-K(j)))^2;%g’(x)endforl=1:1:Outdelta3(l)=error(k)*dyu(k)*epid(l)*dK(l);%δl(3)endforl=1:1:Outfori=1:1:Hd_wo=xite*delta3(l)*Oh(i)+alfa*(wo_1-wo_2);endendwo=wo_1+d_wo+alfa*(wo_1-wo_2);%wli(3)%Hiddenlayerfori=1:1:HdO(i)=4/(exp(I(i))+exp(-I(i)))^2;%f’(x)endsegma=delta3*wo;fori=1:1:Hdelta2(i)=dO(i)*segma(i);%δi(2)endd_wi=xite*delta2'*xi;wi=wi_1+d_wi+alfa*(wi_1-wi_2);%ParametersUpdateu_5=u_4;u_4=u_3;u_3=u_2;u_2=u_1;u_1=u(k);%u为PID输出y_2=y_1;y_1=yout(k);wo_3=wo_2;wo_2=wo_1;wo_1=wo;wi_3=wi_2;wi_2=wi_1;wi_1=wi;error_2=error_1;error_1=error(k);endfigure(1);plot(time,rin,'r',time,yout,'b');xlabel('time(s)');ylabel('rin,yout');figure(2);plot(time,error,'r');xlabel('time(s)');ylabel('error');figure(3);plot(time,u,'r');xlabel('time(s)');ylabel('u');figure(4);subplot(311);plot(time,kp,'r');xlabel('time(s)');ylabel('kp');subplot(312);plot(time,ki,'g');xlabel('time(s)');ylabel('ki');subplot(313);plot(time,kd,'b');xlabel('time(s)');ylabel('kd');=============================================================

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功