Thứ Hai, 11 tháng 11, 2019

Điều khiển Backstepping RBF cho hệ con lắc ngược trong MATLAB Simulink

2 nhận xét




























Backstepping Control Based on RBF for Inverted Pendulum
x1 the oscillation angle

g = 9,8 ;
mc = 1 kg is the vehicle mass
 m=0.1 is the mass of pendulum bar
 l =0.5m is one half of pendulum length
 u is the control input

%S function for control law: chap8_2ctrl.m
function [sys,x0,str,ts] = chap8_2ctrl(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 node
node=5;
sizes = simsizes;
sizes.NumContStates = 2*node;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 5;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 0;
sys = simsizes(sizes);
x0 = [0.1*ones(2*node,1)]; %m(0)>ml
str = [];
ts = [];
c=0.5*[-1 -0.5 0 0.5 1;
-1 -0.5 0 0.5 1];
b=15;
k1=35;k2=35;
function sys=mdlDerivatives(t,x,u)
global c b k1 k2 node
x1d=u(1);
dx1d=0.1*cos(t);
ddx1d=-0.1*sin(t);
x1=u(2);x2=u(3); %Plant states
z=[x1,x2]';
for j=1:1:node
h(j)=exp(-norm(z-c(:,j))^2/(2*b^2));
end
e1=x1-x1d;
de1=x2-dx1d;
x2d=dx1d-k1*e1;
e2=x2-x2d;
dx2d=ddx1d-k1*de1;
Kexi=[e1 e2]';
n=0.1;
Gama1=500;Gama2=0.50;
Gama=[Gama1 0;
0 Gama2];
%dZ=Gama*h*Kexi'-n*Gama*norm(Kexi)*Z;
w_fp=[x(1:node)]'; %fp weight
w_gp=[x(node+1:node*2)]'; %gp weight
for i=1:1:node
sys(i)=Gama(1,1)*h(i)*Kexi(1)-n*Gama(1,1)*norm(Kexi)*w_fp(i); %f estimation
sys(i+node)=Gama(2,2)*h(i)*Kexi(2)-n*Gama(2,2)*norm(Kexi)*w_gp(i); %g estimation
end
function sys=mdlOutputs(t,x,u)
global c b k1 k2 node
x1d=u(1);
dx1d=0.1*cos(t);
ddx1d=-0.1*sin(t);
x1=u(2);x2=u(3);
z=[x1,x2]';
for j=1:1:node
h(j)=exp(-norm(z-c(:,j))^2/(2*b^2));
end
w_fp=[x(1:node)]'; %fp weight
w_gp=[x(node+1:node*2)]'; %gp weight
fp=w_fp*h';
gp=w_gp*h';
e1=x1-x1d;
de1=x2-dx1d;
x2d=dx1d-k1*e1;
e2=x2-x2d;
dx2d=ddx1d-k1*de1;
ut=1/(gp+0.01)*(-e1-fp+dx2d-k2*e2);
sys(1)=ut;
sys(2)=fp;
sys(3)=gp;

%S function for plant: chap8_2plant.m
function [sys,x0,str,ts]=chap8_2plant(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 = 2;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 4;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 0;
sys=simsizes(sizes);
x0=[pi/60 0];
str=[];
ts=[];
function sys=mdlDerivatives(t,x,u)
g=9.8;mc=1.0;m=0.1;l=0.5;
S=l*(4/3-m*(cos(x(1)))^2/(mc+m));
fx=g*sin(x(1))-m*l*x(2)^2*cos(x(1))*sin(x(1))/(mc+m);
fx=fx/S;
gx=cos(x(1))/(mc+m);
gx=gx/S;
sys(1)=x(2);
sys(2)=fx+gx*u(1);
function sys=mdlOutputs(t,x,u)
g=9.8;mc=1.0;m=0.1;l=0.5;
S=l*(4/3-m*(cos(x(1)))^2/(mc+m));
fx=g*sin(x(1))-m*l*x(2)^2*cos(x(1))*sin(x(1))/(mc+m);
fx=fx/S;
gx=cos(x(1))/(mc+m);
gx=gx/S;
sys(1)=x(1);
sys(2)=x(2);
sys(3)=fx;
sys(4)=gx;
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!

2 nhận xét :

  1. đỉnh quá....mà e không hiểu..huhu
    học ngu quá......

    Trả lờiXóa
  2. anh làm video tiếng việt giải thích cụ thể được không ạ

    Trả lờiXóa