固定时间神经网络

This commit is contained in:
iHoney725
2021-01-04 10:37:04 +08:00
committed by GitHub
parent 8dda25c41b
commit ddd735c305
3 changed files with 343 additions and 0 deletions

BIN
Fixed_time_NN.slx Normal file

Binary file not shown.

265
Fixed_time_NNcontroller.m Normal file
View File

@@ -0,0 +1,265 @@
function [sys,x0,str,ts] = Fixed_time_NNcontroller(t,x,u,flag)
% RBF
switch flag
case 0 %
[sys,x0,str,ts]=mdlInitializeSizes;
case 1 %
sys=mdlDerivatives(t,x,u);
case {2,4,9} %仿仿
sys=[];
case 3 %
sys=mdlOutputs(t,x,u);
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts]=mdlInitializeSizes %
global c1 b1 c2 b2 node gama1 gama2 xite belta lg
% 2-7-1
node = 7;
c1 = 0.5*[-2 -1.5 -1 0 1 1.5 2;
-2 -1.5 -1 0 1 1.5 2;
-2 -1.5 -1 0 1 1.5 2;
-2 -1.5 -1 0 1 1.5 2]; % IN * MID 2*7
b1 = 20; % MID * 1 b b
gama1 = 10;
lg = 2;
xite = 20; %
c2 = 1.8*[-2 -1.5 -1 0 1 1.5 2;
-2 -1.5 -1 0 1 1.5 2;
-2 -1.5 -1 0 1 1.5 2;
-2 -1.5 -1 0 1 1.5 2]; % IN * MID 2*7
b2 = 4; % MID * 1 b b
gama2 = 0.01;
belta = 2;
sizes = simsizes;
sizes.NumContStates = node*6; %
sizes.NumDiscStates = 0; %
sizes.NumOutputs = 4; %
sizes.NumInputs = 7; %
sizes.DirFeedthrough = 1; %u1
sizes.NumSampleTimes = 1; %
% 1.
% nn
sys = simsizes(sizes);
x0 = 0.1*[ones(node*4,1); 2*ones(node*1,1);3*ones(node*1,1)]; % WV
str = []; %
ts = [0 0]; % [t1 t2] t1t1=-1t20
function sys = mdlDerivatives(t,x,u) %
global c1 b1 c2 b2 node gama1 gama2 xite belta lg
% 仿 cb bc
yd1 = 0.5*sin(pi*t);
dyd1 = 0.5*pi*cos(pi*t);
ddyd1 = -0.5*pi*pi*sin(pi*t);
yd2 = 0.5*sin(pi*t);
dyd2 = 0.5*pi*cos(pi*t);
ddyd2 = -0.5*pi*pi*sin(pi*t);
q1 = u(1);
q2 = u(2);
dq1 = u(3);
dq2 = u(4);
e1 = yd1 - q1;
e2 = yd2 - q2;
de1 = dyd1 - dq1;
de2 = dyd2 - dq2;
e = [e1;e2];
de = [de1;de2];
%
q = 3;
p = 5;
%
s1 = e1 + 1/belta*abs(de1)^(p/q)*sign(de1);
s2 = e2 + 1/belta*abs(de2)^(p/q)*sign(de2);
s = [s1; s2];
coe1 = p/(belta*q)*de1^(p-q)^(1/q); % 0
coe2 = p/(belta*q)*de2^(p-q)^(1/q); % 0
Input = [q1;q2;dq1;dq2];
% --------------------------------------------- W
hf1 = zeros(node , 1); %7*1
hf2 = zeros(node , 1); %7*1
for i =1:node
hf1(i) = exp(-(norm(Input - c1(:,i))^2) / (2*b1^2));
hf2(i) = exp(-(norm(Input - c1(:,i))^2) / (2*b1^2));
end
W1 = x(1:node); % 7*1
W2 = x(node+1:2*node); % 7*1
fx1 = W1' * hf1;
fx2 = W2' * hf2;
fx = [fx1; fx2]; % 2*1
dw_fx1 = -gama1 * s1 * coe1 * hf1; % 7*1
dw_fx2 = -gama1 * s2 * coe2 * hf2; % 7*1
for i = 1:node
sys(i) = dw_fx1(i);
sys(i+node) = dw_fx2(i);
end
% ------------------------------------------------- V
hg11 = zeros(node , 1); %7*1
hg12 = zeros(node , 1); %7*1
hg21 = zeros(node , 1); %7*1
hg22 = zeros(node , 1); %7*1
for i =1:node
hg11(i) = exp(-(norm(Input - c2(:,i))^2) / (2*b2^2));
hg12(i) = exp(-(norm(Input - c2(:,i))^2) / (2*b2^2));
hg21(i) = exp(-(norm(Input - c2(:,i))^2) / (2*b2^2));
hg22(i) = exp(-(norm(Input - c2(:,i))^2) / (2*b2^2));
end
V11 = x(node*2+1:node*3);
V12 = x(node*3+1:node*4);
V21 = x(node*4+1:node*5);
V22 = x(node*5+1:node*6);
gx11 = V11' * hg11;
gx12 = V12' * hg12;
gx21 = V21' * hg21;
gx22 = V22' * hg22;
gx = [gx11 gx12; gx21 gx22];
%
p1 = 2.9;
p2 = 0.76;
p3 = 0.87;
p4 = 3.04;
M = [p1+p2+2*p3*cos(q2) p2+p3*cos(q2);
p2+p3*cos(q2) p2];
%
g = inv(M);
temp1 = -belta*q/p* (abs(de1)^(2-p/q)*sign(de1)) + fx(1) - (lg+xite)*sign(s1) - ddyd1;
temp2 = -belta*q/p* (abs(de2)^(2-p/q)*sign(de2)) + fx(2) - (lg+xite)*sign(s2) - ddyd2;
temp = [temp1; temp2];
tau = -inv(gx) * temp;
dw_g11 = -gama2 * s1 * coe1 * hg11 * tau(1);
dw_g12 = -gama2 * s1 * coe1 * hg12 * tau(1);
dw_g21 = -gama2 * s2 * coe2 * hg21 * tau(2);
dw_g22 = -gama2 * s2 * coe2 * hg22 * tau(2);
for i = 1 : node
sys(i+node*2) = dw_g11(i);
sys(i+node*3) = dw_g12(i);
sys(i+node*4) = dw_g21(i);
sys(i+node*5) = dw_g22(i);
end
function sys = mdlOutputs(t,x,u) %
global c1 b1 c2 b2 node gama1 gama2 xite belta lg
%
yd1 = 0.5*sin(pi*t);
dyd1 = 0.5*pi*cos(pi*t);
ddyd1 = -0.5*pi*pi*sin(pi*t);
yd2 = 0.5*sin(pi*t);
dyd2 = 0.5*pi*cos(pi*t);
ddyd2 = -0.5*pi*pi*sin(pi*t);
q1 = u(1);
q2 = u(2);
dq1 = u(3);
dq2 = u(4);
e1 = yd1 - q1;
e2 = yd2 - q2;
de1 = dyd1 - dq1;
de2 = dyd2 - dq2;
e = [e1;e2];
de = [de1;de2];
ddyd = [ddyd1; ddyd2];
%
q = 3;
p = 5;
%
s1 = e1 + 1/belta*abs(de1)^(p/q)*sign(de1);
s2 = e2 + 1/belta*abs(de2)^(p/q)*sign(de2);
s = [s1; s2];
Input = [q1;q2;dq1;dq2];
% ------------------------------------------- W
hf1 = zeros(node , 1); %7*1
hf2 = zeros(node , 1); %7*1
for i =1:node
hf1(i) = exp(-(norm(Input - c1(:,i))^2) / (2*b1^2));
hf2(i) = exp(-(norm(Input - c1(:,i))^2) / (2*b1^2));
end
W1 = x(1:node); % 7*1
W2 = x(node+1:2*node); % 7*1
coe1 = p/(belta*q)*de1^(p-q)^(1/q); % 0
coe2 = p/(belta*q)*de2^(p-q)^(1/q); % 0
fx1 = W1' * hf1;
fx2 = W2' * hf2;
fx = [fx1; fx2]; % 2*1
% ------------------------------------------- V
hg11 = zeros(node , 1); %7*1
hg12 = zeros(node , 1); %7*1
hg21 = zeros(node , 1); %7*1
hg22 = zeros(node , 1); %7*1
for i =1:node
hg11(i) = exp(-(norm(Input - c2(:,i))^2) / (2*b2^2));
hg12(i) = exp(-(norm(Input - c2(:,i))^2) / (2*b2^2));
hg21(i) = exp(-(norm(Input - c2(:,i))^2) / (2*b2^2));
hg22(i) = exp(-(norm(Input - c2(:,i))^2) / (2*b2^2));
end
V11 = x(node*2+1:node*3);
V12 = x(node*3+1:node*4);
V21 = x(node*4+1:node*5);
V22 = x(node*5+1:node*6);
gx11 = V11' * hg11;
gx12 = V12' * hg12;
gx21 = V21' * hg21;
gx22 = V22' * hg22;
gx = [gx11 gx12; gx21 gx22];
p1 = 2.9;
p2 = 0.76;
p3 = 0.87;
p4 = 3.04;
M = [p1+p2+2*p3*cos(q2) p2+p3*cos(q2);
p2+p3*cos(q2) p2];
%
g = inv(M);
temp1 = -belta*q/p* (abs(de1)^(2-p/q)*sign(de1)) + fx(1) - (lg+xite)*sign(s1) - ddyd1;
temp2 = -belta*q/p* (abs(de2)^(2-p/q)*sign(de2)) + fx(2) - (lg+xite)*sign(s2) - ddyd2;
temp = [temp1; temp2];
tau = - inv(gx) * temp;
sys(1) = tau(1);
sys(2) = tau(2);
sys(3) = fx1;
sys(4) = fx2;

