当前位置:   article > 正文

rrt* 算法_rrt*算法

rrt*算法

  rrt算法由于没有考虑cost值,使得最终规划的路径质量很差。rrt*算法在此基础上,引入贪心思想,使得规划路径可以随着采样次数增多逐步优化。

一、算法流程

二、rrt*与rrt的不同

1、父节点的选取不同

        rrt扩展完q_{new}后,将距离其最近的节点作为其父节点;而rrt*是划定一个范围,将范围的节点均作为待选父节点,然后分别计算以它们为父节点时,q_{new}的cost值,选择使q_{new}的cost最小的节点作为其父节点。这一步使得扩展得新节点得cost尽可能得小。

2、重布线(rewire)

        在完成新节点的父节点选取后,选取新节点的周边节点,假设将刚扩展的新节点作为它们的父节点,比较此时它们的cost值与其原先得cost值,如果此时cost值较小,则rewire,将新节点作为其父节点,并更新cost值。

三、matlab代码

这里只放两处关键代码,后面会上传github。

1、父节点的选取

  1. %以newnode节点为中心,半径R为半径搜索节点
  2. R=30/ceil(0.001*numel(nodes_list));
  3. dis2new=nodes_list(ind).cost+stepLength;
  4. minCostIndex=ind;
  5. nearNodeList=[];
  6. for index_near=1:N
  7. if norm(nodes_list(index_near).position-newnode)<R
  8. nearNodeList=[nearNodeList,nodes_list(index_near)]; %if node in the range, put it in the nearNodeList
  9. if norm(nodes_list(index_near).position-newnode)+nodes_list(index_near).cost<dis2new
  10. dis2new=norm(nodes_list(index_near).position-newnode)+nodes_list(index_near).cost;
  11. flag=collisionCheck(newnode,nodes_list(index_near).position,fig);
  12. if flag
  13. minCostIndex=index_near;
  14. end
  15. end
  16. end
  17. end
  18. lhandle=plot([nodes_list(minCostIndex).position(1),newnode(1)],[nodes_list(minCostIndex).position(2),newnode(2)],'b-','LineWidth',1);
  19. lhandlelist=[lhandlelist,lhandle];
  20. phandle=plot(newnode(1),newnode(2),'ro','MarkerFaceColor','r','MarkerSize',2);
  21. phandlelist=[phandlelist,phandle];
  22. drawnow;
  23. nodes_list(N+1).position=newnode;
  24. nodes_list(N+1).parentind=minCostIndex;
  25. nodes_list(N+1).cost=nodes_list(minCostIndex).cost+norm(near2rand);
  26. nodes_list(N+1).index=N+1;

2、rewire

  1. %% rewire
  2. NearNums=length(nearNodeList);
  3. for iterNear=1:NearNums
  4. nearNewCost=norm(nearNodeList(iterNear).position-newnode);
  5. if nearNewCost+nodes_list(N+1).cost<nearNodeList(iterNear).cost
  6. flag=collisionCheck(newnode,nearNodeList(iterNear).position,fig);
  7. if flag
  8. nodes_list(nearNodeList(iterNear).index).parentind=N+1;
  9. nodes_list(nearNodeList(iterNear).index).cost=nearNewCost+nodes_list(N+1).cost;
  10. %delete(lhandlelist(nearNodeList(iterNear).index-1));
  11. lhandlelist(nearNodeList(iterNear).index-1)=plot([nearNodeList(iterNear).position(1),newnode(1)],...
  12. [nearNodeList(iterNear).position(2),newnode(2)],'r-','LineWidth',2);
  13. drawnow;
  14. end
  15. end
  16. end
  17. if norm(newnode-goalPoint)<=stepLength && ~findflag
  18. findflag=1;
  19. nodes_list(N+2).position=goalPoint;
  20. nodes_list(N+2).parentind=N+1;
  21. nodes_list(N+2).cost=nodes_list(N+1).cost+norm(newnode-goalPoint);
  22. nodes_list(N+2).index=N+2;
  23. goalindex=N+2;
  24. %plot([newnode(1),goalPoint(1)],[newnode(2),goalPoint(2)],'b-');
  25. end
  26. title(['RRT* algorithm ','sampleNums:',num2str(j)]);
  27. if findflag
  28. updatepathcount=updatepathcount+1;
  29. if updatepathcount==50
  30. updatepathcount=0;
  31. m=2;
  32. path=[];
  33. path(1).position=goalPoint;
  34. pathIndex=nodes_list(goalindex).parentind;
  35. while 1
  36. path(m).position = nodes_list(pathIndex).position;
  37. pathIndex = nodes_list(pathIndex).parentind; % 沿终点回溯到起点
  38. if pathIndex == -1
  39. break
  40. end
  41. m=m+1;
  42. end
  43. for delete_index=1:length(pathhandlelist)
  44. delete(pathhandlelist(delete_index));
  45. end
  46. for m=2:length(path)
  47. pathhandle=plot([path(m).position(1),path(m-1).position(1)],[path(m).position(2),path(m-1).position(2)],'g-','LineWidth',3);
  48. pathhandlelist=[pathhandlelist,pathhandle];
  49. end
  50. end
  51. end

四、几点疑问 

 1、采样次数与时间复杂度的取舍,采样次数越多,路线越优化。

2、随着采样次数增多,后期的父节点选取及rewire的待选节点越多,这一点如何处理。(有人把搜索半径与采样次数关联,采样次数越多,搜索半径越小)。

3、搜索半径的问题,同样半径越大,路径会越优化,但会带来时间成本的增大。

五、参考文章

http://路径规划——改进RRT算法 - 搬砖的旺财的文章 - 知乎 https://zhuanlan.zhihu.com/p/51087819

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/881284
推荐阅读
相关标签
  

闽ICP备14008679号