1. 程式人生 > 其它 >【路徑規劃】基於matlab GUI機器人路徑規劃【含Matlab原始碼 1007期】

【路徑規劃】基於matlab GUI機器人路徑規劃【含Matlab原始碼 1007期】

一、簡介

基於matlab GUI機器人路徑規劃

二、原始碼

function varargout = fpp(varargin)
% FPP M-file for fpp.fig
%      FPP, by itself, creates a new FPP or raises the existing
%      singleton*.
%
%      H = FPP returns the handle to a new FPP or the handle to
%      the existing singleton*.
%
%      FPP('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FPP.M with the given input arguments.
%
%      FPP('Property','Value',...) creates a new FPP or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before fpp_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to fpp_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 fpp

% Last Modified by GUIDE v2.5 15-Jun-2021 23:14:56

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @fpp_OpeningFcn, ...
                   'gui_OutputFcn',  @fpp_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before fpp is made visible.
function fpp_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 fpp (see VARARGIN)

% Choose default command line output for fpp
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes fpp wait for user response (see UIRESUME)
% uiwait(handles.figure1);

map=[];
setappdata(0,'map',map);
posf=0;
setappdata(0,'posf',posf);
mapf=0;
setappdata(0,'mapf',mapf);

axes(handles.axes1) % Select the proper axes
axis([1,100,1,100,-10,300])
view([-20,-15,20])
set(handles.axes1,'XMinorTick','on')



% --- Outputs from this function are returned to the command line.
function varargout = fpp_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 on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

posf=0;
setappdata(0,'posf',posf);
mapf=0;
setappdata(0,'mapf',mapf);
i=1:100;
j=1:100;
w = str2double(get(handles.edit1,'String'));
map=[];
setappdata(0,'map',map);
A=zeros(100,100);
axes(handles.axes1) % Select the proper axes
mesh(i,j,A(i,j))
axis([1,100,1,100,-10,300])
view([-20,-15,20])
set(handles.axes1,'XMinorTick','on')

axes(handles.axes2) % Select the proper axes
contour(i,j,A(i,j),60)
set(handles.axes2,'XMinorTick','on')


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

posf=0;
setappdata(0,'posf',posf);
mapf=1;
setappdata(0,'mapf',mapf);
axes(handles.axes2) % Select the proper axes
set(handles.axes2,'XMinorTick','on')
axis([1 100 1 100]);
% hold on
h=msgbox('Draw a wall by using the left mouse button for start and right mouse button for ending the wall');
uiwait(h,5);
if ishandle(h)==1
    delete(h);
end
but=0;
%but=1 left     but=3 right
while(but~=1)
    [xs,ys,but]=ginput(1);
end
but=0;
while(but~=3)
    [xe,ye,but]=ginput(1);
end

xs=round(xs*10)/100;
ys=round(ys*10)/100;
xe=round(xe*10)/100;
ye=round(ye*10)/100;

map = getappdata(0,'map');
w = str2double(get(handles.edit1,'String'));
map=mmap([xs,ys],[xe,ye],map,w);
setappdata(0,'map',map);

i=1:100;
j=1:100;

x=map(:,2);
y=map(:,1);
w=map(:,3);
R=[];
A1=[];
% GoalY=y(length(x));
% GoalX=x(length(x));

for I=1:100
  for J=1:100
      R=[];
      for r=1:length(x)-1
          R=[R w(r)/((J/10-y(r))^2+(I/10-x(r))^2)];
      end
%          RG = sqrt((J/10-GoalY)^2+(I/10-GoalX)^2);
         A1(I,J) = sum(R);
            if (A1(I,J)>300)
                A1(I,J)=300;
            end  
 end
end
A=A1;
axes(handles.axes1) % Select the proper axes
mesh(i,j,A(i,j))
axis([1,100,1,100,-10,300])
view([-20,-15,20])
set(handles.axes1,'XMinorTick','on')

三、執行結果


四、備註

版本:2014a
完整程式碼或代寫加1564658423