当前位置:   article > 正文

基于运动学模型的无人机模型预测控制(MPC)-3_无人机 模型预测控制

无人机 模型预测控制

基于差分模型的无人机模型预测控制(MPC)-无约束情况

1. 模型建立

无人机运动学模型:
{ x ˙ = v x v x ˙ = u x y = v y v y ˙ = u y \left\{

x˙amp;=vxvx˙=uxyamp;=vyvy˙=uy
\right. {x˙y=vxvx˙=ux=vyvy˙=uy
其中 n x : 状 态 变 量 量 个 数 , n u : 控 制 变 量 个 数 , n m : 输 出 变 量 个 数 n_x:状态变量量个数,n_u:控制变量个数,n_m:输出变量个数 nxnu: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˙v˙xy˙v˙y]
=
[0amp;1amp;0amp;00amp;0amp;0amp;00amp;0amp;0amp;10amp;0amp;0amp;0]
[xvxyvy]
+
[0amp;01amp;00amp;00amp;1]
[uxuy]
x˙v˙xy˙v˙y=0000100000000010xvxyvy+01000001[uxuy]

[ x y ] = [ 1 0 0 0 0 0 1 0 ] [ x v x y v y ]
[xy]
=
[1amp;0amp;0amp;00amp;0amp;1amp;0]
[xvxyvy]
[xy]=[10000100]xvxyvy

其中
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 =
[0amp;1amp;0amp;00amp;0amp;0amp;00amp;0amp;0amp;10amp;0amp;0amp;0]
\quad B =
[0amp;01amp;00amp;00amp;1]
\quad C=
[1amp;0amp;0amp;00amp;0amp;1amp;0]
\quad x(k)=
[xvxyvy]
\quad u(k)=
[uxuy]
\quad
A=0000100000000010B=01000001C=[10000100]x(k)=xvxyvyu(k)=[uxuy]

令:
x m ( k ) = [ x ( k ) v x ( k ) y ( k ) v y ( k ) ] T u m ( k ) = [ u x ( k ) u y ( k ) ] T

amp;xm(k)=[x(k)vx(k)y(k)vy(k)]Tamp;um(k)=[ux(k)uy(k)]T
xm(k)=[x(k)vx(k)y(k)vy(k)]Tum(k)=[ux(k)uy(k)]T
将上述模型离散化,我们得到:
A k = A ∗ Δ t + I B k = B ∗ Δ t
amp;Ak=AΔt+Iamp;Bk=BΔt
Ak=AΔt+IBk=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

amp;xm(k+1)=Akxm(k)+Bkum(k)amp;ym(k+1)=Cxm(k+1)=CAkxm(k)+CBkum(k)amp;xm(k+1)nx×1Aknx×nxBknx×nu
xm(k+1)=Akxm(k)+Bkum(k)ym(k+1)=Cxm(k+1)=CAkxm(k)+CBkum(k)xm(k+1)nx×1Aknx×nxBknx×nu

构建差分系统方程:
Δ 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

[Δxm(k+1)ym(k+1)]=[amp;(Ak)nx×nxamp;0nx×nmamp;(CAk)nm×nxamp;Inm×nm][amp;Δxm(k)nx×1amp;ym(k)nm×1]+[(Bk)nx×nu(CBk)nm×nu]Δum(k)nu×1
[Δxm(k+1)ym(k+1)]=[(Ak)nx×nx(CAk)nm×nx0nx×nmInm×nm][Δxm(k)nx×1ym(k)nm×1]+[(Bk)nx×nu(CBk)nm×nu]Δum(k)nu×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)amp;=AuΔx(k)+BuΔu(k)Δy(k)amp;=CuΔx(k)
Δx(k+1)Δy(k)=AuΔx(k)+BuΔu(k)=CuΔ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 ]

amp;Δx(k+1)=[Δxm(k+1);ym(k+1)](nx+nm)×1amp;Δu(k)nu×1=Δum(k)amp;Δy(k)nm×1amp;Au=[amp;(Ak)nx×nxamp;0nx×nmamp;(CAk)nm×nxamp;Inm×nm]Bu=[(Bk)nx×nu(CBk)nm×nu]Cu=[0nm×nxInm×nm]
Δx(k+1)=[Δxm(k+1);ym(k+1)](nx+nm)×1Δu(k)nu×1=Δum(k)Δy(k)nm×1Au=[(Ak)nx×nx(CAk)nm×nx0nx×nmInm×nm]Bu=[(Bk)nx×nu(CBk)nm×nu]Cu=[0nm×nxInm×nm]