78
Fixed_time_NNplant.m Normal file
View File

@@ -0,0 +1,78 @@
function [sys,x0,str,ts] = Fixed_time_NNplant(t,x,u,flag)
switch flag
case 0 %
[sys,x0,str,ts]=mdlInitializeSizes;
case 1 %
sys=mdlDerivatives(t,x,u);
case {2,4,9} %仿仿
sys=[];
case 3 %
sys=mdlOutputs(t,x,u);
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
function [sys,x0,str,ts]=mdlInitializeSizes %
sizes = simsizes;
sizes.NumContStates = 4; %
sizes.NumDiscStates = 0; %
sizes.NumOutputs = 4; %
sizes.NumInputs = 4; %
sizes.DirFeedthrough = 0; %u1
sizes.NumSampleTimes = 1; %
% 1.
% nn
sys = simsizes(sizes);
x0 = [0.09 -0.09 0 0]; %
str = []; %
ts = [0 0]; % [t1 t2] t1t1=-1t20
function sys=mdlDerivatives(t,x,u) %
tau1 = u(1); %1
tau2 = u(2); %2
q1 = x(1); %
q2 = x(2); %
dq1 = x(3); %
dq2 = x(4); %
q = [q1; q2];
dq = [dq1; dq2];
%
p1 = 2.9;
p2 = 0.76;
p3 = 0.87;
p4 = 3.04;
p5 = 0.87;
g = 9.8;
d = sin(10*x(1))+cos(x(2)); %
% f = [u(3); u(4)]; %LuGre
f = [0.02*sign(dq1);0.02*sign(dq2)];
M = [p1+p2+2*p3*cos(q2) p2+p3*cos(q2);
p2+p3*cos(q2) p2];
C = [-p3*dq2*sin(q2) -p3*(dq1+dq2)*sin(q2);
p3*dq1*sin(q2) 0];
G = [p4*g*cos(q1)+p5*g*cos(q1+q2);
p5*g*cos(q1+q2)];
tau = [tau1; tau2];
ddq = inv(M) * (tau - C*dq - G - d - f);
sys(1) = x(3);
sys(2) = x(4);
sys(3) = ddq(1);
sys(4) = ddq(2);
function sys=mdlOutputs(t,x,u) %
sys(1) = x(1); %q1
sys(2) = x(2); %q2
sys(3) = x(3); %dq1
sys(4) = x(4); %dq2