How to perform an animation of a 5bar parallel link (this is a 2D plot of a 5 bar link) in matlab?
44 次查看(过去 30 天)
显示 更早的评论
Hi there,
I am new to Matlab, but have been trying to work a code out such that it produces a 5 bar parallel link as seen in the image below. I am able to plot it based on values of theta1 and theta5. So by changing these 2 theta values, I get a different plot as seen in the 2nd image.
However, I am tryong to animate the plot such that the whole figure moves over a series of theta values. I have been trying it out, but I am unable to get the code working. May I know if anayone is able to help me out with the code for animation?
Thank you.
% Five bar link centre of mass calculation
%Sanjeev Code%
%%Input the values of the length of the links%%
l0 = input ('What is the value of l0?');
l1 = input ('What is the value of l1?');
l2 = input ('What is the value of l2?');
l3 = input ('What is the value of l3?');
l4 = input ('What is the value of l4?'); % link lengths
% Base joint positions
P5 = [0;0];
P1 = [l0;0];
%%Input the values of theta%%
Theta1 = 70;
Theta5 = 140;
%%Let theta be q%%
q1 = Theta1;
q5 = Theta5;
% Positions of P2 and P4 via trignometry
P4 = P5+l4*[cosd(q5);sind(q5)];
P2 = P1+l1*[cosd(q1);sind(q1)];
d24 = norm(P4-P2); % Distance between P2 and P4
% Bilateration method to find P3
A_243 = -sqrt((d24^2+l2^2+l3^2)^2-2*(d24^4+l2^4+l3^4))/4; % Signed area of triangle formed by P2,P4, and P3
Z_243 = (1/(2*d24^2))*[(d24^2+l2^2-l3^2), -4*A_243; 4*A_243, (d24^2+l2^2-l3^2)]; % Bilateration matrix for this triangle
p24 = P4-P2;
p23 = Z_243*p24;
P3 = P2 + p23;
% Centre of mass calculations
%%Input the values of s of the links%%
s1 = 0.5; s2 = 0.5; s3 = 0.5; s4 = 0.5;
u12 = (P2-P1)/norm(P2-P1);
u23 = (P3-P2)/norm(P3-P2);
u34 = (P4-P3)/norm(P4-P3);
u45 = (P5-P4)/norm(P5-P4); % Unit vectors of links
% mass centres for each link
M1 = P1 + s1*u12;
M2 = P2 + s2*u23;
M3 = P3 + s3*u34;
M4 = P4 + s4*u45;
%m(1,2,3,4) is the masses of the moving links%
m1 = input ('What is the value of m1 (kg)?');
m2 = input ('What is the value of m2 (kg)?');
m3 = input ('What is the value of m3 (kg)?');
m4 = input ('What is the value of m4 (kg)?');
M_tot = m1 + m2 + m3 + m4; % Total mass of linkage
% Centre of mass of linkage
com = (m1*M1+m2*M2+m3*M3+m4*M4)/M_tot;
%Plot links%
%Link P1 and P2 x,y cordinates%
axis([-2 2 -2 2])
x = [P1(1), P2(1)];
y = [P1(2), P2(2)];
plot(x,y, "k-s", "MarkerFaceColor","b","MarkerSize",12);
hold on
% Link P2 and P3 x,y cordinates%
axis([-2 2 -2 2])
x2 = [P2(1), P3(1)];
y2 = [P2(2), P3(2)];
plot(x2,y2, "k-s", "MarkerFaceColor","b","MarkerSize",12);
hold on
% Link P3 and P4 x,y cordinates%
axis([-2 2 -2 2])
x3 = [P3(1), P4(1)];
y3 = [P3(2), P4(2)];
plot(x3,y3, "k-s", "MarkerFaceColor","b","MarkerSize",12);
hold on
%Link P4 and P5 x,y cordinates%
axis([-2 2 -2 2])
x4 = [P4(1), P5(1)];
y4 = [P4(2), P5(2)];
plot(x4,y4, "k-s", "MarkerFaceColor","b","MarkerSize",12);
hold on
%Plot the position of com%
plot(com(1), com(2), 'r*');
hold on
%Plot the centre of links%
plot(M1(1), M1(2), "o", "MarkerFaceColor","black","MarkerSize",9);
plot(M2(1), M2(2), "o", "MarkerFaceColor","black","MarkerSize",9);
plot(M3(1), M3(2), "o", "MarkerFaceColor","black","MarkerSize",9);
plot(M4(1), M4(2), "o", "MarkerFaceColor","black","MarkerSize",9);
set(gca,'YDir', 'reverse')
2 个评论
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!