+ All Categories
Home > Documents > MAZE-SOLVER-SIMULATOR.docx

MAZE-SOLVER-SIMULATOR.docx

Date post: 08-Sep-2015
Category:
Upload: paul-martinez
View: 218 times
Download: 0 times
Share this document with a friend
Popular Tags:
32
MAZE SOLVER SIMULATOR Lema Henry, 401, Martínez Paúl, 479, Navarrete Diego, 734, Pillajo Martha, 733 Robotic Basics Facultad de Informática y Electrónica, ESPOCH, Riobamba, Ecuador Abstract. - This paper presents the development of a GUI using Matlab, whose purpose is to simulate the behavior of a robot follower wall inside a maze, this interface allows the user to choose the dimension of the matrix and then fill it with binary data representing the path to go also you can choose the priority with which you want to run from right or left. The design and development of a prototype of this robot were made as a project for Robotic Basics subject from the seventh semester of the Engineering Control Electronic career from Polytechnic School of Chimborazo. Keywords. - GUI, Matlab, maze, priority. I. INTRODUCTION. MATLAB is a mathematical software tool that offers an integrated development environment with its own programming language that allows the manipulation of matrices, data representation and functions, implementation of algorithms, communication with programs in other languages and creating user interfaces (GUI).The designed prototype was based on "Arduino", an open electronic platform, that allows the creation of prototypes based flexible software and hardware. GUIs (also known as graphical user interfaces or UIs) provide point-and- click control of software applications, eliminating the need to learn a language or type commands in order to run the application. MATLAB apps are self-contained MATLAB programs with GUI front ends that automate a task or calculation. The GUI typically contains controls such as menus, toolbars, buttons, and sliders. Many MATLAB products, such as Curve Fitting Toolbox, Signal Processing Toolbox, and Control System Toolbox, include apps with custom user interfaces. You can also create your own custom apps, including their corresponding UIs, for others to use. II. FRAMEWORK The GUIDE tools are available from the Layout Editor shown in the figure below. The tools are called out in the figure and described briefly below. Subsequent sections show you how to use them.
Transcript

Paper Title (use style: paper title)

MAZE SOLVER SIMULATORLema Henry, 401, Martnez Pal, 479, Navarrete Diego, 734, Pillajo Martha, 733Robotic BasicsFacultad de Informtica y Electrnica, ESPOCH, Riobamba, Ecuador

Abstract. - This paper presents the development of a GUI using Matlab, whose purpose is to simulate the behavior of a robot follower wall inside a maze, this interface allows the user to choose the dimension of the matrix and then fill it with binary data representing the path to go also you can choose the priority with which you want to run from right or left.The design and development of a prototype of this robot were made as a project for Robotic Basics subject from the seventh semester of the Engineering Control Electronic career from Polytechnic School of Chimborazo.

Keywords. - GUI, Matlab, maze, priority.

Introduction.MATLAB is a mathematical software tool that offers an integrated development environment with its own programming language that allows the manipulation of matrices, data representation and functions, implementation of algorithms, communication with programs in other languages and creating user interfaces (GUI).The designed prototype was based on "Arduino", an open electronic platform, that allows the creation of prototypes based flexible software and hardware.GUIs (also known as graphical user interfaces or UIs) provide point-and-click control of software applications, eliminating the need to learn a language or type commands in order to run the application.MATLAB apps are self-contained MATLAB programs with GUI front ends that automate a task or calculation. The GUI typically contains controls such as menus, toolbars, buttons, and sliders. Many MATLAB products, such as Curve Fitting Toolbox, Signal Processing Toolbox, and Control System Toolbox, include apps with custom user interfaces. You can also create your own custom apps, including their corresponding UIs, for others to use.FrameworkThe GUIDE tools are available from the Layout Editor shown in the figure below. The tools are called out in the figure and described briefly below. Subsequent sections show you how to use them.

Fig. 1 Layout Editor from MatlabAvailable on: http://www.mathworks.com/help/releases/R2015a/matlab/creating_guis/guide_menus.png

