300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 【三维路径规划】基于matlab A_star算法无人机三维路径规划(起终点障碍物可设置)【

【三维路径规划】基于matlab A_star算法无人机三维路径规划(起终点障碍物可设置)【

时间:2020-06-16 08:01:02

相关推荐

【三维路径规划】基于matlab A_star算法无人机三维路径规划(起终点障碍物可设置)【

一、获取代码方式

获取代码方式1:

通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

获取代码方式2:

通过紫极神光博客主页开通CSDN会员,凭支付凭证,私信博主,可获得此代码。

获取代码方式3:

完整代码已上传我的资源:【三维路径规划】基于matlab A_star算法无人机三维路径规划(起终点障碍物可设置)【含Matlab源码 1321期】

备注:开通CSDN会员,仅只能免费获得1份代码(有效期为开通日起,三天内有效);

订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);

二、A_star算法简介

0 引言

随着现代技术的发展,飞行器种类不断变多,应用也日趋专一化、完善化,如专门用作植保的大疆PS-X625无人机,用作街景拍摄与监控巡察的宝鸡行翼航空科技的X8无人机,以及用作水下救援的白鲨MIX水下无人机等,决定飞行器性能主要是内部的飞控系统和外部的路径规划问题。就路径问题而言,在具体实施任务时仅靠操作员手中的遥控器控制无人飞行器执行相应的工作,可能会对操作员心理以及技术提出极高的要求,为了避免个人操作失误,进而造成飞行器损坏的危险,一种解决问题的方法就是对飞行器进行航迹规划。

飞行器的测量精度,航迹路径的合理规划,飞行器工作时的稳定性、安全性等这些变化对飞行器的综合控制系统要求越来越高。无人机航路规划是为了保证无人机完成特定的飞行任务,并且能够在完成任务的过程中躲避各种障碍、威胁区域而设计出最优航迹路线的问题。常见的航迹规划算法如图1所示。

图1 常见路径规划算法

文中主要对无人机巡航阶段的航迹规划进行研究,假设无人机在飞行中维持高度与速度不变,那么航迹规划成为一个二维平面的规划问题。在航迹规划算法中,A算法计算简单,容易实现。在改进A算法基础上,提出一种新的、易于理解的改进A算法的无人机航迹规划方法。传统A算法将规划区域栅格化,节点扩展只限于栅格线的交叉点,在栅格线的交叉点与交叉点之间往往存在一定角度的两个运动方向。将存在角度的两段路径无限放大、细化,然后分别用两段上的相应路径规划点作为切点,找到相对应的组成内切圆的圆心,然后作弧,并求出相对应的两切点之间的弧所对应的圆心角,根据下式计算出弧线的长度

式中:R———内切圆的半径;

α———切点之间弧线对应的圆心角。

1 A*算法概述

A算法是在Dijstar算法的基础上引入的启发式函数,通过定义的代价函数来评估代价大小,从而确定最优路径。A算法的代价函数

式中:f(x,y)———初始状态X0(x0,y0)到达目标状态X1(x1,y1)的代价估计;

g(x,y)———状态空间中从初始状态X0(x0,y0)到状态N(x1,y1)的实际代价;

h(x,y)———从状态N(x1,y1)到目标状态X1(x1,y1)最佳路径的估计代价。

要找到最短路径的实质是找到f(x,y)的最小值,其中在式(2)中寻找最短路径的关键在于求估计代价h (x,y)值。设系数λ表示状态N(x1,y1)到X1(x1,y1)最优距离,如果λ<h(x,y),搜索范围小,不能保证得到最优解;λ>h(x,y),搜索范围大,费时,但能找到最优解;λ=h(x,y),搜索到最短路径。其中h(x,y)一般用欧几里德距离(式(3))或者绝对值距离(式(4))计算。

A算法是以起始点为中心,周围8个栅格的中心为下一步预选,并不断地计算预选位置的f(x,y)值,其中f(x,y)值最小的作为当前位置,依次逐层比较,直到当前位置的临近点出现目标点为止,其最小单元如图2所示。

图2 最小单元

A算法的流程如下:

1)创建开始节点START,目标节点TARGET、OPEN列表、CLOSE列表、CLOSE列表初始为空;

2)将START加入到OPEN列表;

3)检查OPEN列表中的节点,若列表为空,则无可行路径;若不为空,选择使f(x,y)值最小的节点k;

