RADAR Docente: ING. ALBERTO ARISPE SANTANDER Auxiliar: Mario Severich Zurita
Universitario: Garcia Acarapi Alex Duher Alanez Roberto Carlos Grupo: 05
SEMESTRE 1/2014 COCHABAMBA-BOLIVIA I. Introduccin Viendo las facilidades que se obtienen al trabajar con el material ofrecido en laboratorio se buscara realizar un proyecto ms complejo que las prcticas realizadas durante el mismo, para poder aplicar los conocimientos de programacin en el software matemtico MATLAB y el desarrollo con el Kit de LEGO MINDSTORM NXT 1.0.
En el presente proyecto se desarrollara un radar ultrasnico, con la ayuda del kit de LEGO MINDSTORM NXT 1.0 haciendo uso del sensor ultrasnico para que pueda mostrar los objetos a su alrededor en tiempo real.
II. Marco Terico Radar El radar (trmino derivado del acrnimo ingls radio detection and ranging, deteccin y medicin de distancias por radio) es un sistema que usa ondas electromagnticas para medir distancias, altitudes, direcciones y velocidades de objetos estticos o mviles como aeronaves, barcos, vehculos motorizados, formaciones meteorolgicas y el propio terreno. Su funcionamiento se basa en emitir un impulso de radio, que se refleja en el objetivo y se recibe tpicamente en la misma posicin del emisor. A partir de este "eco" se puede extraer gran cantidad de informacin. El uso de ondas electromagntica con diversas longitudes de onda permite detectar objetos ms all del rango de otro tipo de emisiones (luz visible, sonido, etc.)
Sensor ultrasnico NXT Este sensor le permite a nuestro robot ver y detectar obstculos as como medir distancias.
Bsicamente puede detectar objectos que estn de 0 a 255 centmetros de distancia con una precisin de +/-3 cm. Esto significa que si hay un objecto a 40 cm exactamente el sensor puede verlo desde 37 hasta 43cm, este es su margen de error.
Este sensor funciona igual que como lo hace un radar o un sonar. Enva ondas de sonido en una frecuencia muy alta y mide el tiempo que el "eco" (el rebote de las ondas) de sonido tarda en regresar al sensor. Esto es muy similar a como un murcilago "ve".
Matlab interfaz GUIDE es un ambiente de desarrollo que permite crear interfaces grficas con el usuario, que contengan elementos tales como botones y ventanas de seleccin, ventanas grficas, mens, ejes para graficar, etc.
Cuando en el command window se escribe guide, se ofrece la posibilidad de abrir hojas de trabajo ya creadas (p.ej. >>guide archivo.fig) o una nueva sobre la cual se irn agregando componentes. Lo que se cree aqu se guardar con la extensin .fig. La primera vez que uno salva la interfaz que est diseando se crea tambin un archivo .m sobre el cual habr que programar lo que se quiere ver o controlar desde el GUI una vez que se disea la interfaz grfica (GUI) que uno desea fijando las caractersticas de botones, ventanas, etc. que la conforman, se puede entonces programar dicha interfaz con el editor de archivos .m IV. Desarrollo Para el desarrollo del proyecto se realiz la interfaz grfica en Matlab:
Donde se pueden ejecutar las siguientes funciones: Encender Se encarga de indicar que el robot est listo para trabajar adems de presentar un texto en la interfaz indicando su condicin.
Apagar Se encarga de cerrar las comunicaciones con el robot y presenta un texto en la interfaz indicando su condicin.
Calibrar Se encarga de realizar la secuencia para calibrar al sensor brjula tal como indica la pgina web de la librera para Matlab.
Posicionar Se encarga de orientar al robot hacia el norte.
Sensar Se encarga de realizar la toma de datos de ngulos y distancias y desplegarlas en tiempo real en la interfaz.
El funcionamiento de la interfaz es bastante simple, los aspectos y graficas son programados en la funcin inicial o modificados con el asistente de la GUIDE de Matlab.
Cada botn realiza un llamado hacia un mtodo el cual se encargara de abrir la comunicacin con el NXT, realizar el programa debido y cerrar la comunicacin, siendo independientes cada uno de ellos para pruebas por separado (sin la interfaz) y relacionando sus datos y variables en los Callbacks de la interfaz.
V. Cdigo
function varargout = Interfaz_radar_2(varargin) % INTERFAZ_RADAR_2 M-file for Interfaz_radar_2.fig % INTERFAZ_RADAR_2, by itself, creates a new INTERFAZ_RADAR_2 or raises the existing % singleton*. % % H = INTERFAZ_RADAR_2 returns the handle to a new INTERFAZ_RADAR_2 or the handle to % the existing singleton*. % % INTERFAZ_RADAR_2('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in INTERFAZ_RADAR_2.M with the given input arguments. % % INTERFAZ_RADAR_2('Property','Value',...) creates a new INTERFAZ_RADAR_2 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Interfaz_radar_2_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Interfaz_radar_2_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 Interfaz_radar_2
% Last Modified by GUIDE v2.5 11-Jul-2013 06:10:29
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Interfaz_radar_2_OpeningFcn, ... 'gui_OutputFcn', @Interfaz_radar_2_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 Interfaz_radar_2 is made visible. function Interfaz_radar_2_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 Interfaz_radar_2 (see VARARGIN)
% Choose default command line output for Interfaz_radar_2 handles.output = hObject;
% UIWAIT makes Interfaz_radar_2 wait for user response (see UIRESUME) % uiwait(handles.figure1);
%DIBUJAR EL RADAR axes(handles.axes1);
set(gca,'Color',[0 0 0]); grid on; line([0 0],[-500 500],'color','g'); line([-250 250],[0 0],'color','g'); line([-250 250],[-250 250],'color','g'); line([250 -250],[-250 250],'color','g'); hold on for j=1:5 t=0:pi/30:2*pi; x=50*j*cos(t); y=50*j*sin(t); plot(x,y,'color','g'); axis([-250 250 -250 250]); hold on end set(handles.text3,'BackgroundColor',[1 0 0],'Visible','on','string','OFF'); set(handles.text4,'Visible','off');
% --- Outputs from this function are returned to the command line. function varargout = Interfaz_radar_2_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 ENCENDER. function ENCENDER_Callback(hObject, eventdata, handles) % hObject handle to ENCENDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Encender_Radar; set(handles.text3,'BackgroundColor',[0 1 0],'Visible','on','string','ON');
% --- Executes during object creation, after setting all properties. function ENCENDER_CreateFcn(hObject, eventdata, handles) % hObject handle to ENCENDER (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in APAGAR. function APAGAR_Callback(hObject, eventdata, handles) % hObject handle to APAGAR (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Apagar_Radar; set(handles.text3,'BackgroundColor',[1 0 0],'Visible','on','string','OFF');
% --- Executes during object creation, after setting all properties. function APAGAR_CreateFcn(hObject, eventdata, handles) % hObject handle to APAGAR (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in SENSAR. function SENSAR_Callback(hObject, eventdata, handles) % hObject handle to SENSAR (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global puntos Var_sen=0;
if(grado<90) xA=-sin(gradoRad)*distancia; yA=cos(gradoRad)*distancia; else if(grado==90) xA=-distancia; yA=0; else if(grado<180) xA=-cos(gradoRad-pi/2)*distancia; yA=-sin(gradoRad-pi/2)*distancia; else if (grado==180) xA=0; yA=-distancia; else if (grado<270) xA=sin(gradoRad-pi)*distancia; yA=-cos(gradoRad-pi)*distancia; else if(grado==270) xA=distancia; yA=0; else xA=cos(gradoRad-3*pi/2)*distancia; yA=sin(gradoRad-3*pi/2)*distancia; end end end end end end xAD(Var_sen+1)=xA; yAD(Var_sen+1)=yA; puntos(Var_sen+1)=plot(xA,yA,'ws-'); drawnow; Var_sen=Var_sen+1; end
%Obtener el Path de la carpeta Actual [stat,struc] = fileattrib; PathCurrent = struc.Name;
%crear las rutas (Path) para carpetas y archivos FolderName = ['datos']; PathFolder = [PathCurrent '/' FolderName]; Nameexcel = [PathFolder '/datosexcel.xls']; Nameexcel2 = [PathFolder '/coordexcel.xls']; % crear las carpetas para guardar los resultados mkdir([PathCurrent], FolderName);
%Guardar datos en archivo EXCEL titulo = {'X' 'Y'}; datos2 = vertcat(xAD,yAD)'; xlswrite(Nameexcel2, titulo, 1, 'A1'); xlswrite(Nameexcel2, datos2, 1, 'A2');
%Guardar datos en archivo EXCEL titulo = {'grado' 'distancia'}; datos = vertcat(gradoD,distanciaD)'; xlswrite(Nameexcel, titulo, 1, 'A1'); xlswrite(Nameexcel, datos, 1, 'A2');
% --- Executes during object creation, after setting all properties. function SENSAR_CreateFcn(hObject, eventdata, handles) % hObject handle to SENSAR (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in POSICIONAR. function POSICIONAR_Callback(hObject, eventdata, handles) % hObject handle to POSICIONAR (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Posicionar_Radar; global estado estado=1; set(handles.text4,'ForegroundColor',[1 1 1],'BackgroundColor',[0 0 0],'Visible','on','string',estado);
% --- Executes during object creation, after setting all properties. function POSICIONAR_CreateFcn(hObject, eventdata, handles) % hObject handle to POSICIONAR (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in CALIBRAR. function CALIBRAR_Callback(hObject, eventdata, handles) % hObject handle to CALIBRAR (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Calibrar_Radar;
% --- Executes during object creation, after setting all properties. function CALIBRAR_CreateFcn(hObject, eventdata, handles) % hObject handle to CALIBRAR (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
VI. Conclusiones El diseo del proyecto se encuentra en un archivo LDD (Lego Digital Designer) adjunto al informe.
Debido a que solo se pueden complicar los cdigos que utilizan instrucciones que hacen referencia al kit de Lego Mindstorm en el Laboratorio, se supusieron varias cosas al momento de realizar los cdigos para acelerar el tiempo de prueba en el laboratorio.
Se encontraron algunas dificultados debido a la compatibilidad de la librera para programar debido a la limitacin de trabajar con mquinas de 64 bits que posean versiones de Matlab inferiores a la 2011b.
Se realizaron algunos cambios oportunos de programacin y diseo oportunos durante la presentacin del proyecto, para un funcionamiento ms correcto.
Debido al tiempo para realizar el proyecto quedan pendientes algunos detalles que podran mejorar el funcionamiento.
Se aprendi a realizar las interfaces graficas en Matlab y el manejo de datos dentro de Matlab.