These are some of tools you can use: Layout Editor. - Select components from the component palette, at the left side of the Layout Editor, and arrange them in the layout area. See Add Components to the GUIDE Layout Area for more information. Figure Resize Tab. - Set the size at which the UI is initially displayed when you run it. See Set the UI Window Size in GUIDE for more information. Menu Editor. - Create menus and context, i.e., pop-up, menus. See Create Menus for GUIDE UIs for more information. Align Objects. - Align and distribute groups of components. Grids and rulers also enable you to align components on a grid with an optional snap-to-grid capability. See Align GUIDE UI Components for more information. Tab Order Editor. - Set the tab and stacking order of the components in your layout. See Customize Tabbing Behavior in a GUIDE UI for more information. Toolbar Editor. - Create Toolbars containing predefined and custom push buttons and toggle buttons. See Create Toolbars for GUIDE UIs for more information. Icon Editor. - Create and modify icons for tools in a toolbar. See Create Toolbars for GUIDE UIs for more information. Property Inspector. - Set the properties of the components in your layout. It provides a list of all the properties you can set and displays their current values. Object Browser. - Display a hierarchical list of the objects in the UI. See View the GUIDE Object Hierarchy for more information. Run. - Save the UI and run the program. Editor. - Display, in your default editor, the code file associated with the UI. See Files Generated by GUIDE for more information. Position Readouts. - Continuously display the mouse cursor position and the positions of selected objects.

V. Development and DesingThis maze solver simulator was designed and developed on Matrix Laboratory MATLAB Software, currently we have designed a little simulator based on wall following algorithm. Our simulator is basically composed by two figures, the one is basically a presentation of our program and the second involves all of the process of simulator. Here we describe the figs one by one.MaskThis figure is only a presentation of our program. In this, we can enter the section of the simulator or just close the app.

Fig. 2 Presentation structureSource: Author

Fig. 3 Presentation been executed Source: AuthorLogic algorithmThe program is based on a search cycle by which we have simulated the operation of a compass. That is, we know our current position and orientation and examine our environment to decide which position and orientation can move forward. This cycle continues to run indefinitely until our present position is equal to the final position entered on the problem. In short, this program runs for all free spaces have, according to their programmed priority and if a number 1 was replaces it with a 2 as a path taken, however if a point has to go back a path will be marked with a number 3 to identify who had to return to that section of the maze.This part helps us to color the maze and determine the actual path of our prototype.SimulabThis figure is the heart of our Simulator. In this all off process to solve maze are developed and shown interactively the resolution of maze.

Fig. 4 Simulator StructureSource: Author

Fig. 5 Simulator Been Executed Source: AuthorUsers GuideThis App allows you dimension the matrix entering the number of rows and columns.After you must indicate the way forward represented by 1 and the remainder will be zero. Considering making a single input and a single output.

Fig. 6 Sizing the matrixSource: Author

In these boxes you must write the start and final position of the path.

Fig. 7 Start and final positionSource: Author

Finally you must choose between right or left priority, and the simulation will run.

Fig. 8 Right or left prioritySource: Author

VI. Conclusions We must be very careful when designing the labyrinth only has one input and one output, otherwise the program may go into an infinite loop. B CVII. References[1] MathWorks. GUIDE Tools Summary [online]. Available in: http://www.mathworks.com/help/matlab/creating_guis/guide-tools-summary.html?refresh=true

[2] MathWorks. Writing Apps in MATLAB [online]. Available in:http://www.mathworks.com/company/newsletters/articles/writing-apps-in-matlab.html

[3] MathWorks. Creating Apps with Graphical User Interfaces in MATLAB [online]. Available in: http://www.mathworks.com/discovery/matlab-gui.html

AuthorLema Henry, Martnez Pal, Navarrete Diego, Pillajo MarthaStudents of Escuela de Ingeniera Electrnica en Control y Redes Industriales.Escuela Superior Politcnica de ChimborazoEcuador10/07/2015

