一、A_star算法简介

1 A Star算法及其应用现状
进行搜索任务时提取的有助于简化搜索过程的信息被称为启发信息.启发信息经过文字提炼和公式化后转变为启发函数.启发函数可以表示自起始顶点至目标顶点间的估算距离, 也可以表示自起始顶点至目标顶点间的估算时间等.描述不同的情境、解决不同的问题所采用的启发函数各不相同.我们默认将启发函数命名为H (n) .以启发函数为策略支持的搜索方式我们称之为启发型搜索算法.在救援机器人的路径规划中, A Star算法能结合搜索任务中的环境情况, 缩小搜索范围, 提高搜索效率, 使搜索过程更具方向性、智能性, 所以A Star算法能较好地应用于机器人路径规划相关领域.

2 A Star算法流程
承接2.1节, A Star算法的启发函数是用来估算起始点到目标点的距离, 从而缩小搜索范围, 提高搜索效率.A Star算法的数学公式为:F (n) =G (n) +H (n) , 其中F (n) 是从起始点经由节点n到目标点的估计函数, G (n) 表示从起点移动到方格n的实际移动代价, H (n) 表示从方格n移动到目标点的估算移动代价.

如图2所示, 将要搜寻的区域划分成了正方形的格子, 每个格子的状态分为可通过(walkable) 和不可通过 (unwalkable) .取每个可通过方块的代价值为1, 且可以沿对角移动 (估值不考虑对角移动) .其搜索路径流程如下:

图2 A Star算法路径规划
Step1:定义名为open和closed的两个列表;open列表用于存放所有被考虑来寻找路径的方块, closed列表用于存放不会再考虑的方块;
Step2:A为起点, B为目标点, 从起点A开始, 并将起点A放入open列表中, closed列表初始化为空;
Step3:查看与A相邻的方格n (n称为A的子点, A称为n的父点) , 可通过的方格加入到open列表中, 计算它们的F, G和H值.将A从open移除加入到closed列表中;
Step4:判断open列表是否为空, 如果是, 表示搜索失败, 如果不是, 执行下一步骤;
Step5:将n从open列表移除加入到closed列表中, 判断n是否为目标顶点B, 如果是, 表示搜索成功, 算法运行结束;
Step6:如果不是, 则扩展搜索n的子顶点:
a.如果子顶点是不可通过或在close列表中, 忽略它.
b.子顶点如果不在open列表中, 则加入open列表, 并且把当前方格设置为它的父亲, 记录该方格的F, G和H值.
Step7:跳转到步骤Step4;
Step8:循环结束, 保存路径.从终点开始, 每个方格沿着父节点移动直至起点, 即是最优路径.A Star算法流程图如图3所示.

图3 A Star算法流程

二、部分源代码

