【路径规划】基于A星算法机器人静态避障路径规划matlab代码

152 阅读2分钟

1 简介

移动机器人路径规划一直是一个比较热门的话题,A星算法以及其扩展性算法被广范地应用于求解移动机器人的最优路径。该文在研究机器人路径规划算法中,详细阐述了传统A星算法的基本原理,并通过栅格法分割了机器人路径规划区域,利用MATLAB仿真平台生成了机器人二维路径仿真地图对其进行仿真实验,并对结果进行分析和研究,为今后进一步的研究提供经验。​

A星算法是一种启发性的算法,即由通过设定评估函数,全面性地对网格的各个节点进行评估。而每个节点就是机器人所到达的位置,对每个位置点都进行智能化评估,找到最好的位置,从而最终找到目标位置。A星算法评估函数如下:

2 部分代码

close all; clear all;

%initial the map size

size_x = 10;

size_y = 10;

size_t = 100;

%1 - white - clear cell

%2 - black - obstacle

%3 - Grayish blue   - robot 1

%4 - Reddish blue - robot 2

%5 - purple - robot 3

%6 - vivid green - robot 4

%7 - Plum red - robot 5

cmap = [1 1 1;            

              0 0 0;

              0.69 0.87 0.90;

              0.25 0.41 0.88;

              0.63 0.13 0.94;

              0 1 0.5;

              0.87 0.63 0.87;

              ];

colormap(cmap);    %将颜色进行映射

%initial the space_time_map and reservation table

space_map = ones(size_x, size_y);

space_time_map = ones(size_x, size_y, size_t);

reservation_table = zeros(size_x, size_y, size_t);

%add the static obstacle

space_time_map(1:5, 5, :) = 2*ones(5,1, size_t);

reservation_table(1:5, 5, :) = 2*ones(5,1, size_t);

%the start point array and end point array

start_points= [2 4; 5 1];%[2 4; 5 1; 1 1; 9 6;7 3 ];

end_points = [8 7; 8 10];%[8 7; 10 10; 7 3; 3 2; 1 1];

len_route_max = 0;

route_all = [];

for index = 1:length(start_points(:,1))

%initial the start point and the end point

route = [];         %搜索出来的最短路径点的集合

start_coords =start_points(index, :);

disp(start_coords);

end_coords = end_points(index, :);

disp(end_coords);

[route] = Time_Astar_For_Cooperative_Path_Finding(start_coords, end_coords, space_time_map, reservation_table);

route_all(index, 1:length(route)) =route; 

disp(route);

    if (length(route) >len_route_max)

        len_route_max = length(route);  %总的需要走过的步数

    end

    for i = 1:size(route, 2)

        reservation_table(route(i)) =index+2;

    end

end

%show  the moving process

for i = 1:len_route_max

        show_map = ones(size_x, size_y);

        show_map(1:5, 5) = 2*ones(5,1);

       for j = 1:length(start_points(:,1))

            if (route_all(j, i))

                [x, y, t] = ind2sub(size(space_time_map), route_all(j, i));

                show_map(x, y) = j+2;

            else

                route_all(j, i) = route_all(j, i-1);

                [x, y, t] = ind2sub(size(space_time_map), route_all(j, i));

                show_map(x, y) = j+2;

             end

        end

       image(1.5, 1.5, show_map)

       grid on;

       axis image;

       drawnow;

       pause(2);

end

3 仿真结果

4 参考文献

[1]周宇杭, 王文明, 李泽彬,等. 基于A星算法的移动机器人路径规划应用研究[J]. 电脑知识与技术:学术版, 2020, 16(13):4.

部分理论引用网络文献,若有侵权联系博主删除。

5 MATLAB代码与数据下载地址

见博客主页