二维平面内无人机的路径规划——势场法-改进
2021/12/31 23:14:11
本文主要是介绍二维平面内无人机的路径规划——势场法-改进,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
通过这一算法可以实现二维平面内无人机的路径规划。在该平面内存在已知的障碍,势场法通过给终点添加引力,对障碍增加斥力,使得无人机能够顺利的避障并到达终点。通过对传统势场法的改进,避免了无人机容易陷入极值的问题,使搜索更易实现。
clear all;
x=[1 3 4 7 6 5.5 8 9.5];%???x??
y=[1.5 2.2 4.5 6 2 6 7.8 7];
plot(x,y,'O',10,10,'v',0,0,'ms');
hold on
%??????????????????,??????????????????????????
%???????
Xo=[0 0];%????
k=20;%???????????
K=0;%???
m=5;%??????????????????
Po=2;%??????????????????????????0??????????????????
n=8;%????
a=0.5;
l=0.05;%??
J=500;%??????
%???????????????????????Po?????????
%end
%?????????
Xsum=[10 10;1 1.5;3 2.2;4 4.5;7 6;6 2;5.5 6;8 7.8;9.5 7];%?????(n+1)*2????[10 10]?????????????????
Xj=Xo;%j=1??????????????Xj
[x,y]=meshgrid(-1:0.5:12,-1:0.5:12);
z=0.5*k./(sqrt((x-10).^2+(y-10).^2+0.09))-0.5*m*(1./(sqrt((x-1).^2+(y-1.5).^2+0.09))-1/3.5).^2-0.5*m*(1./(sqrt((x-3).^2+(y-2.2).^2+0.09))-1/3.5).^2 ...
-0.5*m*(1./(sqrt((x-4).^2+(y-4.5).^2+0.09))-1/3).^2-0.5*m*(1./(sqrt((x-7).^2+(y-6).^2+0.09))-1/3).^2-0.5*m*(1./(sqrt((x-6).^2+(y-2).^2+0.09))-1/3.5).^2 ...
-0.5*m*(1./(sqrt((x-5.5).^2+(y-6).^2+0.09))-1/4).^2-0.5*m*(1./(sqrt((x-8).^2+(y-7.8).^2+0.09))-1/3).^2-0.5*m*(1./(sqrt((x-9.5).^2+(y-7).^2+0.09))-1/3).^2;
% contour(x,y,z,[-50:20:1000]);
[C,h]=contour(x,y,z,[-80:10:300]);
set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2)
colormap cool
[px,py]=gradient(z);%????x,y??????????
quiver(x,y,px,py,'k') %???????????
p=sqrt(px.^2+py.^2);
%%??
t=1;
M(t)=getframe;
t=t+1;
%***************????????????******************
for j=1:J%????
Goal(j,1)=Xj(1);%Goal???????????????????????????
Goal(j,2)=Xj(2);
%????????
Theta=compute_angle(Xj,Xsum,n);%Theta??????????????????X????????????????????????????????
%????????
Angle=Theta(1);%Theta?1????????????????????
angle_at=Theta(1);%???????????????????angle_at
[Fatx,Faty]=compute_Attract(Xj,Xsum,k,Angle,0,Po,n);%???????????x,y?????????
for i=1:n
angle_re(i)=Theta(i+1);%?????????????????n??????n????
end
%????????
[Frerxx,Freryy,Fataxx,Fatayy]=compute_repulsion(Xj,Xsum,m,angle_at,angle_re,n,Po,a);%??????x,y????????
%????????????????????j???????????????????????????????????????????????
Fsumyj=Faty+Freryy+Fatayy;%y?????
Fsumxj=Fatx+Frerxx+Fataxx;%x?????
Position_angle(j)=atan(Fsumyj/Fsumxj);%???x????????
%?????????
Xnext(1)=Xj(1)+l*cos(Position_angle(j));
Xnext(2)=Xj(2)+l*sin(Position_angle(j));
%?????????????
Xj=Xnext;
X=Goal(:,1);
Y=Goal(:,2);
plot(X,Y,'.r');
M(t)=getframe;t=t+1;
%??
if ((Xj(1)-Xsum(1,1))>0)&((Xj(2)-Xsum(1,2))>0)%??????????????????????????????????????
K=j;%??????????????
break;
%?????j?
end%?????if????????????????
end%?????
D130
这篇关于二维平面内无人机的路径规划——势场法-改进的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南