function varargout = Astar(varargin)
% ASTAR MATLAB code for Astar.fig
%      ASTAR, by itself, creates a new ASTAR or raises the existing
%      singleton*.
%
%      H = ASTAR returns the handle to a new ASTAR or the handle to
%      the existing singleton*.
%
%      ASTAR('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ASTAR.M with the given input arguments.
%
%      ASTAR('Property','Value',...) creates a new ASTAR or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Astar_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Astar_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help Astar% Last Modified by GUIDE v2.5 30-Oct-2020 10:58:46% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...'gui_Singleton',  gui_Singleton, ...'gui_OpeningFcn', @Astar_OpeningFcn, ...'gui_OutputFcn',  @Astar_OutputFcn, ...'gui_LayoutFcn',  [] , ...'gui_Callback',   []);
if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});
endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT% --- Executes just before Astar is made visible.
function Astar_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Astar (see VARARGIN)% Choose default command line output for Astar
handles.output = hObject;% Update handles structure
guidata(hObject, handles);% UIWAIT makes Astar wait for user response (see UIRESUME)
% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.
function varargout = Astar_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)% Get default command line output from handles structure
varargout{1} = handles.output;% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
%%%%%%%%%%%%%%%%%%%%%%%%%%初始化参数%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Xo=[0 0];%起点位置
longth=1;%步长
J=2000;%循环迭代次数
Xj=Xo;%j=1循环初始,将车的起始坐标赋给Xj
MAX_X=100;
MAX_Y=100;
%This array stores the coordinates of the map and the
%Objects in each coordinate
MAP=2*(ones(MAX_X,MAX_Y));
% Obtain Obstacle, Target and Robot Position
% Initialize the MAP with input values
% Obstacle=-1,Target = 0,Robot=1,Space=2
j=0;
x_val = 1;
y_val = 1;
axis([-20 120 -20 120])
axis equal;
hold on;
axis off;
%set(gcf,'color','y')
%title ('A*算法路径规划');
fill([-20,120,120,-20],[-20 -20 120 120],'y')
fill([95,120,120,95],[-20 -20 10 10],'w')
text(100,5,'Notes:','FontSize',12)
plot(101,-5,'sb','markerfacecolor','b');
text(101,-5,'  Robot','FontSize',12);
plot(101,-15,'om','markerfacecolor','m');
text(101,-15,'  Ball','FontSize',12);
plot(1,1,'bs')
car=plot(1,1,'sb','markerfacecolor','b');
%car_name=text(0,0,'  ','FontSize',12);
object=plot(0,100,'om','markerfacecolor','m');
%object_name=text(0,100,'  Ball','FontSize',12);
but=1;
text(-4,-4,'  Start','FontSize',12);
n=0;%Number of Obstacles
% BEGIN Interactive Obstacle, Target, Start Location selection
xTarget=0;%X Coordinate of the Target
yTarget=100;%Y Coordinate of the Target
m_Target=[xTarget,yTarget];
%object=plot(1,100,'om','markerfacecolor','m');
%object_name=text(1,100,'  Ball','FontSize',12);
%选择小车起点位置
xval=1;
yval=1;
xStart=xval;
yStart=yval;
MAP(xval,yval)=1;
%car=plot(1,1,'bs','markerfacecolor','b');
%car_name=text(1,1,' ','FontSize',12);
% hObject    handle to axes1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called% Hint: place code in OpeningFcn to populate axes1% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
%main
Xo=[0 0];%起点位置
longth=1;%步长
J=2000;%循环迭代次数
Xj=Xo;%j=1循环初始,将车的起始坐标赋给Xj
%DEFINE THE 2-D MAP ARRAY
MAX_X=100;
MAX_Y=100;
%MAX_VAL=100;
%This array stores the coordinates of the map and the
%Objects in each coordinate
MAP=2*(ones(MAX_X,MAX_Y));
% Obtain Obstacle, Target and Robot Position
% Initialize the MAP with input values
% Obstacle=-1,Target = 0,Robot=1,Space=2
j=0;
x_val = 1;
y_val = 1;
axis([-20 120 -20 120])
%grid on;
%hold on;
axis equal;
hold on;
axis off;
%set(gcf,'color','y')
%title ('A*算法路径规划');
fill([-20,120,120,-20],[-20 -20 120 120],'y')
fill([95,120,120,95],[-20 -20 10 10],'w')
text(100,5,'Notes:','FontSize',12)
plot(101,-5,'sb','markerfacecolor','b');
text(101,-5,'  Robot','FontSize',12);
plot(101,-15,'om','markerfacecolor','m');
text(101,-15,'  Ball','FontSize',12);
plot(1,1,'bs')
car=plot(1,1,'sb','markerfacecolor','b');
%car_name=text(0,0,'  ','FontSize',12);
object=plot(0,100,'om','markerfacecolor','m');
%object_name=text(0,100,'  Ball','FontSize',12);
but=1;
text(-4,-4,'  Start','FontSize',12);
n=0;%Number of Obstacles
% BEGIN Interactive Obstacle, Target, Start Location selection
xTarget=0;%X Coordinate of the Target
yTarget=100;%Y Coordinate of the Target
m_Target=[xTarget,yTarget];
%object=plot(1,100,'om','markerfacecolor','m');
%object_name=text(1,100,'  Ball','FontSize',12);
%选择小车起点位置
xval=1;
yval=1;
xStart=xval;
yStart=yval;
MAP(xval,yval)=1;
while but == 1[xval,yval,but] = ginput(1);if but==1xval=floor(xval);yval=floor(yval);MAP(xval,yval)=-1;%Put on the closed list as well%plot(xval,yval,'ro','markerfacecolor','r','MarkerSize',10);Theta=0:pi/20:pi;xx =xval+cos(Theta)*3;yy= yval+sin(Theta)*3;fill(xx,yy,'w')Theta=pi:pi/20:2*pi;xx =xval+cos(Theta)*3;yy= yval+sin(Theta)*3;fill(xx,yy,'k')end
end%End of While loop

三、运行结果

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
[3]钱程,许映秋,谈英姿.A Star算法在RoboCup救援仿真中路径规划的应用[J].指挥与控制学报. 2017,3(03)

【路径规划】基于matlab A_star算法机器人动态避障路径规划【含Matlab源码 1033期】相关推荐

  1. 【路径规划】基于matlab A_star算法机器人动态避障【含Matlab源码 2571期】

    ⛄一.A_star算法简介 1 A Star算法及其应用现状 进行搜索任务时提取的有助于简化搜索过程的信息被称为启发信息.启发信息经过文字提炼和公式化后转变为启发函数.启发函数可以表示自起始顶点至目标 ...

  2. 【路径规划】基于matlab DWA算法机器人局部避障路径规划【含Matlab源码 890期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[路径规划]基于matlab DWA算法机器人局部避障路径规划[含Matlab源码 890期] 获取代码方式2: 通过订阅紫极神光博客付费 ...

  3. 【Matlab图像融合】小波变换遥感图像融合【含GUI源码 744期】

    一.代码运行视频(哔哩哔哩) [Matlab图像融合]小波变换遥感图像融合[含GUI源码 744期] 二.matlab版本及参考文献 1 matlab版本 2014a 2 参考文献 [1] 包子阳,余 ...

  4. 【Matlab人脸识别】KL变换人脸识别【含GUI源码 859期】

    一.代码运行视频(哔哩哔哩) [Matlab人脸识别]KL变换人脸识别[含GUI源码 859期] 二.matlab版本及参考文献 1 matlab版本 2014a 2 参考文献 [1] 蔡利梅.MAT ...

  5. 【Matlab语音隐写】DWT音频数字水印【含GUI源码 712期】

    一.代码运行视频(哔哩哔哩) [Matlab语音隐写]DWT音频数字水印[含GUI源码 712期] 二.matlab版本及参考文献 1 matlab版本 2014a 2 参考文献 [1]韩纪庆,张磊, ...

  6. 【Matlab通信】DTMF双音多频电话拨号仿真【含GUI源码 805期】

    一.代码运行视频(哔哩哔哩) [Matlab通信]DTMF双音多频电话拨号仿真[含GUI源码 805期] 二.matlab版本及参考文献 1 matlab版本 2014a 2 参考文献 [1] 蔡利梅 ...

  7. 【Matlab心音信号】EMD心音信号特征提取【含GUI源码 1735期】

    一.代码运行视频(哔哩哔哩) [Matlab心音信号]EMD心音信号特征提取[含GUI源码 1735期] 二.matlab版本及参考文献 1 matlab版本 2014a *2 参考文献 [1] 沈再 ...

  8. 【A_star三维路径规划】基于matlab A_star算法机器人栅格地图三维路径规划【含Matlab源码 190期】

    一.A_star算法简介 1 A Star算法及其应用现状 进行搜索任务时提取的有助于简化搜索过程的信息被称为启发信息.启发信息经过文字提炼和公式化后转变为启发函数.启发函数可以表示自起始顶点至目标顶 ...

  9. 【Matlab路径规划】蚁群算法机器人大规模栅格地图最短路径规划【含源码 1860期】

    一.代码运行视频(哔哩哔哩) [Matlab路径规划]蚁群算法机器人大规模栅格地图最短路径规划[含源码 1860期] 二.蚁群算法及栅格地图简介 随着机器人技术在诸多领域的应用, 如机器人协作焊接.灾 ...

  10. A星融合DWA的路径规划算法,可实现静态避障碍及动态避障,代码注释详细,matlab源码

    A星融合DWA的路径规划算法,可实现静态避障碍及动态避障,代码注释详细,matlab源码 ID:4525679980340317云的歌儿

最新文章

  1. 剑指offer:面试题10- I. 斐波那契数列
  2. 艾麦捷科技-铂金小猪新年致辞
  3. 私有云的优缺点_2019年中国云计算行业竞争格局与发展趋势分析「图」
  4. 王者荣耀中有哪些获胜率高的玩法?
  5. iris数据_Kaggle 数据可视化课程5
  6. 输入一个以回车结束的字符串,判断该字符串是否对称(正序与逆序相同,如aBc2cBa为对称字符串)
  7. python 多进程 调用模块内函数_进程创建fork()和multiprocessing模块Process类
  8. AutoML在推荐系统协同过滤中的探索与发现(附交流视频和PPT下载链接)
  9. python set去重 字典 计算求和_python字典set方法的特殊方法
  10. 【Luogu1182】数列分段Section II(二分)
  11. python 对象和json互相转换
  12. codeigniter_MY_Model
  13. MacBook M1安装Git与Git可视化工具---kalrry
  14. 海思视频监控芯片如何一步步成为行业霸主
  15. UniFi AP 5.5.20的基本使用与设置(普通漫游和无缝漫游)
  16. No package erlang available
  17. word目录怎么自动生成?写作人必学的小技巧
  18. 计算机键盘pausebreak,键盘PauseBreak键作用
  19. 商标注册服务的详细讲解
  20. Kruskal vs Borůvka

热门文章

  1. npm 代理的设置和取消
  2. 赋值运算符、逻辑运算符、表达式
  3. VS2010 MVC的 安装
  4. 2014年java软件project师面试题收集
  5. 20145233《网络对抗》Exp6 信息收集和漏洞扫描
  6. 快速对表的某字段赋递增的数值
  7. 修改Apache配置文件开启gzip压缩传输
  8. Tomcat6.0 配置外部数据源(JNDI)
  9. python读图片生成ROI并保存
  10. 算法与数据结构 第3章 高级排序算法上 归并算法