MPath

From The iroboapp Project
Jump to: navigation, search

MPath

Get the MPath Simulator Code

The code is open source under the GNU license. It can be downloaded from RAstar_4neighbors or RAstar_8neighbors

This is an example script to call, display and save the results of Astar algorithm.
map should be a 2-D matrix containing 0s for free cells and 100 for obstacle cells.


%To call the RAstar function:

[map_with_path,path,g_score,iter,cost,fail,t] = RAstar_diagonalH_8neighbors(map,Nb_iter_max,i_start,j_start,i_goal,j_goal); 


%Choosing file names to save performance and distance matrices:

outFile=strcat(DirectoryNamePerf,'/Astar_wTB.txt');
outFile2=strcat(DistanceMatrixDirectory,'/',fileName,'_run',num2str(k),'Astar_wTB.mat')
nb_expanded=sum(g_score(:)<Inf); 


% Performance statistics:

Perf=[mapDim,ObsRatio,ObsSize,k,i_start,j_start,i_goal,j_goal,iter,size(path,1),cost,t,fail,nb_expanded];


% Saving performance and distance matrices:

save(outFile,'Perf','-ascii','-append'); 
save(outFile2,'g_score');


% Displaying the map with the generated path

figure(3);imagesc(map_with_path);hold on;if ~isempty(path), plot(path(:,2),path(:,1),'g.-'), end
text(j_start,i_start,'START','FontSize',10)
text(j_goal,i_goal,'GOAL','FontSize',10)

Mpath 1.jpg


% Saving the figure:

figName=strcat(DirectoryName,'/',fileName,'_run',num2str(k),'Astar_wTB.png');
print('-dpng',figName);hold off


% Displaying the distance map

g_score(map_with_path==obstacle)=-100;
figure(4);imagesc(g_score);colorbar;hold on;
text(j_start,i_start,'START','FontSize',10)
text(j_goal,i_goal,'GOAL','FontSize',10)


Mpath 2.jpg


% Saving the figure

figName2=strcat(DistanceMapDirectory,'/',fileName,'_run',num2str(k),'Astar_wTB.png');
print('-dpng',figName2);hold off