ANNEXES

PROGRAM CODE(Mask)

function varargout = Caratula(varargin)% CARATULA M-file for Caratula.fig% CARATULA, by itself, creates a new CARATULA or raises the existing% singleton*.%% H = CARATULA returns the handle to a new CARATULA or the handle to% the existing singleton*.%% CARATULA('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in CARATULA.M with the given input arguments.%% CARATULA('Property','Value',...) creates a new CARATULA or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before Caratula_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to Caratula_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 Caratula % Last Modified by GUIDE v2.5 14-Jun-2015 20:05:56 % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Caratula_OpeningFcn, ... 'gui_OutputFcn', @Caratula_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 Caratula is made visible.function Caratula_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 Caratula (see VARARGIN) % Choose default command line output for Caratulahandles.output = hObject; % Update handles structureguidata(hObject, handles);%Las siguientes tres lneas cambian la apariencia%reemplazando el logo de MATLAB por el de JAVAwarning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame'); javaFrame = get(hObject,'JavaFrame');javaFrame.setFigureIcon(javax.swing.ImageIcon('icon.JPG')); %La siguientes lneas permiten la visualizacin de los logos de la %ESPOCH, FIE y el fondo de esta figuraaxes(handles.axes1)background = imread('espoch.jpg'); axis off; imshow(background);axes(handles.axes2) background = imread('fie.jpg'); axis off; imshow(background); axes(handles.axes5)background = imread('rob.jpg'); axis off; imshow(background); % UIWAIT makes Caratula wait for user response (see UIRESUME)% uiwait(handles.caratula); % --- Outputs from this function are returned to the command line.function varargout = Caratula_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 structurevarargout{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)%Si seleccionamos este botn se cerrar el programaclose; % --- Executes on button press in entra.function entra_Callback(hObject, eventdata, handles)% hObject handle to entra (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%Al hacer click en el botn llamado entra:%Cerramos la figura actual y procedemos a abrir la figura SimuLab%en donde se encuentra el Simulador de LaberintocloseSimuLab % --- Executes when caratula is resized.function caratula_ResizeFcn(hObject, eventdata, handles)% hObject handle to caratula (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

(SimuLab)

function varargout = SimuLab(varargin)% SIMULAB MATLAB code for SimuLab.fig% SIMULAB, by itself, creates a new SIMULAB or raises the existing% singleton*.%% H = SIMULAB returns the handle to a new SIMULAB or the handle to% the existing singleton*.%% SIMULAB('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in SIMULAB.M with the given input arguments.%% SIMULAB('Property','Value',...) creates a new SIMULAB or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before SimuLab_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to SimuLab_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 SimuLab % Last Modified by GUIDE v2.5 14-Jun-2015 19:57:35 % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @SimuLab_OpeningFcn, ... 'gui_OutputFcn', @SimuLab_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 SimuLab is made visible.function SimuLab_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 SimuLab (see VARARGIN) % Choose default command line output for SimuLab handles.output = hObject;%Borramos todas las variables del Command Window de MATLABclc%Estas lneas nos ayudan a mostrar la imagen en la parte inferior derecha%de la GUIaxes(handles.axes3)background = imread('rob2.jpg'); axis off; imshow(background);%Mediante estas lneas volvemos invisibles todos los campos al iniciar el%programaset(handles.mat_lab,'Visible','Off');set(handles.axes1,'Visible','Off');set(handles.axes2,'Visible','Off');set(handles.prioder,'Visible','Off');set(handles.prioizq,'Visible','Off');set(handles.inglab,'Visible','Off');set(handles.entrada,'Visible','Off');set(handles.salida,'Visible','Off');set(handles.pix,'Visible','Off');set(handles.piy,'Visible','Off');set(handles.pfx,'Visible','Off');set(handles.pfy,'Visible','Off');set(handles.ingpos,'Visible','Off');set(handles.text6,'Visible','Off');set(handles.text7,'Visible','Off');set(handles.text8,'Visible','Off');set(handles.text9,'Visible','Off');%Mediante estas lineas cambiamos la apariencia, introduciendo el icono de%JAVA en la aplicacionwarning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');javaFrame = get(hObject,'JavaFrame');javaFrame.setFigureIcon(javax.swing.ImageIcon('icon.JPG'));% Update handles structureguidata(hObject, handles); % UIWAIT makes SimuLab wait for user response (see UIRESUME)% uiwait(handles.figure1); % --- Outputs from this function are returned to the command line.function varargout = SimuLab_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 structurevarargout{1} = handles.output; function columnas_Callback(hObject, eventdata, handles)% hObject handle to columnas (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA%Agui obtenemos el numero de columnas y se lo asignamos a una variable%llamada numcol para manejarla dentro del programaval1=get(hObject,'String');valor1=str2double(val1);handles.numcol=valor1;guidata(hObject,handles); % Hints: get(hObject,'String') returns contents of columnas as text% str2double(get(hObject,'String')) returns contents of columnas as a double % --- Executes during object creation, after setting all properties.function columnas_CreateFcn(hObject, eventdata, handles)% hObject handle to columnas (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end function filas_Callback(hObject, eventdata, handles)% hObject handle to filas (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%Agui obtenemos el numero de filas y se lo asignamos a una variable%llamada numcol para manejarla dentro del programaval2=get(hObject,'String');valor2=str2double(val2);handles.numfil=valor2;guidata(hObject,handles);% Hints: get(hObject,'String') returns contents of filas as text% str2double(get(hObject,'String')) returns contents of filas as a double % --- Executes during object creation, after setting all properties.function filas_CreateFcn(hObject, eventdata, handles)% hObject handle to filas (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end % --- Executes on button press in ingdim.function ingdim_Callback(hObject, eventdata, handles)% hObject handle to ingdim (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%Esta funcion lee los valores ingresados para las filas y las columnas, si%se encuentran dentro del rango determinado permite ingresarlas y crear una%matriz de dichas dimensionesnum_col=handles.numcol;num_fil=handles.numfil;%Creamos variables globales para manejar las dimensiones de la matriz en%todo el programaglobal nc;global nf; %Controlamos errores de dimensiones if ((num_col=30) errordlg('Ingrese valores vlidos',' ERROR');else %Asignamos los valores ingresados a las variables globales antes %creadas nc=num_col; nf=num_fil; %Procedemos a crear una matriz de las dimensiones ingresadas y a la vez %generamos una tabla de las mismas dimensiones para ingresar los datos matl=cell(num_fil,num_col); matl(:,:)={''}; set(handles.mat_lab,'Data',matl); set(handles.mat_lab,'ColumnEditable',true(1,num_col)); %Volvemos visibles los demas campos, los mismos que permanecian ocultos set(handles.mat_lab,'Visible','On'); set(handles.axes1,'Visible','On'); set(handles.axes2,'Visible','On'); set(handles.prioder,'Visible','On'); set(handles.prioizq,'Visible','On'); set(handles.inglab,'Visible','On'); set(handles.entrada,'Visible','On'); set(handles.salida,'Visible','On'); set(handles.pix,'Visible','On'); set(handles.piy,'Visible','On'); set(handles.pfx,'Visible','On'); set(handles.pfy,'Visible','On'); set(handles.ingpos,'Visible','On'); set(handles.text6,'Visible','On'); set(handles.text7,'Visible','On'); set(handles.text8,'Visible','On'); set(handles.text9,'Visible','On');end guidata(hObject,handles); % --- Executes on button press in inglab.function inglab_Callback(hObject, eventdata, handles)% hObject handle to inglab (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%Al hacer click en este boton primeramente comprobamos que todos los datos%ingresados sean 1`s o 0`s; de lo contrario no se permite el ingreso de la%matrizglobal mlabglobal mlab2num_col=handles.numcol;num_fil=handles.numfil; datos=(get(handles.mat_lab,'data'))for i=1:num_fil for j=1:num_col ml(i,j)=str2double(datos{i,j}); endendcorrecto=1;for i=1:num_fil for j=1:num_col if( ml(i,j)~=0&&ml(i,j)~=1) %Mensaje de error si tenemos un dato errneo errordlg('Recuerde ingresar valores de 1 y 0 para el laberinto. Ingrese de nuevo',' ERROR'); correcto=0; break end endendif (correcto==1) mlab=ml; mlab2=mlab; %Mensaje si se ingresa correctamente warndlg('Laberinto correctamente ingresado',' COMPLETO');end % --- Executes on button press in Salir.function Salir_Callback(hObject, eventdata, handles)% hObject handle to Salir (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%Al hacer click en este boton cerramos el programa.close SimuLab % --- Executes on button press in prioder.function prioder_Callback(hObject, eventdata, handles)% hObject handle to prioder (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%Funcion prioridad derecha %Borramos las variables del Command Window e Inicializamos variables%locales tomando los valores correspondientes de variables globalesclcglobal mlab;matrizlab=mlab;global nfglobal nc%Procedemos a comprobar el posicionamiento tanto del inicio como del fin%del camino trazado para el laberintoglobal posixxglobal posiyyglobal posfxxglobal posfyynorte=0;sur=0;este=0;oeste=0; % global avanza;% global retrocede;% global izquierda;% global derecha;% global regreso;posixx=handles.posix;posiyy=handles.posiy;posfxx=handles.posfx;posfyy=handles.posfy;%Mensaje si hay error en las posiciones finales o iniciales de la rutaif (posixxnf || posiyync || (posfxxnf || posfyync || mlab(posixx,posiyy)==0 || mlab(posfxx,posfyy)==0)) errordlg('Ingrese valores vlidos',' ERROR');else%Proceso a realizar si se cumple correctamente el ingreso del inicio y del%fin del laberinto. %Inicialmente nos basamos en una matriz auxiliar que nos ayude a la hora de%dibujar el mismo, inicialmente trazamos el patron en blanco y negro. for i=1:nf for j=1:nc if mlab(i,j)==1 matrizlab(i,j,1)=255; %Definimos laberinto entre blanco y negro matrizlab(i,j,2)=255; %blanco para la via y negro para paredes de matrizlab(i,j,3)=255; %laberinto end end end %Trazamos las posiciones de salida y entrada del laberinto matrizlab(posixx,posiyy,2)=0; matrizlab(posfxx,posiyy,2)=0; imshow(matrizlab,'parent',handles.axes1); pause(2); regreso=0; %Variables de orientacion que nos ayudaran a determinar nuestra posicon %actual en todo momento norte=0; sur=0; este=0; oeste=0; %Al comenzar determinamos posicionamiento inicial del robot posxact=posixx; posyact=posiyy; %El programa se basa en un ciclo de busqueda mediante el cual se ha %simulado el funcionamiento de una brujula. Es decir: sabemos nuestra %posicion y orientacion actual y examinamos nuestro entorno para %decidir a hacia que posicion y orientacion podemos avanzar. Dicho %ciclo seguira ejecuandose de modo indefinido hasta que nuestra %posicion actual sea igual a la posicion final ingresada en el %problema. Motivo por el que debemos tener mucho cuidado al disear el %laberinto que solo tenga una entrada y una salida, de lo contrario el %programa puede entrar en un ciclo infinito while(posxact~=posfxx||posyact~=posfyy) %Inicialmente debemos determinar en donde nos encontramos y hacia %donde tenemos espacio libre y decidimos segun nuestra prioridad en %este caso derecha. if (posxact==1 &&posyact>1&&posyact1&&posyact1&&posxact1&&posxact1&&posxact1&&posyact1&&posyact1&&posyact1&&posxact1&&posxact1&&posxact1&&posyact


Recommended