• 大小: 2KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-03-22
  • 语言: Matlab
  • 标签: bppid控制  BP  BP-PID  

资源简介

BP神经网络PID控制代码,可以在matlab中直接运行

资源截图

代码片段和文件信息



%被控对象近似数学模型为:yout(k)=a(k)*yout(k-1)/1+yout^2(k-1) + u(k-1)                          %      
%式中a(k)是慢时变的 a(k)=1.2(1-0.8e^(-0.1k))                           %%      %%
%神经网络的结构选4-5-3 学习速率η=0.28,惯性系数α=0.04,加权系数初始值取区间【-0.50.5】上的随机数  %
%输入指令分两种①rin(k)=1.0;②rin(k)=sin(2*π*t)
%取S=1时为阶跃跟踪,S=2时为正弦跟踪,初始权值取随机值,运行稳定后用稳定值代替随机值

% BP based PID Control
clear all;
close all

%xite=0.25;
%alfa=0.05;
xite=0.04;
alfa=0.31;
raa=zeros(1500);

S=2; %Signal type 
IN=4;H=5;Out=3;%NN Structure
if S==1 % Step Signal
wi=[-0.6394 -0.2696 -0.3756 -0.7023;
    -0.8603 -0.2013 -0.5024 -0.2596;
    -1.0749 0.5543  -1.6820 -0.5437;
    -0.3625 -0.0724 -0.6463 -0.2859;
    0.1425  0.0279  -0.5406 -0.7660];
%wi=0.50*rands(HIN);
wi_1=wi; wi_2=wi;wi_3=wi;
wo=[0.7576 0.2616 0.5820 -0.1416 -0.1325;
    -0.1146 0.2949 0.8352 0.2205 0.4508;
    0.7201 0.4566 0.7672 0.4962 0.3632];
%wo=0.50*rands(OutH);
wo_1=wo;wo_2=wo;wo_3=wo;
end


if S==2 %Sine Signal
wi=[-0.2846 0.2193 -0.5097 -1.0668;
    -0.7484 -0.1210 -0.4708 0.0988;
    -0.7176  0.8297 -1.6000 0.2049;
    -0.0858 0.1925 -0.6346 0.0347;
    0.4358 0.2369 -0.4564 -0.1324];
%wi=0.50*rands(HIN);
wi_1=wi;wi_2=wi;wi_3=wi;
wo=[1.0438 0.5478 0.8682 0.1446 0.1537;
    0.1716 0.5811 1.1214 0.5067 0.7370
    1.0063 0.7428 1.0534 0.7824 0.6494];
%wo=0.50*rands(OutH);
wo_1=wo;wo_2=wo;wo_3=wo;
end
x=[000];
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(H1);%Output from NN middle layer
I=Oh; %Input to NNmiddle layer
error_2=0;
error_1=0;



ts=0.005;
rin=zeros(14601);
time=zeros(14601);
for k=1:1:4601
time(k)=k*ts;
%time(k)=k;

% % if S==1
% % rin(k)=5.0;
% % elseif S==2
% % rin(k)=sin(1*2*pi*k*ts);
% % end


    if time(k)<=8
        rin(k)=50*time(k);
    elseif time(k)<=10.5
        rin(k)=80*time(k)-240;
    elseif time(k)<=12.5
        rin(k)=600;
    elseif time(k)<=15
        rin(k)=-80*time(k)+1600;
    else
        rin(k)=-50*time(k)+1150;
    end


    


%Unlinear model
a(k)=1.2*(1-0.8*exp(-0.1*k));
yout(k)=a(k)*y_1/(1+y_1^2)+u_1;

error(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‘;
for j=1:1:H
Oh(j)=(exp(I(j))-exp(-I(j)))/(exp(I(j))+exp(-I(j)));%Middle layer
end
K=wo*Oh;%Output layer
for im=1:1:Out
K(im)=exp(K(im))/(exp(K(im))+exp(-K(im)));%Getting Kp Ki Kd
end
kp(k)=K(1);ki(k)=K(2);kd(k)=K(3);
Kpid=[kp(k)ki(k)kd(k)];

du(k)=Kpid*epid;
u(k)=u_1+du(k);
if u(k)>=600 % Restricting the output of controller

u(k)=600;
end
if u(k)<=-600
u(k)=-600;
end

dyu(k)=sign((yout(k)-y_1)/(u(k)-u_1+0.0000001));
%Output layer
for j=1:1:Out
dK(j)=2/(exp(K(j))+exp(-K(j)))^2;
end
for im=1:1:Out
delta3(im)=error(k)*dyu(k)*epid(im)*dK(im);
end

for im=1:1:Out
for i=1:1:H
d_wo=xite*delta3(im)*Oh(i)+alfa*(wo_1-wo_2);
end
end
wo=wo_1+d_wo+alfa*(wo_1-wo_2);
%Hidden layer
for i=1:1:H

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        3902  2014-11-16 15:55  BPPID.m

评论

共有 条评论