控制四旋翼飞行器以进行多目标航点导航的MPC算法(Matlab代码实现)

    目录

💥1 概述

📚2 运行结果

🎉3 参考文献

👨‍💻4 Matlab代码

💥1 概述

目前研究的四旋翼无人机航迹跟踪控制系统跟踪过程不稳定,导致跟踪结果不准确;为此基于MPC设计了一种新的四旋翼无人机航迹跟踪控制系统。通过空中飞行控制器、地面控制器和人工干预器实现了无人机航线的跟踪控制;空中飞行控制器包括GPS导航定位模块、姿态评估模块(MTI)、飞行控制系统计算机,显示模块等;地面控制器探测周围飞行环境,规避障碍物、规划安全航线,传输至空中自主飞行控制系统,包括无线通讯的数据连接电路和地面终端控制模块;人工干预模块能对飞行过程中发生的意外情况进行人工干预以避免突发情况造成危险。​​

📚2 运行结果

主函数部分代码:

%% Robot Motion Planning and Control Assignment 
clc
clearvars
close all force
yalmip('clear')
​
%% Initialisation
Ts = 0.02;                      % sample time [s]
​
% Weighting matrices Q, Qt, R, W and control horizon N
mpc_sim.Q   =   [1e4   0   0   0   0   0;
                 0     1e2 0   0   0   0;
                 0     0   1e4 0   0   0;
                 0     0   0   1e2 0   0;
                 0     0   0   0   1e4 0;
                 0     0   0   0   0   1e2];                    
mpc_sim.Qt  = mpc_sim.Q*1e2;    % Terminal state matrix
mpc_sim.R   = eye(3)*1e2;       % Input matrix
mpc_sim.W   = mpc_sim.Q;        % Waypoint matrix
mpc_sim.N   = ceil(2/Ts);       % Control horizon [s]
​
%% Ring initialisation
% Ring 1
randx1 = -1+2*rand(1);  % Generate x-coordinate for ring 1
randy1 = 1+3*rand(1);   % Generate y-coordinate for ring 1
randz1 = -1+2*rand(1);  % Generate z-coordinate for ring 1
​
% Ring 2
randx2 = -1+2*rand(1);  % Generate x-coordinate for ring 2
randy2 = 5+4*rand(1);   % Generate y-coordinate for ring 2
randz2 = -1+2*rand(1);  % Generate z-coordinate for ring 2
​
%% Simulation settings
x0 = [0 0 0 0 0 0]';            % Define start position and velocity [m and m/s]
ring1 = [randx1 0  randy1  5  randz1  0];   % [x, desired x-velocity, y, desired y-velocity, z, desired z-velocity]
ring2 = [randx2 0  randy2  5 randz2  0];    % [x, desired x-velocity, y, desired y-velocity, z, desired z-velocity]
goal = [0 0 10 0 0 0];          % Define goal position and velocity [m and m/s]
simT = 7;                       % Simulation time [s]
ulim = [1 1 1]*7;               % Maximum absolute value input [N]
​
%% Run simulations
% Run simulation and MPC controller. Inputs are simulation settings, start
% en goal positions, simulation time and sampling time, ring locations.
[results] = MPC_Controller(mpc_sim, x0, simT, Ts, ulim, ring1, ring2, goal);
​
%% Construct rings
t = linspace(0,2*pi);
x = cos(t);
y = sin(t);
z = 0*t;
pnts = [x;y;z];
​
n0 = [0;0;0.1]; 
n0 = n0/norm(n0);
n1 = [0;1;0]; 
n1 = n1/norm(n1); 
​
c = dot(n0,n1) / ( norm(n0)*norm(n1) ); % cos(theta)
s = sqrt(0.1-c*c);                        % sin(theta)
u = cross(n0,n1) / ( norm(n0)*norm(n1) ); % rotation axis
u = u/norm(u); % unit rotation axis
C = 0.35-c;
​
% the rotation matrix
R = [u(1)^2*C+c, u(1)*u(2)*C-u(3)*s, u(1)*u(3)*C+u(2)*s
    u(2)*u(1)*C+u(3)*s, u(2)^2*C+c, u(2)*u(3)*C-u(1)*s
    u(3)*u(1)*C-u(2)*s, u(3)*u(2)*C+u(1)*s, u(3)^2*C+c];
