Taller UI Con Matlab

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Taller: UI (User Interface) con MATLAB

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


RobotDiosa

% Last Modified by GUIDE v2.5 24-Aug-2021 16:59:11

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn',
@RobotDiosa_OpeningFcn, ...
'gui_OutputFcn',
@RobotDiosa_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 RobotDiosa is made visible.


function RobotDiosa_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 RobotDiosa (see
VARARGIN)

% Choose default command line output for RobotDiosa


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes RobotDiosa wait for user response (see


UIRESUME)
% uiwait(handles.figure1);
tic;
global t vel pos x y n
t=0;
vel=0;
pos=0;
x=0;
y=0;
n=0;
handles.timer = timer(...
'ExecutionMode','fixedSpacing', ... % Run timer
repeatedly
'Period', 0.1, ... % Initial period
'TimerFcn', {@actualizar,hObject}); %'TimerFcn',
{@actualizar,hObject}); % Specify callback function
start(handles.timer); % Configurar e iniciar
temporizador

% --- Outputs from this function are returned to the


command line.
function varargout = RobotDiosa_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)
global n
n=n+1;
if n>2
n=1;
end

% --- Executes on slider movement.


function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data (see
GUIDATA)

% Hints: get(hObject,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to
determine range of slider
global pos p
p=get(handles.slider1,'value');
set(handles.text4,'string',strcat(num2str(p,'%.1f')))
pos=p*pi/180;

% --- Executes during object creation, after setting all


properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles empty - handles not created until after all
CreateFcns called

% Hint: slider controls usually have a light gray


background.
if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on slider movement.


function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data (see
GUIDATA)

% Hints: get(hObject,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to
determine range of slider
global vel v
v=get(handles.slider2,'value');
set(handles.text5,'string',strcat(num2str(v,'%.1f')))
vel=v/10;

% --- Executes during object creation, after setting all


properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles empty - handles not created until after all
CreateFcns called

% Hint: slider controls usually have a light gray


background.
if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function actualizar(hObject,eventdata,hfigure)
handles = guidata(hfigure); %linea desde ejemplo del
timer matlab
global n vel pos x y
%set(handles.text5,'string',strcat(num2str(toc,'%.1f')))

if n==1
set(handles.pushbutton1,'BackgroundColor','red')
set(handles.pushbutton1,'string','DETENER')

y(length(y)+1)=sin(pos)*vel+y(length(y));
x(length(x)+1)=cos(pos)*vel+x(length(x));

plot(handles.axes1,x,y,'*')
xlim(handles.axes1,[-1000 1000])
ylim(handles.axes1,[-1000 1000])
end
if n==2
set(handles.pushbutton1,'BackgroundColor','green')
set(handles.pushbutton1,'string','AVANZAR')
end

% --- Executes when user attempts to close figure1.


function figure1_CloseRequestFcn(hObject, eventdata,
handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future
version of MATLAB
% handles structure with handles and user data (see
GUIDATA)

% Hint: delete(hObject) closes the figure


delete(hObject);

stop(timerfindall); %Parar temporizador


delete(timerfindall); % Eliminar temporizador

Gráficas
1. Robot inicia en una posición 0,0.

2. Procedemos accionar el robot variando su velocidad y posición con el fin de evidenciar su


trayectoria, para esto definimos las posiciones tipo circulo, es decir que variaran en
ángulos de 0 a 360 grados.
3. Procedemos a variar el rango de ángulos que abarcará el robot nuevamente, esto debido a
que en el ejemplo anterior no vemos la trayectoria en ángulos negativos.

You might also like