Chủ Nhật, 10 tháng 11, 2019

Điều khiển backstepping RBF hệ tay máy trong MATLAB Simulink

Không có nhận xét nào













S function for control law and adaptive law: chap8_4ctrl.m
function [sys,x0,str,ts] = chap8_4ctrl(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case {2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
global c b k1 k2 k3 k4 node
node=5;
sizes = simsizes;
sizes.NumContStates = 3*node+1;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 7;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 0;
sys = simsizes(sizes);
x0 = [zeros(3*node,1);500]; %m(0)>ml
str = [];
ts = [];
c=[-1 -0.5 0 0.5 1;
-1 -0.5 0 0.5 1;
-1 -0.5 0 0.5 1;
-1 -0.5 0 0.5 1];
b=1.5;
k1=0.35;k2=0.35;k3=0.35;k4=0.35;
function sys=mdlDerivatives(t,x,u)
global c b k1 k2 k3 k4 node
x1d=u(1);
dx1d=cos(t);
ddx1d=-sin(t);
dddx1d=-cos(t);
ddddx1d=sin(t);
x1=u(2);x2=u(3);x3=u(4);x4=u(5); %Plant states
z=[x1,x2,x3,x4]';
for j=1:1:node
h(j)=exp(-norm(z-c(:,j))^2/(2*b^2));
end
th_gp=[x(1:node)]';     %gp weight value
th_dp=[x(node+1:node*2)]';
th_fp=[x(node*2+1:node*3)]';    %dp weight value
%fp weight value
gp=th_gp*h';
dp=th_dp*h';
fp=th_fp*h';
mp=x(3*node+1);
e1=x1-x1d;
x2d=dx1d-k1*e1;
e2=x2-x2d;
dx2d=ddx1d-k1*(x2-dx1d);
x3d=-gp+dx2d-k2*e2-e1;
%D3=dddx1d-k1*(x3-ddx1d)-k2*(x3-dx2d)+dx1d-x2;
dx3d1=dddx1d-k1*(x3-ddx1d)-k2*(x3-dx2d)+dx1d-x2;
e3=x3-x3d;
x4d=dx3d1-dp-k3*e3-e2;
e4=x4-x4d;
%D4=ddddx1d-k1*(x4-dddx1d)-k2*(x4-dddx1d+k1*(x3-ddx1d))+ddx1d-x3-k3*(x4-D3)-(x3-dx2d);
dx4d1=ddddx1d-k1*(x4-dddx1d)-k2*(x4-dddx1d+k1*(x3-ddx1d))+ddx1d-x3-k3*(x4-dx3d1)-(x3-dx2d);
ut=(1/mp)*(-fp+dx4d1-k4*e4-e3);
Kexi=[e1 e2 e3 e4]';
n=0.01;
Gama2=250;Gama3=250;Gama4=250;
Gama=[0 0 0 0;
0 Gama2 0 0;
0 0 Gama3 0;
0 0 0 Gama4];
eta=150;
ml=1;
if (e4*ut>0)
dm=(1/eta)*e4*ut;
end
if (e4*ut<=0)
if (mp>ml)
dm=(1/eta)*e4*ut;
else
dm=1/eta;
end
end
for i=1:1:node
sys(i)=Gama(2,2)*h(i)*Kexi(2)-n*Gama(2,2)*norm(Kexi)*th_gp(i); %g estimation
sys(i+node)=Gama(3,3)*h(i)*Kexi(3)-n*Gama(3,3)*norm(Kexi)*th_dp(i); %d estimation
sys(i+node*2)=Gama(4,4)*h(i)*Kexi(4)-n*Gama(4,4)*norm(Kexi)*th_fp(i); %f estimation
end
sys(3*node+1)=dm;
function sys=mdlOutputs(t,x,u)
global c b k1 k2 k3 k4 node
x1d=u(1);
dx1d=cos(t);
ddx1d=-sin(t);
dddx1d=-cos(t);
ddddx1d=sin(t);
x1=u(2);x2=u(3);x3=u(4);x4=u(5);
z=[x1,x2,x3,x4]';
for j=1:1:node
h(j)=exp(-norm(z-c(:,j))^2/(2*b^2));
end
th_gp=[x(1:node)]';
th_dp=[x(node+1:node*2)]';  %gp weight
%dp weight
th_fp=[x(node*2+1:node*3)]';    %fp weight
gp=th_gp*h';
dp=th_dp*h';
fp=th_fp*h';
mp=x(node*3+1);
e1=x1-x1d;
x2d=dx1d-k1*e1;
e2=x2-x2d;
dx2d=ddx1d-k1*(x2-dx1d);
x3d=-gp+dx2d-k2*e2-e1;
%D3=dddx1d-(k1)*(x3-ddx1d)-(k2)*(x3-dx2d)+dx1d-x2;
dx3d1=dddx1d-(k1)*(x3-ddx1d)-(k2)*(x3-dx2d)+dx1d-x2;
e3=x3-x3d;
x4d=dx3d1-dp-k3*e3-e2;
e4=x4-x4d;

%D4=ddddx1d-(k1)*(x4-dddx1d)-(k2)*(x4-dddx1d+(k1)*(x3-ddx1d))-(k3)*(x4-D3)-(x3-dx2d)+ddx1d-x3;
dx4d1=ddddx1d-(k1)*(x4-dddx1d)-(k2)*(x4-dddx1d+(k1)*(x3-ddx1d))-(k3)*(x4-dx3d1)-(x3-dx2d)+ddx1d-x3;
ut=(1/mp)*(-fp+dx4d1-k4*e4-e3);
sys(1)=ut;
sys(2)=gp;
sys(3)=mp;


S function for plant: chap8_4plant.m
function [sys,x0,str,ts]=chap8_plant(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case {2, 4, 9 }
sys = [];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 4;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 6;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 0;
sys=simsizes(sizes);
x0=[0 0 0 0];
str=[];
ts=[];
function sys=mdlDerivatives(t,x,u)
M=0.2;L=0.02;I=1.35*0.001;K=7.47;J=2.16*0.1;
g=9.8;
gx=-x(3)-M*g*L*sin(x(1))/I-(K/I)*(x(1)-x(3));
fx=(K/J)*(x(1)-x(3));
m=1/J;
ut=u(1);
sys(1)=x(2);
sys(2)=x(3)+gx;
sys(3)=x(4);
sys(4)=fx+m*ut;
function sys=mdlOutputs(t,x,u)
M=0.2;L=0.02;I=1.35*0.001;K=7.47;J=2.16*0.1;
g=9.8;
gx=-x(3)-M*g*L*sin(x(1))/I-(K/I)*(x(1)-x(3));
m=1/J;
sys(1)=x(1);
sys(2)=x(2);
sys(3)=x(3);
sys(4)=x(4);
sys(5)=gx;
sys(6)=m;
Web: http://nguyenvankhoa.com Facebook: http://www.facebook.com/NguyenVanKhoaCom Đăng ký kênh youtube: http://goo.gl/rHDTKK Rất mong được sự ủng hộ của quý vị Xin trân trọng!

Không có nhận xét nào :

Đăng nhận xét