4)将节点k从OPEN中去除,并将其添加到CLOSE中,判断节点k是否目标节点TARGET,若是,则说明找到路径;若不是,则继续扩展节点k,生成k节点的子节点集,设q为k的子节点集,对所有节点q计算相应的f(x,y)值,并选择f(x,y)值最小的节点,将该节点放入CLOSE列表中;

5)跳到3),直到算法获得可行路径或无解退出。

三、部分源代码

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%DEFINE THE 2-D MAP ARRAYMAX_X=10;MAX_Y=10;MAX_VAL=10;%This array stores the coordinates of the map and the %Objects in each coordinateMAP=2*(ones(MAX_X,MAX_Y));% Obtain Obstacle, Target and Robot Position% Initialize the MAP with input values% Obstacle=-1,Target = 0,Robot=1,Space=2j=0;x_val = 1;y_val = 1;axis([1 MAX_X+1 1 MAX_Y+1])grid on;hold on;n=0;%Number of Obstacles% BEGIN Interactive Obstacle, Target, Start Location selectionpause(1);h=msgbox('Please Select the Target using the Left Mouse button');uiwait(h,5);if ishandle(h) == 1delete(h);endxlabel('Please Select the Target using the Left Mouse button','Color','black');but=0;while (but ~= 1) %Repeat until the Left button is not clicked[xval,yval,but]=ginput(1);endxval=floor(xval);yval=floor(yval);xTarget=xval;%X Coordinate of the TargetyTarget=yval;%Y Coordinate of the TargetMAP(xval,yval)=0;%Initialize MAP with location of the targetplot(xval+.5,yval+.5,'gd');text(xval+1,yval+.5,'Target')pause(2);h=msgbox('Select Obstacles using the Left Mouse button,to select the last obstacle use the Right button');xlabel('Select Obstacles using the Left Mouse button,to select the last obstacle use the Right button','Color','blue');uiwait(h,10);if ishandle(h) == 1delete(h);endwhile but == 1[xval,yval,but] = ginput(1);xval=floor(xval);yval=floor(yval);MAP(xval,yval)=-1;%Put on the closed list as wellplot(xval+.5,yval+.5,'ro');end%End of While looppause(1);h=msgbox('Please Select the Vehicle initial position using the Left Mouse button');uiwait(h,5);if ishandle(h) == 1delete(h);endxlabel('Please Select the Vehicle initial position ','Color','black');but=0;while (but ~= 1) %Repeat until the Left button is not clicked[xval,yval,but]=ginput(1);xval=floor(xval);yval=floor(yval);endxStart=xval;%Starting PositionyStart=yval;%Starting PositionMAP(xval,yval)=1;plot(xval+.5,yval+.5,'bo');%End of obstacle-Target pickup%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%LISTS USED FOR ALGORITHM%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%OPEN LIST STRUCTURE%--------------------------------------------------------------------------%IS ON LIST 1/0 |X val |Y val |Parent X val |Parent Y val |h(n) |g(n)|f(n)|%--------------------------------------------------------------------------OPEN=[];%CLOSED LIST STRUCTURE%--------------%X val | Y val |%--------------% CLOSED=zeros(MAX_VAL,2);CLOSED=[];%Put all obstacles on the Closed listk=1;%Dummy counterfor i=1:MAX_Xfor j=1:MAX_Yif(MAP(i,j) == -1)CLOSED(k,1)=i; CLOSED(k,2)=j; k=k+1;endendendCLOSED_COUNT=size(CLOSED,1);%set the starting node as the first nodexNode=xval;yNode=yval;OPEN_COUNT=1;path_cost=0;goal_distance=distance(xNode,yNode,xTarget,yTarget);OPEN(OPEN_COUNT,:)=insert_open(xNode,yNode,xNode,yNode,path_cost,goal_distance,goal_distance);OPEN(OPEN_COUNT,1)=0;CLOSED_COUNT=CLOSED_COUNT+1;CLOSED(CLOSED_COUNT,1)=xNode;CLOSED(CLOSED_COUNT,2)=yNode;NoPath=1;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% START ALGORITHM%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%while((xNode ~= xTarget || yNode ~= yTarget) && NoPath == 1)% plot(xNode+.5,yNode+.5,'go');exp_array=expand_array(xNode,yNode,path_cost,xTarget,yTarget,CLOSED,MAX_X,MAX_Y);exp_count=size(exp_array,1);%UPDATE LIST OPEN WITH THE SUCCESSOR NODES%OPEN LIST FORMAT%--------------------------------------------------------------------------%IS ON LIST 1/0 |X val |Y val |Parent X val |Parent Y val |h(n) |g(n)|f(n)|%--------------------------------------------------------------------------%EXPANDED ARRAY FORMAT%--------------------------------%|X val |Y val ||h(n) |g(n)|f(n)|%--------------------------------for i=1:exp_countflag=0;for j=1:OPEN_COUNTif(exp_array(i,1) == OPEN(j,2) && exp_array(i,2) == OPEN(j,3) )OPEN(j,8)=min(OPEN(j,8),exp_array(i,5)); %#ok<*SAGROW>if OPEN(j,8)== exp_array(i,5)%UPDATE PARENTS,gn,hnOPEN(j,4)=xNode;OPEN(j,5)=yNode;OPEN(j,6)=exp_array(i,3);OPEN(j,7)=exp_array(i,4);end;%End of minimum fn checkflag=1;end;%End of node check% if flag == 1% break;end;%End of j forif flag == 0OPEN_COUNT = OPEN_COUNT+1;OPEN(OPEN_COUNT,:)=insert_open(exp_array(i,1),exp_array(i,2),xNode,yNode,exp_array(i,3),exp_array(i,4),exp_array(i,5));end;%End of insert new element into the OPEN listend;%End of i for%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END OF WHILE LOOP%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Find out the node with the smallest fn index_min_node = min_fn(OPEN,OPEN_COUNT,xTarget,yTarget);if (index_min_node ~= -1) %Set xNode and yNode to the node with minimum fnxNode=OPEN(index_min_node,2);yNode=OPEN(index_min_node,3);path_cost=OPEN(index_min_node,6);%Update the cost of reaching the parent node%Move the Node to list CLOSEDCLOSED_COUNT=CLOSED_COUNT+1;CLOSED(CLOSED_COUNT,1)=xNode;CLOSED(CLOSED_COUNT,2)=yNode;OPEN(index_min_node,1)=0;else%No path exists to the Target!!NoPath=0;%Exits the loop!end;%End of index_min_node checkend;%End of While Loop%Once algorithm has run The optimal path is generated by starting of at the%last node(if it is the target node) and then identifying its parent node%until it reaches the start node.This is the optimal pathi=size(CLOSED,1);Optimal_path=[];xval=CLOSED(i,1);yval=CLOSED(i,2);i=1;Optimal_path(i,1)=xval;Optimal_path(i,2)=yval;i=i+1;if ( (xval == xTarget) && (yval == yTarget))inode=0;%Traverse OPEN and determine the parent nodesparent_x=OPEN(node_index(OPEN,xval,yval),4);%node_index returns the index of the nodeparent_y=OPEN(node_index(OPEN,xval,yval),5);while( parent_x ~= xStart || parent_y ~= yStart)%Get the grandparents:-)inode=node_index(OPEN,parent_x,parent_y);parent_x=OPEN(inode,4);%node_index returns the index of the nodeparent_y=OPEN(inode,5);i=i+1;end;j=size(Optimal_path,1);%Plot the Optimal Path!p=plot(Optimal_path(j,1)+.5,Optimal_path(j,2)+.5,'bo');j=j-1;for i=j:-1:1pause(.25);set(p,'XData',Optimal_path(i,1)+.5,'YData',Optimal_path(i,2)+.5);drawnow ;end;plot(Optimal_path(:,1)+.5,Optimal_path(:,2)+.5);elsepause(1);h=msgbox('Sorry, No path exists to the Target!','warn');uiwait(h,5);end

四、运行结果

五、matlab版本及参考文献

1 matlab版本

a

2 参考文献

[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,.

[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,.

[3]巫茜,罗金彪,顾晓群,曾青.基于改进PSO的无人机三维航迹规划优化算法[J].兵器装备工程学报. ,42(08)

[4]邓叶,姜香菊.基于改进人工势场法的四旋翼无人机航迹规划算法[J].传感器与微系统. ,40(07)

[5]马云红,张恒,齐乐融,贺建良.基于改进A*算法的三维无人机路径规划[J].电光与控制. ,26(10)

[6]焦阳.基于改进蚁群算法的无人机三维路径规划研究[J].舰船电子工程. ,39(03)

【三维路径规划】基于matlab A_star算法无人机三维路径规划(起终点障碍物可设置)【含Matlab源码 1321期】

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。