Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.45 KB | None | 0 0
  1. %--------------------------------------------------------------------------
  2. % Test of ASTAR Path Planning Implementation
  3. %--------------------------------------------------------------------------
  4.  
  5. % Importing Original Image File
  6. Image=imread('imobstacle.png');
  7.  
  8. % Generating a Binary Image Map
  9.     % BW=FindObjects(Image);
  10.     % Returns a binary image map when the black boxes represent the areas
  11.     % where the path is not allowed (Matrix locations where the value is
  12.     % equal to 0) [0=Black 1=White]
  13. % Temporary file import
  14. load 'imdata.mat';
  15. BW=FindObjects(im);
  16. %BW(150:200,250:300)=0;
  17. %MAP=imcomplement(BW);
  18. MAP(200:350,150:200)=0;
  19. MAP(100:200,1:200)=0;
  20. MAP=imcomplement(MAP);
  21. % Take the Start and End Positions
  22. Start=Select_im_pts(Image,1); % Y loc first, X loc second
  23. End=Select_im_pts(Image,1); % Y loc first, X loc second
  24.  
  25. % Create the Goal Node for the algorithm to process
  26. Goal=int8(zeros(480,640));
  27. Goal(End(1),End(2))=1;
  28.  
  29. % Create an arbitrary distance between nodes
  30. Distance=8;
  31.  
  32. % Running Path Planning
  33. Path=ASTAR_Algorithm(Start(2),Start(1),MAP,Goal,Distance);
  34. % End
  35.  
  36. if size(Path,2)>1
  37.     figure(10)
  38.     imagesc((MAP))
  39.     colormap(flipud(gray));
  40.  
  41.     hold on
  42.     plot(Path(1,2),Path(1,1),'o','color','k')
  43.     plot(Path(end,2),Path(end,1),'o','color','b')
  44.     plot(Path(:,2),Path(:,1),'r')
  45.     legend('Goal','Start','Path')
  46. else
  47.      pause(1);
  48.  h=msgbox('Sorry, No path exists to the Target!','warn');
  49.  uiwait(h,5);
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement