1. 程式人生 > >RRT路徑規劃演算法

RRT路徑規劃演算法

%%%%% parameters
map=im2bw(imread('map2.bmp')); % input map read from a bmp file. for new maps write the file name here
source=[10 10]; % source position in Y, X format
goal=[490 490]; % goal position in Y, X format
stepsize=20; 	% size of each step of the RRT
disTh=20; 		% nodes closer than this threshold are taken as almost the same
maxFailedAttempts = 10000;
display=true; 	% display of RRT

tic;

if ~feasiblePoint(source,map), error('source lies on an obstacle or outside map'); end
if ~feasiblePoint(goal,map), error('goal lies on an obstacle or outside map'); end
if display, imshow(map);rectangle('position',[1 1 size(map)-1],'edgecolor','k'); end

RRTree1 = double([source -1]); % First RRT rooted at the source, representation node and parent index
RRTree2 = double([goal -1]);   % Second RRT rooted at the goal, representation node and parent index
counter=0;
tree1ExpansionFail = false; % sets to true if expansion after set number of attempts fails
tree2ExpansionFail = false; % sets to true if expansion after set number of attempts fails

while ~tree1ExpansionFail || ~tree2ExpansionFail  % loop to grow RRTs
    if ~tree1ExpansionFail 
        [RRTree1,pathFound,tree1ExpansionFail] = rrtExtend(RRTree1,RRTree2,goal,stepsize,maxFailedAttempts,disTh,map); % RRT 1 expands from source towards goal
        if ~tree1ExpansionFail && isempty(pathFound) && display
            line([RRTree1(end,2);RRTree1(RRTree1(end,3),2)],[RRTree1(end,1);RRTree1(RRTree1(end,3),1)],'color','b');
            counter=counter+1;M(counter)=getframe;
        end
    end
    if ~tree2ExpansionFail 
        [RRTree2,pathFound,tree2ExpansionFail] = rrtExtend(RRTree2,RRTree1,source,stepsize,maxFailedAttempts,disTh,map); % RRT 2 expands from goal towards source
        if ~isempty(pathFound), pathFound(3:4)=pathFound(4:-1:3); end % path found
        if ~tree2ExpansionFail && isempty(pathFound) && display
            line([RRTree2(end,2);RRTree2(RRTree2(end,3),2)],[RRTree2(end,1);RRTree2(RRTree2(end,3),1)],'color','r');
            counter=counter+1;M(counter)=getframe;
        end
    end
    if ~isempty(pathFound) % path found
         if display
            line([RRTree1(pathFound(1,3),2);pathFound(1,2);RRTree2(pathFound(1,4),2)],[RRTree1(pathFound(1,3),1);pathFound(1,1);RRTree2(pathFound(1,4),1)],'color','green');
            counter=counter+1;M(counter)=getframe;
        end
        path=[pathFound(1,1:2)]; % compute path
        prev=pathFound(1,3);     % add nodes from RRT 1 first
        while prev > 0
            path=[RRTree1(prev,1:2);path];
            prev=RRTree1(prev,3);
        end
        prev=pathFound(1,4); % then add nodes from RRT 2
        while prev > 0
            path=[path;RRTree2(prev,1:2)];
            prev=RRTree2(prev,3);
        end
        break;
    end
end

if display 
    disp('click/press any key');
    waitforbuttonpress; 
end

if size(pathFound,1)<=0, error('no path found. maximum attempts reached'); end
pathLength=0;
for i=1:length(path)-1, pathLength=pathLength+distanceCost(path(i,1:2),path(i+1,1:2)); end
fprintf('processing time=%d \nPath Length=%d \n\n', toc,pathLength); 
imshow(map);
rectangle('position',[1 1 size(map)-1],'edgecolor','k');
line(path(:,2),path(:,1));

相關推薦

RRT路徑規劃演算法

%%%%% parameters map=im2bw(imread('map2.bmp')); % input map read from a bmp file. for new maps write the file name here source=[10 10]; % source position

常用的地圖導航和路徑規劃演算法

作者:李傳學 連結:https://www.zhihu.com/question/24870090/answer/73834896 來源:知乎 著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。   明確一點,基本的圖搜尋演算法dijkstra是無法滿足網際網路地圖檢

Field D*路徑規劃演算法

Field D*路徑規劃演算法 1.柵格法路徑規劃存在的問題 2.Filed D*演算法主要思想解析 3.Filed D*演算法虛擬碼 4.演算法優化 5.演算法總結 參考文獻 緊接著上一篇D* Lite路徑規劃演算法

移動機器人D*Lite路徑規劃演算法設計、模擬及原始碼

轉自:https://blog.csdn.net/ayawaya/article/details/70155932 Dstar Lite路徑規劃演算法簡介 D*Lite演算法是Koenig S和Likhachev M基於LPA*演算法基礎上提出的路徑規劃演算法。 LPA

淺談路徑規劃演算法之Dijkstra演算法

 迪傑斯特拉(dijkstra)演算法是典型的用來解決最短路徑的演算法,也是很多教程中的範例,由荷蘭電腦科學家狄克斯特拉於1959年提出,用來求得從起始點到其他所有點最短路徑。該演算法採用了貪心的思想,每次都查詢與該點距離最的點,也因為這樣,它不能用來解決存在負權邊的圖。解

