You are on page 1of 4

%Mecanismo de 4 Barras -- Erwin Cuno Luza

clear all
clc, close all
l1=input('Ingrese la Longitud del brazo 1 = ');
l2=input('Ingrese la Longitud del brazo 2 = ');
l3=input('Ingrese la Longitud del brazo 3 = ');
l4=input('Ingrese la Longitud del brazo 4 = ');
opc=input('El mecanismo tendra velocidad angular constante? \n Si(1)\n
No(2)\nOpcion:');

if opc==1
t1p=input('Ingrese la velocidad angular(w)=');
for i=0:5:360
t1=i*pi/180;
A=l4-(l1*cos(t1));
B=l1*sin(t1);
beta=atan(A/B);
C=(l3^2-(A^2)-(B^2)-l2^2)/(2*l2);
t2=(asin(C)+beta);
t3=(acos((l1*sin(t1)+l2*sin(t2))/l3));
M=[l2*sin(t2),-l3*cos(t3);l2*cos(t2),l3*sin(t3)];
t1pp=0;
kv=[-l1*sin(t1)*t1p;-l1*cos(t1)*t1p];
V=M\kv;
t2p=V(1,1);
t3p=V(2,1);
ka=[-l1*cos(t1)*(t1p^2)-l1*cos(t1)*(t1pp^2)l2*cos(t2)*(t2p^2);l1*sin(t1)*(t1p^2)-l1*cos(t1pp)+l2*sin(t2).*(t2p^2)l3*sin(t3)*(t3p^2)];
Ac=M\ka;
t2pp=Ac(1,1);
t3pp=Ac(2,1);
t11=t1*180/pi;
t22=t2*180/pi;
t33=t3*180/pi;
figure(1)
plot(t11,t22,'xr','linewidth',5);
title('Grafica de Posicion');
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_2()','fontsize',15);
grid on;
hold on;
figure(2);
plot(t11,t33,'ob','linewidth',2);
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_3(rad)','fontsize',15);
grid on;
hold on;
figure(3)
plot(t11,t1p,'xr','linewidth',2);
title('Grafica de Posicion');
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_1_p(rad/s^2)','fontsize',15);

grid on;
hold on;
figure(4);
plot(t11,t2p,'ob','linewidth',2);
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_2_p(rad/s)','fontsize',15);
grid on;
hold on;
figure(5);
plot(t1,t3p,'sg','linewidth',2);
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_3_p(rad/s)','fontsize',15);
grid on;
hold on;
figure(6);
plot(t11,t1pp,'xr','linewidth',2);
title('Grafica de Posicion');
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_1_p_p(rad/s^2)','fontsize',15);
grid on;
hold on;
figure(7);
plot(t11,t2pp,'ob','linewidth',2);
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_2_p_p(rad/s^2)','fontsize',15);
grid on;
hold on;
figure(8);
plot(t11,t3pp,'sg','linewidth',2);
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_3_p_p(rad/s^2)','fontsize',15);
grid on;
hold on;

end
end
if opc==2
t1p_o=input('Ingrese la velocidad angular inicial(w_o)=');
t1pp=input('Ingrese la aceleracion angular(a)=');
for i=0:5:360
t1=i*pi/180;
A=l4-(l1*cos(t1));
B=l1*sin(t1);
beta=atan(A/B);
C=(l3^2-(A^2)-(B^2)-l2^2)/(2*l2);
t2=(asin(C)+beta);
t3=(acos((l1*sin(t1)+l2*sin(t2))/l3));
M=[l2*sin(t2),-l3*cos(t3);l2*cos(t2),l3*sin(t3)];
t=i/2;%tiempo 180s
%w=w0+at, mientras la aceleracion sea constante
t1p=t1p_o+t1pp*t;%velocidad varia con respecto al tiempo en
funcion de la aceleracion
kv=[-l1*sind(t1).*t1p ; -l1*cosd(t1).*t1p];
V=M\kv;
t2p=V(1,1);
t3p=V(2,1);

ka=[-l1*cos(t1)*(t1p^2)-l1*cos(t1)*(t1pp^2)l2*cos(t2)*(t2p^2);l1*sin(t1)*(t1p^2)-l1*cos(t1pp)+l2*sin(t2)*(t2p.^2)l3*sind(t3)*(t3p^2)];
Ac=M\ka;
t2pp=Ac(1,1);
t3pp=Ac(2,1);
t11=t1*180/pi;
t22=t2*180/pi;
t33=t3*180/pi;
figure(1)
plot(t11,t22,'xr','linewidth',5);
title('Grafica de Posicion');
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_2()','fontsize',15);
grid on;
hold on;
figure(2);
plot(t11,t33,'ob','linewidth',2);
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_3(rad)','fontsize',15);
grid on;
hold on;
figure(3)
plot(t11,t1p,'xr','linewidth',2);
title('Grafica de Posicion');
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_1_p(rad/s^2)','fontsize',15);
grid on;
hold on;
figure(4);
plot(t11,t2p,'ob','linewidth',2);
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_2_p(rad/s)','fontsize',15);
grid on;
hold on;
figure(5);
plot(t1,t3p,'sg','linewidth',2);
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_3_p(rad/s)','fontsize',15);
grid on;
hold on;
figure(6);
plot(t11,t1pp,'xr','linewidth',2);
title('Grafica de Posicion');
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_1_p_p(rad/s^2)','fontsize',15);
grid on;
hold on;
figure(7);
plot(t11,t2pp,'ob','linewidth',2);
xlabel('\theta_1()','fontsize',15);
ylabel('\theta_2_p_p(rad/s^2)','fontsize',15);
grid on;
hold on;
figure(8);
plot(t11,t3pp,'sg','linewidth',2);
xlabel('\theta_1()','fontsize',15);

ylabel('\theta_3_p_p(rad/s^2)','fontsize',15);
grid on;
hold on;
end
end

COMMAND WINDOW
Ingrese la Longitud del brazo 1 = 3
Ingrese la Longitud del brazo 2 = 5
Ingrese la Longitud del brazo 3 = 4
Ingrese la Longitud del brazo 4 = 6
El mecanismo tendra velocidad angular constante?
Si(1)
No(2)
Opcion:1
Ingrese la velocidad angular(w)=2

You might also like