博大广阔 发表于 2012-6-6 20:51

基于不确定逼近的RBF网络自适应控制——控制对象单臂

%基于不确定逼近的RBF网络自适应控制——控制对象单臂
function a=RBF_a()
clc
clear all
%初始化
kp=50;kv=30;
c=0.60*ones(2,5);       %径向基的中心值
b=3.0*ones(5,1);      %径向基的扩展常数
weight2= 0.1*ones(1,5).';
ts=0.001;tmax=10;
X0=;

%仿真循环需要的参数
t=0;n=1;

while t<tmax
%期望轨迹:
Xd=[sin(t);
   -cos(t);
   -sin(t)];
E=Xd-X0;             %误差通常都是期望值减去实际值
X=E(1:2);

%%%%%%%%%%%%%%%%%%%%控制器输出%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
q=X(1);
g=9.8;m=1;l=0.25;D0=4/3*m*l^2;C0=2.0;G0=m*g*l*cos(q);
ddqd=Xd(3);e=E(1);de=E(2); dq=X0(2);

M=3;
if M==1            %Control for Precise Model
    tol1=D0*(ddqd-kv*de-kp*e)+C0*dq+G0;
    tol2=0;
    tol=tol1;
elseif M==2          %Control with Precise Nonlinear Compensation
    f=1/D0*(d_D0*ddq+d_C0*dq+d_G0+d);
    tol1=D0*(ddqd-kv*de-kp*e)+C0*dq+G0;
    tol2=-D0*f;
    tol=tol1+tol2;
elseif M==3          %Control with Neural Compensation
    tol1=D0*(ddqd-kv*de-kp*e)+C0*dq+G0;
    th=weight2;
    xi=;
    h=zeros(5,1);
for j=1:1:5
    h(j)=exp(-norm(xi-c(:,j))^2/(2*b(j)*b(j)));
end
    %f=1/D0*(d_D0*ddq+d_C0*dq+d_G0+d);
    fn=th'*h;
    tol2=-D0*fn;
    tol=tol1+1*tol2;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%自适应规律%%%%%%%%%%%%%%%%%%%%%%
A=;
B=;
Q=[50 0;
   0 50];
P=lyap(A',Q);         %李雅普函数的稳定性分析
h=zeros(5,1);
for j=1:1:5
    h(j)=exp(-norm(X-c(:,j))^2/(2*b(j)*b(j)));
end
gama=20;
M1=2;
if M1==1       % Adaptive Law
    S=gama*h*X'*P*B;
elseif M1==2   % Adaptive Law with UUB
    k1=0.001;
    S=gama*h*X'*P*B+k1*gama*norm(X)*weight2;
end
dweight2=S;       %导数
weight2=weight2+dweight2*ts;
%%%%%%%%%%%%%%%%%%%%%%被控对象%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%四阶龙格计算%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
x10=;u=tol;h=ts;
=derives(t,x10,u);
       m1=h*dX;            t=t+0.5*h;X=x10+0.5*m1; %更新导数   
   =derives(t,X,u);
      m2=h*dX;            X=x10+0.5*m2;      %更新导数
    =derives(t,X,u);
   m3=h*dX;          t=t+0.5*h; X=x10+m3;   %更新导数
    =derives(t,X,u);
    m4=h*dX;      
   x10=x10+(1/6)*(m1+2*m2+2*m3+m4); XX=x10;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%保存%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
time(n)=t; RR(n)=Xd(1);YY(n)=XX(1);n=n+1;
   
   
end
plot(time,RR,'b',time,YY,'r');grid on


function =derives(t,x10,u)
x=x10; tol=u;
%%%%%%%%%%%%%%%%%%系统模型%%%%%%%%%%%%%%%%%%%%%
g=9.8;m=1;l=0.25;D0=4/3*m*l^2;d_D0=0.2*D0;
D=D0-d_D0;
C0=2.0;
d_C0=0.2*C0;
C=C0-d_C0;
G0=m*g*l*cos(x(1));
d_G0=0.2*G0;
G=G0-d_G0;
d=1.3*sin(0.5*pi*t);
P=2;
dX=zeros(length(x),1);

%%%%%%%%%%%%%%%%%%求导数%%%%%%%%%%%%%%%%%%%
dX(1,:)=x(2);
if P==1
    dX(2,:)=1/D0*(-C0*x(2)-G0+tol);
elseif P==2
    dX(2)=1/D*(-C*x(2)-G+tol+d);
end





























Rainyboy 发表于 2012-6-7 11:59

恩,很猛啊,一上来发了不少有意义的代码。
页: [1]
查看完整版本: 基于不确定逼近的RBF网络自适应控制——控制对象单臂