递推公式推导:
{ Δ 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 ( k i + 3 ∣ k i ) = A u 3 Δ x ( k i ) + A u 2 B u Δ u ( k i ) + A u B u Δ u ( k i + 1 ) + B u Δ u ( k i + 2 ) ⋮ Δ x ( k i + N p ∣ k i ) = A u N p Δ x ( k i ) + A u N p − 1 B u Δ u ( k i ) + A u N p − 2 B u Δ u ( k i + 1 ) + ⋯ + A u N p − N c B u Δ u ( k i + N c − 1 ) \left\{

Δx(ki+1|ki)amp;=AuΔx(ki)+BuΔu(ki)Δx(ki+2|ki)amp;=Au2Δx(ki)+AuBuΔu(ki)+BuΔu(ki+1)Δx(ki+3|ki)amp;=Au3Δx(ki)+Au2BuΔu(ki)+AuBuΔu(ki+1)+BuΔu(ki+2)Δx(ki+Np|ki)amp;=AuNpΔx(ki)+AuNp1BuΔu(ki)+AuNp2BuΔu(ki+1)++AuNpNcBuΔu(ki+Nc1)
\right. Δx(ki+1ki)Δx(ki+2ki)Δx(ki+3ki)Δx(ki+Npki)=AuΔx(ki)+BuΔu(ki)=Au2Δx(ki)+AuBuΔu(ki)+BuΔu(ki+1)=Au3Δx(ki)+Au2BuΔu(ki)+AuBuΔu(ki+1)+BuΔu(ki+2)=AuNpΔx(ki)+AuNp1BuΔu(ki)+AuNp2BuΔu(ki+1)++AuNpNcBuΔu(ki+Nc1)

{ Δ y ( k i + 1 ∣ k i ) = C u A u Δ x ( k i ) + C u B u Δ u ( k i ) Δ y ( k i + 2 ∣ k i ) = C u A u 2 Δ x ( k i ) + C u A u B u Δ u ( k i ) + C u B u Δ u ( k i + 1 ) Δ y ( k i + 3 ∣ k i ) = C u A u 3 Δ x ( k i ) + C u A u 2 B u Δ u ( k i ) + C u A u B u Δ u ( k i + 1 ) + C u B u Δ u ( k i + 2 ) ⋮ Δ y ( k i + N p ∣ k i ) = C u A u N p Δ x ( k i ) + C u A u N p − 1 B u Δ u ( k i ) + C u A u N p − 2 B u Δ u ( k i + 1 ) + ⋯ + C u A u N p − N c B u Δ u ( k i + N c − 1 ) \left\{

Δy(ki+1|ki)amp;=CuAuΔx(ki)+CuBuΔu(ki)Δy(ki+2|ki)amp;=CuAu2Δx(ki)+CuAuBuΔu(ki)+CuBuΔu(ki+1)Δy(ki+3|ki)amp;=CuAu3Δx(ki)+CuAu2BuΔu(ki)+CuAuBuΔu(ki+1)+CuBuΔu(ki+2)Δy(ki+Np|ki)amp;=CuAuNpΔx(ki)+CuAuNp1BuΔu(ki)+CuAuNp2BuΔu(ki+1)+amp;+CuAuNpNcBuΔu(ki+Nc1)
\right. Δy(ki+1ki)Δy(ki+2ki)Δy(ki+3ki)Δy(ki+Npki)=CuAuΔx(ki)+CuBuΔu(ki)=CuAu2Δx(ki)+CuAuBuΔu(ki)+CuBuΔu(ki+1)=CuAu3Δx(ki)+CuAu2BuΔu(ki)+CuAuBuΔu(ki+1)+CuBuΔu(ki+2)=CuAuNpΔx(ki)+CuAuNp1BuΔu(ki)+CuAuNp2BuΔu(ki+1)++CuAuNpNcBuΔu(ki+Nc1)

即得到如下递推方程:
Y = F Δ x ( k i ) + Φ U Y = F\Delta x(k_i)+\Phi U Y=FΔx(ki)+ΦU

性能指标:
J = ( R s − Y ) T ( R s − Y ) + U T R U = ( R s − F x ( k i ) − Φ U ) T ( R s − F x ( k i ) − Φ U ) + U T R U = ( R s − F x ( k i ) ) T ( R s − F x ( k i ) ) − 2 U T Φ ( R s − F x ( k i ) ) + U T ( Φ T Φ + R ) U

Jamp;=(RsY)T(RsY)+UTRUamp;=(RsFx(ki)ΦU)T(RsFx(ki)ΦU)+UTRUamp;=(RsFx(ki))T(RsFx(ki))2UTΦ(RsFx(ki))+UT(ΦTΦ+R)U
J=(RsY)T(RsY)+UTRU=(RsFx(ki)ΦU)T(RsFx(ki)ΦU)+UTRU=(RsFx(ki))T(RsFx(ki))2UTΦ(RsFx(ki))+UT(ΦTΦ+R)U

∂ J ∂ U \frac{\partial J}{\partial U} UJ得:
∂ 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 ) )

JUamp;=2ΦT(RsFx(ki))+2(ΦTΦ+R)U=0Uamp;=(ΦTΦ+R)1ΦT(RsFx(ki))
UJU=2ΦT(RsFx(ki))+2(ΦTΦ+R)U=0=(ΦTΦ+R)1ΦT(RsFx(ki))

即差分方程迭代:
Δ 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

Δx(ki+1)amp;=AkΔx(:,ki)+BkU(1:nm)Uamp;=U(1:nm)+oldUX(:,i+1)amp;=AkX(:,ki)+BkU
Δx(ki+1)UX(:,i+1)=AkΔx(:,ki)+BkU(1:nm)=U(1:nm)+oldU=AkX(:,ki)+BkU

2. matlab 仿真代码

%================无人机模型预测控制-基于差分模型的模型预测================%
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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/925635
推荐阅读
相关标签
  

闽ICP备14008679号