路徑規劃演算法之Bellman-Ford演算法

最近由於工作需要一直在研究Bellman-Ford演算法,這也是我第一次用C++編寫程式碼。 1、Bellman-Ford演算法總結 (1)Bellman-Ford演算法計算從源點(起始點)到任意一點的最短路徑的長度,初始化陣列m_Dist[m_Segment[i].m_StartPoint] = m_M

ROS中的路徑規劃演算法dijkstra和A*

ROS Navigation包裡面的GlobalPlanner自帶是提供了兩種全域性路徑規劃的方法,dijkstra和A* dijkstra 大家都知道了,A*在之前的一篇部落格裡面有介紹 A* 評估函式 為 f(n) = g(n) + h(n) g(

路徑規劃: PRM 路徑規劃演算法 (Probabilistic Roadmaps 隨機路標圖)

路徑規劃作為機器人完成各種任務的基礎,一直是研究的熱點。研究人員提出了許多規劃方法如: 1. A* 2. Djstar

路徑規劃演算法初步認識

資料 上面那個論文把uav的路徑規劃分為以下5類: sampling-based algorithms node-based algorithms mathematical model based algorithms Bio-inspired algorithms multi-fusion based

PRM路徑規劃演算法

%% PRM parameters map=im2bw(imread('map1.bmp')); % input map read from a bmp file. for new maps write the file name here source=[10 10]; % source position

octomap中3d-rrt路徑規劃

路徑規劃 在octomap中制定起止點,目標點,使用rrt規劃一條路徑出來,沒有運動學,動力學的限制,只要能避開障礙物。 效果如下(綠線是規劃的路線,紅線是B樣條優化的曲線): #include "ros/ros.h" #include <octomap_msgs/Octomap.h> #i

AI與遊戲——吃豆人(3)基本的路徑規劃演算法(上)

這次我們來講一下程式碼中涉及的一些路徑規劃演算法,在這個遊戲中,路徑規劃雖然不屬於人工智慧但是確實實現AI演算法不可或缺的基礎方法,下面就來大致介紹一下有哪些主要的方法以及這些方法的實現。 (1)getApproximateNextMoveTowardsTar

路徑規劃:PRM路徑規劃演算法(Probabilistic Roadmap 隨機路標圖)

global_planner: A*、Dijstra、prm、人工勢場、單元分解、快速搜尋樹(RRT)等 local_planner: eband_local_planner、asr_ftc_local_planner、dwa_local_planner、teb_loc

圖論動態規劃演算法——Floyd最短路徑

前言 推出一個新系列,《看圖輕鬆理解資料結構和演算法》,主要使用圖片來描述常見的資料結構和演算法,輕鬆閱讀並理解掌握。本系列包括各種堆、各種佇列、各種列表、各種樹、各種圖、各種排序等等幾十篇的樣子。 Floyd演算法 Floyd是一種經典的多源最短路徑演算法,它通過動態規劃的思想來尋找給定加權圖中的多源

手把手教用matlab做無人駕駛(二)-路徑規劃A*演算法

對於路徑規劃演算法-A*演算法在matlab中模擬,首先我們在matlab中構建地圖: 先給出matlab主函式程式: % editor: Robert.Cao % 2018.9.1 clc clear all close all disp('A Star

Dijkstra演算法(D演算法)實現路徑搜尋matlab GUI 實現 路徑規劃

Dijkstra(迪傑斯特拉)演算法是典型的單源最短路徑演算法,用於計算一個節點到其他所有節點的最短路徑。主要特點是以起始點為中心向外層層擴充套件,直到擴充套件到終點為止。Dijkstra演算法是很有代表性的最短路徑演算法,在很多專業課程中都作為基本內容有詳細的介紹,如資料結

手把手教用matlab做無人駕駛(三)-路徑規劃A*演算法

這裡,我們更新主程式如下: % editor: Robert.Cao % 2018.9.1 clc clear all close all disp('A Star Path Planing start!!') p.start=[1,1]; %起始點 p.goa

路徑規劃Dijkstra演算法

Dijkstra搜尋最短路徑: 整體思路 從起始節點開始,將鄰域節點進行遍歷,標註好鄰域節點最小的累計路徑長度,直到遍歷到終止節點。 演算法複雜度 naive的方式,演算法複雜度為O(|V|2),其中|V|是節點數量 聰明的方式,使用優先佇

路徑規劃(最短路徑演算法C#實現

    ///<summary>/// RoutePlanner 提供圖演算法中常用的路徑規劃功能。     /// 2005.09.06     ///</summary>publicclass RoutePlanner     {         public RoutePlan

路徑/運動規劃演算法計算複雜度

1. 演算法的計算時間複雜度 相關連結: (1). “我們假設計算機執行一行基礎程式碼需要執行一次運算”。但這和矩陣的運算複雜度的關係呢?如果矩陣運算就是一行程式碼,那這就不對了?十分鐘搞定時間複雜度 (2).  Wiki :computational complexity o