✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
个人主页:Matlab科研工作室
个人信条:格物致知。
更多Matlab仿真内容点击
智能优化算法 神经网络预测 雷达通信 无线传感器
信号处理 图像处理 路径规划 元胞自动机 无人机
⛄ 内容介绍
最初,一架无人机盘旋飞行,试图找到一朵云,一旦找到它,它就会调用更多的无人机绕着云飞行,并跟踪对应于污染物浓度 1.0 的云的边界。目标是让无人机在云层周围均匀分布。每架无人机可以飞行 30 分钟,之后需要返回基地 (0,0) 充电。
思路:为了在云周围均匀分布,无人机计算云的凸包(基于采样点)并根据其他无人机的位置加速/减速。如果云的周长变得太大,就会调用新的无人机绕云飞行。避免碰撞规则:为了实现这一点,将每架无人机建模为一个电子,每架无人机对所有其他无人机(足够接近)施加排斥力。
⛄ 部分代码
function sim_start
% load cloud data
% choose a scenario
% load ‘cloud1.mat’
close all;
load ‘cloud1.mat’
% time and time step
t = 0;
dt = 1;
last_launch = 1; %time when the last UAV was launched
% open new figure window
figure
hold on % so each plot doesn’t wipte the predecessor
%create initial UAVs
id_count = 1; %id for the next spawned UAV
num_uavs = 1; %number of active UAVs
uav(num_uavs,1) = UAVsim;
ang = rand*2*pi;
uav(1) = UAVsim(0,0,ang,1);%x,y,ang,id
old_msg = zeros(num_uavs,5); %keeps the messages that have to be processed for next iterration
spawn_new_uav = false; %if this becomes true, launch a new uav
for kk=1:3600
new_msg = zeros(num_uavs,5); %create an empty matrix for the new messages
t = t + dt;
spawn_new_uav = false;
i=1;
while i<=num_uavs
[x,y,p,id,new_uav] = uav(floor(i)).step(dt,t,cloud,old_msg);
new_msg(i,1:5) = [x,y,p,id,new_uav]; %get the message from the current UAV
if (new_uav)
spawn_new_uav = true;
end
if uav(i).state == 5
%if UAV ran out of battery
uav(i)=[];%remove the current UAV
i=i-1;
num_uavs = num_uavs-1;
end
i=i+1;
end
if num_uavs<1
%sanity check
return;
end
%plot the UAVs and the cloud
cla
title(sprintf(‘t=%.1f secs pos=(%.1f, %.1f) Concentration=%.2f’,t, uav(1).get_real_x,uav(1).get_real_y,uav(1).p))
for i=1:num_uavs
text(uav(i).get_real_x()-14, uav(i).get_real_y()-5,sprintf(‘%d’,uav(i).id));
if uav(i).t_alive>15
%I assumed that during take off, the UAV does not need to
%do collision avoidance (until it reaches the required
%height) so I do not plot a circle around it for the first
%15 seconds.
% this is useful in the case the cloud spreads over the
% base (0,0);
plot_circle(uav(i).get_real_x(),uav(i).get_real_y(),25);
end
end
cloudplot(cloud,t);
old_msg = new_msg;
if spawn_new_uav && (kk-last_launch>25)
last_launch = kk+1;
num_uavs = num_uavs+1;
id_count = id_count+1;
ang = rand*2*pi;
uav = [uav;UAVsim(0,0,ang,id_count)];
end
end
end
function plot_circle(x,y,r)
%plots a circle at (x,y) corrdinates with radius r;
%quality of the plotted circle is not very good but it is decent enough;
ang = 0:0.5:2*pi;
xp = r*cos(ang);
yp = r*sin(ang);
plot(x+xp,y+yp);
end
⛄ 运行结果
⛄ 参考文献
[1]李文超, 袁冬莉. 基于机动目标模型的无人机视场跟踪仿真研究[J]. 计算机测量与控制, 2011, 19(2):4.
[2]蔡中轩. 无人机群体分布式导引关键技术研究与系统实现[D]. 国防科技大学, 2017.
❤️ 关注我领取海量matlab电子书和数学建模资料
❤️部分理论引用网络文献,若有侵权联系博主删除