​
% Rotated points
newPnts = R*pnts;
​
%% Plot results
figure; plot3(results.state(:, 1), results.state(:, 3), results.state(:, 5));
hold on
plot3(ring1(1)+1*newPnts(1,:), ring1(3)+1*newPnts(2,:), ring1(5)+1*newPnts(3,:), 'LineWidth',5)
plot3(ring2(1)+1*newPnts(1,:), ring2(3)+1*newPnts(2,:), ring2(5)+1*newPnts(3,:), 'LineWidth',5)
plot3(goal(1), goal(3), goal(5), 'b*')
plot3(x0(1), x0(3), x0(5), 'k*')
xlabel('x'); ylabel('y'); zlabel('z');
legend('Trajectory', 'ring 1', 'ring 2', 'goal', 'start')
grid on
xlim([-1.5 1.5]); ylim([0 10]); zlim([-1.5 1.5])
pbaspect([3 10 3])
​
%% Animate results
figure('units','normalized','outerposition',[0 0 1 1])
plot3(ring1(1)+1*newPnts(1,:), ring1(3)+1*newPnts(2,:), ring1(5)+1*newPnts(3,:), 'LineWidth',5)
hold on
plot3(ring2(1)+1*newPnts(1,:), ring2(3)+1*newPnts(2,:), ring2(5)+1*newPnts(3,:), 'LineWidth',5)
plot3(goal(1), goal(3), goal(5), 'b*')
plot3(x0(1), x0(3), x0(5), 'k*')
xlabel('x'); ylabel('y'); zlabel('z');
xlim([-1.5 1.5]); ylim([0 10]); zlim([-1.5 1.5])
pbaspect([3 10 3])
grid on
​
tic
for i = 1:simT/Ts
     plot3(results.state(1:i, 1), results.state(1:i, 3), results.state(1:i, 5), 'r--');
     p1 = plot3(results.state(i, 1), results.state(i, 3), results.state(i,5), 'r.');
     pause(Ts/2)
%      F(i) = getframe;
     delete(p1)
end

🎉3 参考文献

[1]聂博文,马宏绪,王剑,王建文.微小型四旋翼飞行器的研究现状与关键技术[J].电光与控制,2007(06):113-117.

部分理论引用网络文献,若有侵权联系博主删除。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
多旋翼L3控制是一种基于位置和速度控制控制方法,可以实现较为稳定的飞行控制。以下是一个简单的多旋翼L3控制MATLAB代码示例,供您参考: ```matlab % 多旋翼L3控制MATLAB代码示例 % 假设控制目标点为 (x_d, y_d, z_d),目标速度为 (vx_d, vy_d, vz_d) % 多旋翼参数 m = 1.0; % 质量 g = 9.81; % 重力加速度 l = 0.25; % 旋翼臂长 kF = 1.0; % 推力系数 kM = 0.1; % 扭矩系数 % 控制参数 Kp_p = 1.0; % 位置控制增益 Kd_p = 0.1; % 位置控制微分增益 Kp_v = 1.0; % 速度控制增益 Kd_v = 0.1; % 速度控制微分增益 % 初始化状态 x = 0.0; % 当前位置 x y = 0.0; % 当前位置 y z = 0.0; % 当前位置 z vx = 0.0; % 当前速度 vx vy = 0.0; % 当前速度 vy vz = 0.0; % 当前速度 vz phi = 0.0; % 当前姿态角 phi theta = 0.0; % 当前姿态角 theta psi = 0.0; % 当前姿态角 psi % 控制循环 for t = 0:0.01:10 % 时间步长为 0.01 秒 % 计算误差 dx = x - x_d; dy = y - y_d; dz = z - z_d; dvx = vx - vx_d; dvy = vy - vy_d; dvz = vz - vz_d; % 计算期望推力和期望姿态角 F = m * (g + Kp_p * dz + Kd_p * dvz) / (cos(phi) * cos(theta)); phi_d = (1 / g) * (Kp_v * dvx + Kd_v * (F / m) * sin(psi)); theta_d = (1 / g) * (Kp_v * dvy + Kd_v * (F / m) * cos(psi)); % 计算期望扭矩 Mx = kM * (phi_d - phi); My = kM * (theta_d - theta); Mz = kM * (psi_d - psi); % 计算期望旋翼推力 F1 = (F / 4) - (1 / (4 * kF)) * (Mx / l + My / l - Mz / (kF * 4)); F2 = (F / 4) - (1 / (4 * kF)) * (-Mx / l + My / l + Mz / (kF * 4)); F3 = (F / 4) - (1 / (4 * kF)) * (-Mx / l - My / l - Mz / (kF * 4)); F4 = (F / 4) - (1 / (4 * kF)) * (Mx / l - My / l + Mz / (kF * 4)); % 更新状态 x = x + vx * 0.01; y = y + vy * 0.01; z = z + vz * 0.01; vx = vx + (F / m) * sin(phi) * cos(theta) * cos(psi) * 0.01; vy = vy + (F / m) * sin(phi) * cos(theta) * sin(psi) * 0.01; vz = vz - (F / m) * cos(phi) * cos(theta) * 0.01; phi = phi + phi_d * 0.01; theta = theta + theta_d * 0.01; psi = psi + psi_d * 0.01; % 输出状态和控制量 disp(['Time: ', num2str(t), ', x: ', num2str(x), ', y: ', num2str(y), ', z: ', num2str(z)]); disp(['F1: ', num2str(F1), ', F2: ', num2str(F2), ', F3: ', num2str(F3), ', F4: ', num2str(F4)]); end ``` 需要注意的是,上述代码仅为示例,实际应用中需要根据具体的多旋翼参数和控制需求进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值