Академический Документы
Профессиональный Документы
Культура Документы
DISEO MECNICO
Punto i di ai i
1 1 d1 0 90
Figura 5. Equipo realizando la implementacin 2 2+90 0 a2 0
3 3-90 0 a3 0
4 4+90 0 a4 90
5 5 d5 0 0
6 GRIPPER 0 0 0
i = 1,2,..,n
g : es el vector de gravedad expresado en el
sistema de la base {S0} y viene expresado por
(gx0,gy0,gz0,0)
rj : es el vector de coordenadas homognea del
Figura 19. Jacobiano de velocidad angular obtenido para centro de masas del elemento j expresado en el
este caso sistema de referencia del elemento i.
J. La ecuacin dinmica del sistema ser:
DINMICA DE LAGRANGE
Algoritmo computacional para el modelado dinmico de Donde T es el vector de fuerzas y pares motores
Lagrange-Euler. efectivos aplicados sobre cada coordenada qi.
delay(1000);
//Activa el puerto serial Ploteo de coordenadas:
Serial.begin(9600); function hout = plot_frame(T,varargin)
} % plot_frame Plot the frame of a 3D
transformation
void loop() { %
// put your main code here, to run repeatedly: % PLOT_FRAME(T, OPTIONS) draws a 3D
if(Serial.available()==4) coordinate frame represented by the
{//A. Leemos el byte enviado % SE(3) homogeneous transform T(4x4).
int angle_01=Serial.read(); // Se lee el valor %
int angle_02=Serial.read(); // Se lle valor uchar % Author: Ivan A. Calle
int angle_03=Serial.read(); // Se lee el valor Flores(icallef@uni.pe)
int angle_04=Serial.read(); // Se lle valor uchar
//B. enviamos el angulo al serrvomotor %--------------------------------------
my_servo_01.write(angle_01); --------------------------------%
% 1. INITIAL CONFIGURATION line(o,y1,o,'Color',
%-------------------------------------- opt.color,'linewidth',3,'Parent', hg)
--------------------------------% line(o,o,z1,'Color',
% 1.1. CHECK FOR THE CASE "trplot(H, opt.color,'linewidth',3,'Parent', hg)
T)" end
if isscalar(T) && ishandle(T)
% Set handle and transformation % 2.3. NOW PLACE THE FRAME IN THE
matrix DESIRED POSE
H = T; set(hg, 'Matrix', T);
T = varargin{1};
% Check for basic rotation matrices
if(size(T,1)==3 && size(T,2)==3) %--------------------------------------
T = [T zeros(3,1); zeros(1,3) --------------------------------%
1]; % 3. ADD EXTRA STUFF TO THE AXES
end %--------------------------------------
% Update Frame --------------------------------%
set(H, 'Matrix', T); % 3.1. LABEL THE AXES
return; if isempty(opt.frame)
end fmt = '%c';
else
% 1.2. CREATE A 'hgtransform' GRAPHICS fmt = sprintf('%%c_{%s}',
OBJECT TO HANDLE ALL THE AXES opt.frame);
hax = gca; end
hg = hgtransform('Parent', hax); % -> Put the labels 'Xi, Yi'
hold on text(x1(1), x1(2), x1(3), sprintf(fmt,
'X'), 'Parent', hg,....
% 1.3. SET VECTOR OF OPTIONS 'FontWeight', 'bold', 'FontSize',
% -> Default values 14);
opt.color = 'b'; text(y1(1), y1(2), y1(3), sprintf(fmt,
opt.axes = true; 'Y'), 'Parent', hg,...
opt.axis = []; 'FontWeight', 'bold', 'FontSize',
opt.frame = []; 14);
opt.view = []; text(z1(1), z1(2), z1(3), sprintf(fmt,
opt.width = 1; 'Z'), 'Parent', hg,...
opt.handle = []; 'FontWeight', 'bold', 'FontSize',
% -> Parse the vector 14);
opt = tb_optparse(opt, varargin);
% 3.2. LABEL THE NUMBER OF THE FRAME
% 1.4. CHECK FOR ROTATION MATRICES AT THE ORIGIN
if(size(T,1)==3 && size(T,2)==3) text(o(1)-0.04*x1(1), o(2)-0.04*y1(2),
T = [T zeros(3,1); zeros(1,3) 1]; ['\{' opt.frame '\}'], 'Parent', hg);
end
% 3.3. SET 'VIEWPOINT'
if ischar(opt.view) && strcmp(opt.view,
%-------------------------------------- 'auto')
--------------------------------% cam = x1+y1+z1;
% 2. DRAW THE AXES view(cam(1:3));
%-------------------------------------- elseif ~isempty(opt.view)
--------------------------------% view(opt.view);
% 2.1. CREATE UNIT VECTORS end
o = [0 0 0]';
x1 = [1 0 0]';
y1 = [0 1 0]'; %--------------------------------------
z1 = [0 0 1]'; --------------------------------%
% 4. RETURN HANDLE
% 2.2. DRAW THE NORMAL AXES AND ATTACH %--------------------------------------
THEM TO THE GROUP --------------------------------%
for i=1:3 if nargout > 0
line(x1,o,o,'Color', hout = hg;
opt.color,'linewidth',3,'Parent', hg) end
%Ponemos Los parametros DH
end % END FUNCTION q faltan
this.d1=L1;
this.a2=L2;
this.a3=L3;
this.a4=L4;
end
function
q=cinematica_inversa(this,xc,yc,zc)
Clase robot_RRRR %Metodo para la cinematica
inversa
classdef robot_RRRR<handle L1=this.LL1;
%ROBOT PLANAR L2=this.LL2;
L3=this.LL3;
L4=this.LL4;
properties
%PARAMETROS MECANICOS %%%%%%%%%%%%%%%%
LL1 %Angulo "theta 1"
LL2 q1_star=atan2(yc,xc);
LL3 %Angulo "theta3"
LL4 r2=xc^2+yc^2;
%PARAMETROS D.H r1=sqrt(r2);
d1 r=r1-L4;
a1 s=zc-L1;
alpha1 num=r^2+s^2-L2^2-L3^2;
d2 den=2*L2*L3;
a2 D=num/den;
alpha2 if(abs(D)>1)
d3 error('POSICION IMPOSIBLE
a3 DE ALCANZAR')
alpha3 end
d4 q3_star=atan2(+sqrt(1-D^2),D);
a4 q2_star=atan2(s,r)-...
alpha4
end atan2(L3*sin(q3_star),L2+L3*cos(q3_star
));
methods q4_star=-1*(q2_star + q3_star);
% CONSTRUCTOR %Vector de ANgulos
function this= robot_RRRR() q=[q1_star q2_star q3_star
%Inicializamos parametros q4_star];
this.a1=0; %fijo end
this.alpha1=pi/2; %fijo function
this.d2=0; A1=compute_matrix_A1(this,theta1)
this.alpha2=0; %Metodo para hallar A1
this.d3=0;
this.alpha3=0; A1=matriz_homogenea_DH(theta1,...
this.d4=0;
this.alpha4=0; this.d1,this.a1,this.alpha1);
end end
function
set_dimensions(this,L1,L2,L3,L4) function
%Metodo para asignar las A2=compute_matrix_A2(this,theta2)
dimensiones %Metodo para hallar A2
this.LL1=L1;
this.LL2=L2; A2=matriz_homogenea_DH(theta2,...
this.LL3=L3;
this.LL4=L4; this.d2,this.a2,this.alpha2);
end
%Angulo enviado al arduino
function ang_servo0y=[25 30 40 50 60 70 80 90
A3=compute_matrix_A3(this,theta3) 100 110 120 130 140 150 160 170 180];
%Metodo para hallar A3 %Angulo de trabajo
ang_servo0x=[0 10 20 30 40 50 60 70 80
A3=matriz_homogenea_DH(theta3,... 90 95 100 110 120 130 140 150];
%Angulo enviado al arduino
this.d3,this.a3,this.alpha3); ang_servo1y=[16 25 36 46 56 66 76 86 96
end 106 116 126 136 146 156];
%Angulo de trabajo
function
A4=compute_matrix_A4(this,theta4) ang_servo1x=[-2 15 25 40 50 60 70 80
%Metodo para hallar A3 100 115 120 130 145 155 170];
%Angulo enviado al arduino
ang_servo2y=[0 10 20 30 40 50 60 70 80
A4=matriz_homogenea_DH(theta4,...
90 100 110 120 130 140 150 160 170
180];
this.d4,this.a4,this.alpha4); %Angulo de trabajo
end ang_servo2x=[-20 -15 0 10 25 35 45 60
end 70 80 100 110 120 130 142 155 165 180
end 190];
%Angulo enviaado al arduino
Cinemtica Inversa: ang_servo3y=[30 40 50 60 70 80 90 100
El codigo busca que el actuador final se mantenga en 110 120 130 140 150 154 160 180];
direccion horizontal. %Angulo de trabajo
function q=cinematica_inversa(this,xc,yc,zc) ang_servo3x=[140 135 125 115 105 90 82
70 60 48 32 20 10 -8 -20 -30];
% Metodo para la cinematica inversa
L1=this.LL1;
P0=polyfit(ang_servo0x,ang_servo0y,2);
L2=this.LL2; P1=polyfit(ang_servo1x,ang_servo1y,2);
L3=this.LL3; P2=polyfit(ang_servo2x,ang_servo2y,2);
L4=this.LL4; P3=polyfit(ang_servo3x,ang_servo3y,2);
theta1=polyval(P0,ang_1);
%%%%%%%%%%%%%%%% theta2=polyval(P1,ang_2);
%Angulo "theta 1" theta3=polyval(P2,ang_3);
q1_star=atan2(yc,xc); theta4=polyval(P3,ang_4);
%Angulo "theta3"
r2=xc^2+yc^2;
r1=sqrt(r2); if(ang_1>0 && ang_1<20)
r=r1-L4; theta1=30;
s=zc-L1; end
num=r^2+s^2-L2^2-L3^2; if(ang_2>0 && ang_2<25)
den=2*L2*L3; theta1=25;
D=num/den; end
if(abs(D)>1) Codigo de interfaz (GUIDE)
error('POSICION IMPOSIBLE DE ALCANZAR') function varargout =
end Brazo_UNI(varargin)
%CODO ARRIBA
% BRAZO_UNI MATLAB code for
q3_star=atan2(-sqrt(1-D^2),D);
q2_star=atan2(s,r)-... Brazo_UNI.fig
atan2(L3*sin(q3_star),L2+L3*cos(q3_star)); % BRAZO_UNI, by itself, creates a
q4_star=-1*(q2_star + q3_star); new BRAZO_UNI or raises the existing
%Vector de ANgulos % singleton*.
q=[q1_star q2_star q3_star q4_star]; %
end % H = BRAZO_UNI returns the handle
to a new BRAZO_UNI or the handle to
Ajuste de servomotores: % the existing singleton*.
Ya que se observaba un desfasaje entre el angulo que se %
le mandaba al arduino y el ngulo de trabajo real. Se opt %
por hacer un ajuste usando la funcin polyval de matlab
BRAZO_UNI('CALLBACK',hObject,eventData,
para cada angulo , colocando todo esto en la funcin
thetas.
handles,...) calls the local
function [theta1,theta2, % function named CALLBACK in
theta3,theta4]=thetas(ang_1,ang_2,ang_3 BRAZO_UNI.M with the given input
,ang_4) arguments.
%
% function Brazo_UNI_OpeningFcn(hObject,
BRAZO_UNI('Property','Value',...) eventdata, handles, varargin)
creates a new BRAZO_UNI or raises the % This function has no output args, see
% existing singleton*. Starting OutputFcn.
from the left, property value pairs are % hObject handle to figure
% unrecognized property name or % eventdata reserved - to be defined
invalid value makes property in a future version of MATLAB
application % handles structure with handles and
% stop. All inputs are pa% user data (see GUIDATA)
applied to the GUI before % varargin command line arguments to
Brazo_UNI_OpeningFcn gets called. An Brazo_UNI (see VARARGIN)
%ssed to Brazo_UNI_OpeningFcn via
varargin.com % Choose default command line output
% for Brazo_UNI
% *See GUI Options on GUIDE's handles.output = hObject;
Tools menu. Choose "GUI allows only
one % Update handles structure
% instance to run (singleton)". guidata(hObject, handles);
%
% See also: GUIDE, GUIDATA, GUIHANDLES % UIWAIT makes Brazo_UNI wait for user
response (see UIRESUME)
% Edit the above text to modify the % uiwait(handles.figure1);
response to help Brazo_UNI
% Last Modified by GUIDE v2.5 19-Nov- % --- Outputs from this function are
2016 16:52:05 returned to the command line.
function varargout =
% Begin initialization code - DO NOT Brazo_UNI_OutputFcn(hObject, eventdata,
EDIT handles)
gui_Singleton = 1; % varargout cell array for returning
gui_State = struct('gui_Name', output args (see VARARGOUT);
mfilename, ... % hObject handle to figure
'gui_Singleton', % eventdata reserved - to be defined
gui_Singleton, ... in a future version of MATLAB
'gui_OpeningFcn', % handles structure with handles and
@Brazo_UNI_OpeningFcn, ... user data (see GUIDATA)
'gui_OutputFcn',
@Brazo_UNI_OutputFcn, ... % Get default command line output from
'gui_LayoutFcn', [] handles structure
, ... varargout{1} = handles.output;
'gui_Callback', %%
[]); axes(handles.axes1);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = %----------------------------%
str2func(varargin{1}); % 1.CONFIGURACION INICIAL
end %---------------------------%
%1.1 Posicion deseada
if nargout xc=3;
[varargout{1:nargout}] = yc=0;
gui_mainfcn(gui_State, varargin{:}); zc=2;
else %1.2 Ploteo del entorno
gui_mainfcn(gui_State, T0=eye(4);
varargin{:}); plot_frame(T0,'color','k','view','auto'
end );
% End initialization code - DO NOT EDIT axis([-2 4 -2 4 0 3])
hold on
grid on
% --- Executes just before Brazo_UNI is xlabel('x(m)')
made visible. ylabel('y(m)')
plot3(xc,yc,zc,'ro','MarkerFaceColor',' %4.2 Eslabon4
k','MarkerSize',10) %->Hallamos A4
%--------------------------------- theta4=0;
%2.Parametros Mecanicos Del Robot A4=my_robot.compute_matrix_A4(theta4);
%-------------------------------- %Ploteamos
L1=0.3; T04=T03*A4;
L2=1.2; h4=plot_frame(T04,'frame','4','color','
L3=1.25; b');
L4=1.54;
global my_robot set(handles.xc,'String',T04(1,4))
my_robot=robot_RRRR; set(handles.yc,'String',T04(2,4))
my_robot.set_dimensions(L1,L2,L3,L4) set(handles.zc,'String',T04(3,4))
%--------------------%
%3.CINEMATICA INVERSA global conectado
%--------------------% conectado = 0;
%3.1 UISAMOS EL METODO global linea
"cinemtica_inversa" linea = 0;
% axes(handles.axes2);
q=my_robot.cinematica_inversa(xc,yc,zc) hold on;
; I=imread ('uni.jpg');
% q1d=q(1); image(I);
% q2d=q(2);
% q3d=q(3); % --- Executes on button press in
% q4d=q(4); pushbutton1.
% %3.2Salidas function pushbutton1_Callback(hObject,
% disp('Angulos') ~, handles)
% disp(q) % hObject handle to pushbutton1 (see
% disp(q*180/pi) GCBO)
%----------------% % eventdata reserved - to be defined
%4.1 Eslabon 1 in a future version of MATLAB
%->Hallamos A1 % handles structure with handles and
global theta1 theta2 theta3 theta4 user data (see GUIDATA)
global h1 h2 h3 h4 xc =
theta1=0; str2num(get(handles.textbox1,'String'))
A1=my_robot.compute_matrix_A1(theta1); ;
%Ploteamos yc =
T01=A1; str2num(get(handles.textbox2,'String'))
h1=plot_frame(T01,'frame','1','color',' ;
r'); zc =
str2num(get(handles.textbox3,'String'))
;
%4.2 Eslabon2 %plot3(xc, yc, zc, 'ro',
%->Hallamos A2 'MarkerFaceColor', 'k',
theta2=0; 'MarkerSize',3);
A2=my_robot.compute_matrix_A2(theta2); global my_robot
%Ploteamos
T02=T01*A2; %. Cinematica Inversa
h2=plot_frame(T02,'frame','2','color',' %--------------------------------------
m'); -----------------------------------%
% 3.1. Usamos el Metodo " Cinematica_
Ivarsa"
%4.2 Eslabon3 q = my_robot.cinematica_inversa(xc, yc,
%->Hallamos A3 zc);
theta3=0; q1d = q(1);
A3=my_robot.compute_matrix_A3(theta3); q2d = q(2);
%Ploteamos q3d = q(3);
T03=T02*A3; q4d = q(4);
h3=plot_frame(T03,'frame','3','color',' % 3.2. Salidas
b'); % disp('angulos')
% disp(q)
% disp(q*180/pi) m=[theta1 theta2 theta3
% qc = q*180/pi; theta4]*180/pi();
%
% set(handles.th1,'String',qc(1)) [m1,m2,m3,m4]=thetas(m(1),m(2),m(3),m(4
% set(handles.th2,'String',qc(2)) ));
% set(handles.th3,'String',qc(3)) if conectado==1
% set(handles.th3,'String',qc(4)) fwrite(s1,
[m1,m2,m3,m4],'uchar');
end
set(handles.xc,'String',T04(1,4))
q1d =
function textbox4_Callback(hObject, str2num(get(handles.textbox4,'String'))
eventdata, handles) *pi()/180;
% hObject handle to textbox4 (see q2d =
GCBO) str2num(get(handles.textbox5,'String'))
% eventdata reserved - to be defined *pi()/180;
in a future version of MATLAB q3d =
% handles structure with handles and str2num(get(handles.textbox6,'String'))
user data (see GUIDATA) *pi()/180;
q4d =
% Hints: get(hObject,'String') returns str2num(get(handles.textbox7,'String'))
contents of textbox4 as text *pi()/180;
%
str2double(get(hObject,'String'))
returns contents of textbox4 as a STEPS=20;
double THETA1=linspace(theta1,q1d,STEPS);
THETA2=linspace(theta2,q2d,STEPS);
THETA3=linspace(theta3,q3d,STEPS);
% --- Executes during object creation, THETA4=linspace(theta4,q4d,STEPS);
after setting all properties. %5. Lazo Principal
function textbox4_CreateFcn(hObject, for i=1:STEPS
eventdata, handles) %A.Obtenemos Los angulos
% hObject handle to textbox4 (see theta1=THETA1(i);
GCBO) theta2=THETA2(i);
% eventdata reserved - to be defined theta3=THETA3(i);
in a future version of MATLAB theta4=THETA4(i);
%%
m=[theta1 theta2 theta3 function conectar_Callback(hObject,
theta4]*180/pi(); eventdata, handles)
% hObject handle to conectar (see
[m1,m2,m3,m4]=thetas(m(1),m(2),m(3),m(4 GCBO)
)); % eventdata reserved - to be defined
if conectado==1 in a future version of MATLAB
fwrite(s1, % handles structure with handles and
[m1,m2,m3,m4],'uchar'); user data (see GUIDATA)
end
%% % Hint: get(hObject,'Value') returns
toggle state of conectar
set(handles.th1,'String',theta1*180/pi( global conectado
)) global puerto
%clear puerto
set(handles.th2,'String',theta2*180/pi( global s1
)) conectado = 1-conectado;
puerto = get(handles.puerto,'String');
set(handles.th3,'String',theta3*180/pi( puerto = strcat('com',puerto);
)) if conectado == 1
fclose('all');
set(handles.th4,'String',theta4*180/pi( delete(instrfind)
)) s1=serial(puerto);
m=[theta1 theta2 theta3 theta4]; fopen(s1);
disp('m:') disp(puerto)
disp(m*180/pi) old=[0,0,0,0];
%B.Obtenemos Los angulos fwrite(s1,old,'uchar');
end
A1=my_robot.compute_matrix_A1(theta1);
A2=my_robot.compute_matrix_A2(theta2);
function puerto_Callback(hObject,
A3=my_robot.compute_matrix_A3(theta3); eventdata, handles)
% hObject handle to puerto (see
A4=my_robot.compute_matrix_A4(theta4); GCBO)
% eventdata reserved - to be defined
T01=A1; in a future version of MATLAB
T02=A1*A2; % handles structure with handles and
T03=T02*A3; user data (see GUIDATA)
T04=T03*A4;
set(handles.xc,'String',T04(1,4)) % Hints: get(hObject,'String') returns
set(handles.yc,'String',T04(2,4)) contents of puerto as text
set(handles.zc,'String',T04(3,4)) %
%C.PLOTEAMOS LOS SITEMAS str2double(get(hObject,'String'))
COORDENADOS returns contents of puerto as a double
plot_frame(h1,T01);
plot_frame(h2,T02);
plot_frame(h3,T03); % --- Executes during object creation,
plot_frame(h4,T04); after setting all properties.
function puerto_CreateFcn(hObject,
%DELTA DE TIEMPO eventdata, handles)
pause(0.1) % hObject handle to puerto (see
end GCBO)
% eventdata reserved - to be defined
theta1 = q1d; in a future version of MATLAB
theta2 = q2d; % handles empty - handles not
theta3 = q3d; created until after all CreateFcns
theta4 = q4d; called
% --- Executes on button press in
conectar. % Hint: edit controls usually have a
white background on Windows.
% See ISPC and COMPUTER. end
if ispc && % --- Executes on button press in
isequal(get(hObject,'BackgroundColor'), modo_linea.
get(0,'defaultUicontrolBackgroundColor' function modo_linea_Callback(hObject,
)) eventdata, handles)
% hObject handle to modo_linea (see
set(hObject,'BackgroundColor','white'); GCBO)
end % eventdata reserved - to be defined
in a future version of MATLAB
% handles structure with handles and
% --- Executes during object creation, user data (see GUIDATA)
after setting all properties. global linea
function th4_CreateFcn(hObject, linea = 1-linea;
eventdata, handles)
% hObject handle to th4 (see GCBO) % Hint: get(hObject,'Value') returns
% eventdata reserved - to be defined toggle state of modo_linea
in a future version of MATLAB
% handles empty - handles not
created until after all CreateFcns
called
function textbox7_Callback(hObject,
eventdata, handles)
% hObject handle to textbox7 (see
GCBO)
% eventdata reserved - to be defined
in a future version of MATLAB
% handles structure with handles and
user data (see GUIDATA)