【二维路径规划】基于A星算法求解机器人路径规划
matlab代码
1 简介
移动机器人路径规划一直是一个比较热门的话题,A星算法以及其扩展性算法被广范地应用于求解移动机
器人的最优路径.该文在研究机器人路径规划算法中,详细阐述了传统A星算法的基本原理,并通过栅格法分
割了机器人路径规划区域,利用MATLAB仿真平台生成了机器人二维路径仿真地图对其进行仿真实验,并对
结果进行分析和研究,为今后进一步的研究提供经验.
2 部分代码
function varargout = test(varargin)
% TEST MATLAB code for test.fig
,obj2_currentPos,'Curvature',[1 1],'FaceColor',[0 0 1]);
end
if obj3 == 1
rectangle('Position',obj3_currentPos,'Curvature',[1 1],'FaceColor',[0 0
1]);
end
str = strcat(str,sprintf('\nReach the goal point...'));
set(handles.result,'String',str);
end
% --- Executes on button press in obj1.
function obj1_Callback(hObject, eventdata, handles)
% hObject handle to obj1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get the handles to the objects of interest:
hObj1X = handles.obj1X;
hObj1Y = handles.obj1Y;
% Get the string value
stringObj1X = get(hObj1X,'String');
stringObj1Y = get(hObj1Y,'String');
obj1X = str2num(stringObj1X);
obj1Y = str2num(stringObj1Y);
setappdata( 0, 'obj1', 1 );
mapResize = evalin( 'base', 'mapResize' );
if(length(obj1X)>0 && length(obj1Y)>0)
[obj1_currentPos,obj1_centerPoint] = createObj(mapResize,obj1X,obj1Y);
else
[obj1_currentPos,obj1_centerPoint] = createObj(mapResize);
end
rectangle('Position',obj1_currentPos,'Curvature',[1 1],'FaceColor',[0 0 1]);
% save route into basic workspace
assignin('base', 'obj1_centerPoint', obj1_centerPoint);
assignin('base', 'obj1_currentPos', obj1_currentPos);
global str;
tmp = sprintf('\nobject 1 start point is: [');
tmp = strcat(tmp,num2str(obj1_centerPoint(1)));
tmp = strcat(tmp,',');
tmp = strcat(tmp,num2str(obj1_centerPoint(2)));
tmp = strcat(tmp,']');
str = strcat(str,tmp);
set(handles.result,'String',str);
% --- Executes on button press in obj2.
function obj2_Callback(hObject, eventdata, handles)
% hObject handle to obj2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get the handles to the objects of interest:
hObj2X = handles.obj2X;
hObj2Y = handles.obj2Y;
% Get the string value
stringObj2X = get(hObj2X,'String');
stringObj2Y = get(hObj2Y,'String');
obj2X = str2num(stringObj2X);
obj2Y = str2num(stringObj2Y);
% save route into basic workspace
assignin('base', 'obj2X', obj2X);
assignin('base', 'obj2Y', obj2Y);
setappdata( 0, 'obj2', 1 );
mapResize = evalin( 'base', 'mapResize' );
if(length(obj2X)>0 && length(obj2Y)>0)
[obj2_currentPos,obj2_centerPoint] = createObj(mapResize,obj2X,obj2Y);
else
[obj2_currentPos,obj2_centerPoint] = createObj(mapResize);
end
rectangle('Position',obj2_currentPos,'Curvature',[1 1],'FaceColor',[0 0 1]);
% save route into basic workspace
assignin('base', 'obj2_centerPoint', obj2_centerPoint);
assignin('base', 'obj2_currentPos', obj2_currentPos);
global str;
tmp = sprintf('\nobject 2 start point is: [');
tmp = strcat(tmp,num2str(obj2_centerPoint(1)));
tmp = strcat(tmp,',');
tmp = strcat(tmp,num2str(obj2_centerPoint(2)));
tmp = strcat(tmp,']');
str = strcat(str,tmp);
set(handles.result,'String',str);
% --- Executes on button press in obj3.
function obj3_Callback(hObject, eventdata, handles)
% hObject handle to obj3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.result,'String','obj3');
% Get the handles to the objects of interest:
hObj3X = handles.obj3X;
hObj3Y = handles.obj3Y;
% Get the string value
stringObj3X = get(hObj3X,'String');
stringObj3Y = get(hObj3Y,'String');
obj3X = str2num(stringObj3X);
评论5