0% found this document useful (0 votes)
359 views

Matlab Script of Four Bar Linkage - Google Drive

This Matlab script simulates the motion of a four bar linkage mechanism. It defines the key link lengths and angles as input variables, then uses a loop equation to calculate the position of the joints throughout a full rotation of the crank. The script plots the changing positions of the four joints to animate the motion of the four bar linkage. It allows the user to input different parameter values to see how it affects the mechanism's movement.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
359 views

Matlab Script of Four Bar Linkage - Google Drive

This Matlab script simulates the motion of a four bar linkage mechanism. It defines the key link lengths and angles as input variables, then uses a loop equation to calculate the position of the joints throughout a full rotation of the crank. The script plots the changing positions of the four joints to animate the motion of the four bar linkage. It allows the user to input different parameter values to see how it affects the mechanism's movement.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Matlab Script of Four bar Linkage - Google Drive

1 of 3

https://docs.google.com/document/d/1ZFmXAc6Hi0tYBXEVoOBlBSb...

Picture copy from Kenneth J. Waldron, Gary L. Kinzel; Kinematics, Dynamics, and Design of
Machinery 2nd edition
Below is my Matlab Script:
%give initial value
clear all
r1 = input('Input Frame Length [73]:');
if isempty(r1); r1 = 73; end %the default value is 73
r2 = input('Input Crank Length [16]:');
if isempty(r2); r2 = 16; end
r3 = input('Input Coupler Length [60]:');
if isempty(r3); r3 = 60; end
r4 = input('Input Rocker Length [58]:');
if isempty(r4); r4 = 58; end
theta1 = input('Input Frame Angle(deg.) [35]:');
if isempty(theta1); theta1 = 35 ; end
beta = input('Input Beta Angle [0]:');
if isempty(beta); beta = 0; end
r6 = input('Input Coupler Radius [18]');
if isempty(r6); r6= 18; end
a1=0:-1:-360; % the angle of rotation of Crank
theta2=(a1);
n=361; % the numble of frame of Four bar animation
rm = r2; rj = r3;
thetam = theta2;
%calculate Loop Equation for four bar
A = 2*r1*r4*cos(theta1*(pi/180))-2*rm*r4*cos(thetam.*(pi/180));
B = 2*r1*r4*sin(theta1*(pi/180))-2*rm*r4*sin(thetam.*(pi/180));
C =
(r1^2)+(rm^2)+(r4^2)-(rj^2)-2*r1*rm*(cos(theta1*(pi/180))*cos(thetam.*(pi/180)

9/25/2013 15:48

Matlab Script of Four bar Linkage - Google Drive

2 of 3

https://docs.google.com/document/d/1ZFmXAc6Hi0tYBXEVoOBlBSb...

)+sin(theta1*(pi/180))*sin(thetam.*(pi/180)));
det = sqrt((B.^2)+(A.^2)-(C.^2)); %the discriminant of Loop equation
if det > 0
fprintf('Two distinct real roots, checking which one is you want . \n');
theta41 = 2* atan2((-B+det),(C-A))*(180/pi);
theta42 = 2* atan2((-B-det),(C-A))*(180/pi);
thetaj1 =
atan2((r1*sin(theta1*(pi/180))+r4*sin(theta41*(pi/180))-rm*sin(thetam.*(pi/180
))),...
(r1*cos(theta1*(pi/180))+r4*cos(theta41*(pi/180))-rm*cos(thetam.*(pi/180))));
thetaj2 =
atan2((r1*sin(theta1*(pi/180))+r4*sin(theta42*(pi/180))-rm*sin(thetam.*(pi/180
))),...
(r1*cos(theta1*(pi/180))+r4*cos(theta42*(pi/180))-rm*cos(thetam.*(pi/180))));
theta31 = thetaj1*(180/pi);
theta32 = thetaj2*(180/pi);
elseif det == 0
fprintf('One real root.');
theta4 = 2* atan2((-B),(C-A))*(180/pi);
thetaj =
atan2((r1*sin(theta1*(pi/180))+r4*sin(theta4*(pi/180))-rm*sin(thetam.*(pi/180)
)),...
(r1*cos(theta1*(pi/180))+r4*cos(theta4*(pi/180))-rm*cos(thetam.*(pi/180))));
theta3 = thetaj*(180/pi);
else
fprintf('No real root, the input data can not make a four bar.\n');
break
end
%showing the four bar by calculating the position of four joints
for i = 1:3
for i = 1:n
JAx = r2*cos(theta2(i)*(pi/180)); JAy = r2*sin(theta2(i)*(pi/180));
JBx = r1*cos(theta1*(pi/180))+r4*cos(theta41(i)*(pi/180)); JBy =
r1*sin(theta1*(pi/180))+r4*sin(theta41(i)*(pi/180));
JCx = r1*cos(theta1*(pi/180)); JCy = r1*sin(theta1*(pi/180));
JOx = 0; JOy = 0;

9/25/2013 15:48

Matlab Script of Four bar Linkage - Google Drive

3 of 3

https://docs.google.com/document/d/1ZFmXAc6Hi0tYBXEVoOBlBSb...

x = [JOx JAx JBx JCx]; y = [JOy JAy JBy JCy];

h = plot(x,y, 'erasemode', 'normal');


axis([-20,80,-20,60]);
%title('four-bar linkage')
set(h, 'xdata',x,'ydata',y);
set(h,'linewidth',2)
drawnow
end
end

9/25/2013 15:48

You might also like