赞
踩
无人机运动学模型:
{
x
˙
=
v
x
v
x
˙
=
u
x
y
=
v
y
v
y
˙
=
u
y
\left\{
其中
n
x
:
状
态
变
量
量
个
数
,
n
u
:
控
制
变
量
个
数
,
n
m
:
输
出
变
量
个
数
n_x:状态变量量个数,n_u:控制变量个数,n_m:输出变量个数
nx:状态变量量个数,nu:控制变量个数,nm:输出变量个数,我们得到如下状态空间:
[
x
˙
v
˙
x
y
˙
v
˙
y
]
=
[
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
]
[
x
v
x
y
v
y
]
+
[
0
0
1
0
0
0
0
1
]
[
u
x
u
y
]
[
x
y
]
=
[
1
0
0
0
0
0
1
0
]
[
x
v
x
y
v
y
]
其中
A
=
[
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
]
B
=
[
0
0
1
0
0
0
0
1
]
C
=
[
1
0
0
0
0
0
1
0
]
x
(
k
)
=
[
x
v
x
y
v
y
]
u
(
k
)
=
[
u
x
u
y
]
A =
令:
x
m
(
k
)
=
[
x
(
k
)
v
x
(
k
)
y
(
k
)
v
y
(
k
)
]
T
u
m
(
k
)
=
[
u
x
(
k
)
u
y
(
k
)
]
T
将上述模型离散化,我们得到:
A
k
=
A
∗
Δ
t
+
I
B
k
=
B
∗
Δ
t
即我们得到系统方程:
x
m
(
k
+
1
)
=
A
k
x
m
(
k
)
+
B
k
u
m
(
k
)
y
m
(
k
+
1
)
=
C
x
m
(
k
+
1
)
=
C
A
k
x
m
(
k
)
+
C
B
k
u
m
(
k
)
x
m
(
k
+
1
)
∈
n
x
×
1
A
k
∈
n
x
×
n
x
B
k
∈
n
x
×
n
u
构建差分系统方程:
Δ
x
m
(
k
+
1
)
=
x
m
(
k
+
1
)
−
x
m
(
k
)
=
A
k
Δ
x
m
(
k
)
+
B
k
Δ
u
m
(
k
)
\Delta x_m(k+1)=x_m(k+1)-x_m(k)=A_k\Delta x_m(k)+B_k\Delta u_m(k)
Δxm(k+1)=xm(k+1)−xm(k)=AkΔxm(k)+BkΔum(k)
即得到:
[
Δ
x
m
(
k
+
1
)
y
m
(
k
+
1
)
]
=
[
(
A
k
)
n
x
×
n
x
0
n
x
×
n
m
(
C
A
k
)
n
m
×
n
x
I
n
m
×
n
m
]
[
Δ
x
m
(
k
)
n
x
×
1
y
m
(
k
)
n
m
×
1
]
+
[
(
B
k
)
n
x
×
n
u
(
C
B
k
)
n
m
×
n
u
]
Δ
u
m
(
k
)
n
u
×
1
y m ( k + 1 ) − y m ( k ) = C ( x m ( k + 1 ) − x m ( k ) ) = C Δ x m ( k + 1 ) = C A k Δ x m ( k ) + C B k Δ u m ( k ) y_m(k+1)-y_m(k)=C(x_m(k+1)-x_m(k))=C\Delta x_m(k+1)=CA_k\Delta x_m(k)+CB_k\Delta u_m(k) ym(k+1)−ym(k)=C(xm(k+1)−xm(k))=CΔxm(k+1)=CAkΔxm(k)+CBkΔum(k)
我们得到如下差分系统方程:
Δ
x
(
k
+
1
)
=
A
u
Δ
x
(
k
)
+
B
u
Δ
u
(
k
)
Δ
y
(
k
)
=
C
u
Δ
x
(
k
)
其中:
Δ
x
(
k
+
1
)
=
[
Δ
x
m
(
k
+
1
)
;
y
m
(
k
+
1
)
]
(
n
x
+
n
m
)
×
1
Δ
u
(
k
)
n
u
×
1
=
Δ
u
m
(
k
)
Δ
y
(
k
)
n
m
×
1
A
u
=
[
(
A
k
)
n
x
×
n
x
0
n
x
×
n
m
(
C
A
k
)
n
m
×
n
x
I
n
m
×
n
m
]
B
u
=
[
(
B
k
)
n
x
×
n
u
(
C
B
k
)
n
m
×
n
u
]
C
u
=
[
0
n
m
×
n
x
I
n
m
×
n
m
]
递推公式推导:
{
Δ
x
(
k
i
+
1
∣
k
i
)
=
A
u
Δ
x
(
k
i
)
+
B
u
Δ
u
(
k
i
)
Δ
x
(
k
i
+
2
∣
k
i
)
=
A
u
2
Δ
x
(
k
i
)
+
A
u
B
u
Δ
u
(
k
i
)
+
B
u
Δ
u
(
k
i
+
1
)
Δ
x
(
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x
(
k
i
)
)
T
(
R
s
−
F
x
(
k
i
)
)
−
2
U
T
Φ
(
R
s
−
F
x
(
k
i
)
)
+
U
T
(
Φ
T
Φ
+
R
)
U
求
∂
J
∂
U
\frac{\partial J}{\partial U}
∂U∂J得:
∂
J
∂
U
=
−
2
Φ
T
(
R
s
−
F
x
(
k
i
)
)
+
2
(
Φ
T
Φ
+
R
)
U
=
0
U
=
(
Φ
T
Φ
+
R
)
−
1
Φ
T
(
R
s
−
F
x
(
k
i
)
)
即差分方程迭代:
Δ
x
(
k
i
+
1
)
=
A
k
Δ
x
(
:
,
k
i
)
+
B
k
U
(
1
:
n
m
)
U
=
U
(
1
:
n
m
)
+
o
l
d
U
X
(
:
,
i
+
1
)
=
A
k
X
(
:
,
k
i
)
+
B
k
U
%================无人机模型预测控制-基于差分模型的模型预测================% clear all;clc;close all; %% 无人机参数设定--采用运动学模型进行轨迹跟踪 x0 = 10; y0 = 5; x1 = 11; y1 = 6; vx0 = 0; vy0 = 0; vx1 = 1; vy1 = 1; x(1) = x0; y(1) = y0;vx(1) = vx0;vy(1) = vy0; %% 领航者参数设定 inter = 0.05; % 采样周期 time = 60; % 总时长 R = 2; omega = 2; t = 0:inter:time; %% 八字形 for i = 1:1:length(t) if (mod(floor(omega*t(i)/(2*pi)),2) == 0) Xr(i) = R*cos(omega*t(i))-R; Yr(i) = R*sin(omega*t(i)); Vxr(i) = -R*sin(omega*t(i))*omega; Vyr(i) = R*cos(omega*t(i))*omega; Uxr(i) = -R*cos(omega*t(i))*omega^2; Uyr(i) = -R*sin(omega*t(i))*omega^2; else Xr(i) = -R*cos(omega*t(i))+R; Yr(i) = R*sin(omega*t(i)); Vxr(i) = R*sin(omega*t(i))*omega; Vyr(i) = R*cos(omega*t(i))*omega; Uxr(i) = R*cos(omega*t(i))*omega^2; Uyr(i) = -R*sin(omega*t(i))*omega^2; end end %% 直线 % Xr = (2*t)'; % Yr = 3*ones(length(t),1); % Vxr = 2*ones(length(t),1); % Vyr = 2*zeros(length(t),1); % Uxr = zeros(length(t),1); % Uyr = zeros(length(t),1); %% 圆形 % Xr = -R*cos(t); % Yr = R*sin(t); % Vxr = R*sin(t); % Vyr = R*cos(t); % Uxr = R*cos(t); % Uyr = -R*sin(t); %% % EX(:,1) = [x0 - Xr(1);vx0 - Vxr(1);y0 - Yr(1);vy0 - Vyr(1)]; X(:,1) = [x0;vx0;y0;vy0]; deltaX(:,1) = [0;0;0;0;x0;y0]; %% 领航者轨迹 % figure % grid minor % l1 = []; % axis([-7 7 -7 7]); % axis equal % for i = 2:1:length(t) % hold on % plot([Xr(i) Xr(i-1)],[Yr(i) Yr(i-1)],'b'); % hold on % delete(l1); % l1 = plot(Xr(i),Yr(i),'r.','MarkerSize',20); % pause(0.1); % % end %% 模型预测控制参数设定 Np = 20; % 预测步长 Nc = 10; % 控制步长 A = [0 1 0 0;0 0 0 0;0 0 0 1;0 0 0 0]; B = [0 0;1 0;0 0;0 1]; C = [1 0 0 0;0 0 1 0]; nx = size(A); nx = nx(1); nu = size(B); nu = nu(2); nm = 2; R = 0.002*eye(Nc*nu); Ak = A*inter + eye(nx); Bk = B*inter; Au = [Ak zeros(nx,nm);C*Ak eye(nm)]; Bu = [Bk;C*Bk]; Cu = [zeros(nm,nx) eye(nm)]; F = cell(Np,1); PHI = cell(Np,Nc); for i = 1:1:Np % 计算预测方程矩阵 F{i,1} = Cu*Au^i; end F = cell2mat(F); for i = 1:1:Np for j = 1:1:Nc if (j<=i) PHI{i,j} = Cu*Au^(i-j)*Bu; else PHI{i,j} = zeros(nm,nu); end end end PHI = cell2mat(PHI); k1 =2;k2 =2; XX = []; %% 迭代计算 k = 1; oldU = [0;0]; for i = 1:1:length(t)-1 for j = i:1:(Np+i-1) if j >= length(Xr) j = length(Xr); end XX = [XX;[Xr(j);Yr(j)]]; end U = inv(PHI'*PHI + R)*PHI'*(XX- F*deltaX(:,i)); XX = []; u = U(1:2,1) + oldU; oldU = u; X(:,i+1) = Ak*X(:,i) + Bk*u; deltaX(:,i+1) = Au*deltaX(:,i) + Bu*U(1:2,1); % err =[X(:,i+1) - [Xr(i+1);Vxr(i+1);Yr(i+1);Vyr(i+1)]] ; end x = (X(1,:))'; vx = (X(2,:))'; y = (X(3,:))'; vy = (X(4,:))'; % VV = vecnorm([Vxr;Vyr]); % VX = vecnorm([vx;vy]); % plot(t,VV,'r') % hold on % plot(t,VX(1:length(t)),'b') figure thetr = atan2(Yr,Xr); thet = atan2(y,x); plot(t,thetr(1:length(t)),'r'); hold on plot(t,thet(1:length(t)),'k'); legend('Leader','follower1') l1 = []; l2 = []; pic_num = 1; figure grid minor % axis([-5 5 -5 5]) axis equal Tag1 = animatedline('Color','r'); for i = 1:1:length(Xr)-1 hold on delete(l1); delete(l2); plot([x(i) x(i+1)],[y(i) y(i+1)],'b'); hold on plot([Xr(i) Xr(i+1)],[Yr(i) Yr(i+1)],'r'); hold on l1 = plot(x(i+1),y(i+1),'b.','MarkerSize',20); hold on l2 = plot(Xr(i+1),Yr(i+1),'r.','MarkerSize',20); pause(0.1); % addpoints(Tag1,t(i),x(i)); % drawnow; % F=getframe(gcf); % I=frame2im(F); % [I,map]=rgb2ind(I,256); % if pic_num == 1 % imwrite(I,map,'test.gif','gif', 'Loopcount',inf,'DelayTime',0.2); % else % imwrite(I,map,'test.gif','gif','WriteMode','append','DelayTime',0.2); % end % pic_num = pic_num + 1; F = getframe(gcf); I = frame2im(F); [I,map] = rgb2ind(I,256); if pic_num == 1 imwrite(I,map,'test.gif','gif','Loopcount',inf,'DelayTime',0.2); else imwrite(I,map,'test.gif','gif','WriteMode','append','DelayTime',0.2); end pic_num = pic_num + 1; end
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。