FINAL INDEPENDENT PROJECT
SYNTHESIS OF A 4-BAR MECHANISM
1)AIM: Aim of this project is to write a MATLAB code for synthesizing the motion of a four-bar Mechanism for a user given function.
2)ABSTRACT:
- Mechanisms are means of power transmission as well as motion transformers. A fourbar mechanism consists mainly of four planar links connected with four revolute joints. The input is usually given as rotary motion of a link and output can be obtained from the motion of another link or a coupler point. Straight line motion from a four bar linkages has been used in several ways as in a dwell mechanism and as a linkage to vehicle suspension.
This project studies the straight line motion obtained from planar four bar mechanism and optimizes the design to produce the maximized straight line portion of the linkages .The precision points for four-bar mechanisms will be obtaines and dimensional requirements for these mechanisms will be obtained in order to produce the required motion. A numerical procedure will be studied and computer codes that generate the mechanism will be presented. Following the numerical results study, a synthesis procedure will be given to help a designer in selecting the optimized straight line motion based on design criteria.
OBJECTIVES:
- The Main aim this project is to design a four bar mechanism to generate the user defined function, y = f (x). ( output link (y) moves as a function of input link (x) )
- Obtain the precision points on the function where there are zero error, using chebyshev spacing equation
- The linear relationship between the points and corresponding angles is obtained by angle relationships for function generation
- Calculate the lengths of the linkages by using the concept of dimensional Synthesis, using Freudenstiens equations
- Calculate the Structural error between the generated function and required function
- Visualize the movement four-bar mechanism for different values if theta and phi within given range, as shown in the figure below:
Fig1. Four Bar synthesis at verious positions
4)PROBLEM STATEMENT:
In this project the precision points ( the points at much the generated function and the required functions agree) are shown, hence it is impossible to produce function y=f(x) at more than a few points, and hence zero per cent error is only possible at these points. Also visualize the motion of the mechanism for various positions with the given range of input angles.
5)GOVERNING EQUATIONS:
5.1)Freudenstien's Equation:
`x_j = 1/2(x_f + x_s) - 1/2(x_f-x_s) cos[(pi(2j-1))/(2n)]`
`x_j` = Precision positions, j = 1,2,3...n
`x_s` = Starting position
`x_f`= Finishing positions
n = number of precision position
5.2)Angle Realtionship for Function Generation:
`(theta_f-theta_s)/(x_f-x_s) = (triangletheta)/(trianglephi)`
`theta_f` = Starting angle of input link
`theta_s` = ending angle of input link
`(phi_f - phi_s)/(y_f - y_s) = ((trianglephi)/(triangley))`
`phi_f` = Starting angle of output link
`phi_s` = ending angle of output link
Freudenstien's Equation:
`K1cos(phi) - K2cos(theta) + K3 = cos(theta-phi)`
K1 = d/a;
K2 = d/c;
`K3 = (a^2-b^2+c^2+d^2)/(2ac)`
a = length of input link;
b = length of coupler link;
c = length of output link;
d = length of grounded link;
6)THEORY AND EXPLAINATION:
- The synthesis is the opposite of analysis. The synthesis of mechanism is the design or creation of a mechanism to produce a desired output motion for a given input motion. In other words, the synthesis of mechanism deals with the determination of proportions of a mechanism for the given input and output motion.
In the application of synthesis, to the design of a mechanism, the problem divides itself into the following three parts:
- Type synthesis, i.e. the type of mechanism to be used.
- Number synthesis, i.e. the number of links and the number of joints needed to produce the required motion.
- Dimensional synthesis, i.e. the proportions or lengths of the links necessary to satisfy the required motion characteristics.
- In designing a mechanism, one factor that must be kept in mind is that of the accuracy required of the mechanism. Sometimes, it is possible to design a mechanism that will theoretically generate a given motion.
- The difference between the desired motion and the actual motion produced is known as structural error. In addition to this, there are errors due to manufacture. The error resulting from tolerances in the length of links and bearing clearances is known as mechanical error.
Class of Function used:
6.1)Function generation: The major classification of the synthesis problems that arises in the design of links in a mechanism is a function generation. In designing a mechanism, the frequent
requirement is that the output link should either rotate, oscillate or reciprocate according to a specified function of time or function of the motion of input link. This is known as function generation. A simple example is that of designing a four bar mechanism to generate the function y = f (x). In this case, x represents the motion of the input link and the mechanism is to be designed so that the motion of the output link approximates the function y.
METHODOLOGY USED:
Flowchart for function generator synthesis:
Fig2. This the the flowchart of the Algorithm implemented
- In designing a mechanism to generate a particular function, it is usually impossible toaccurately produce the function at more than a few points. The points at which the generated and desired functions agree are known as precision points or accuracy points and must be located so as to minimise the error generated between these points.
Fig3. Function Generation of four bar synthesis
- The best spacing of the precision points, for the first trial, is called Chebychev spacing.
- You will be free to select both starting angles theta_s and phi_s . You will find that many starting angle selections will resulting awkward values for links. It will be very valuable to be able to quickly compute the lengths , that's the reason for writing a MATLAB program to obtain the solution.
- The linear relationship between the points and corresponding angles is obtained by angle relationships for function generation
Fig4. Function generation for angle relationship and the liner relationship between the same
8)MATLAB IN-BUILT FUNCTIONS USED:
- Feval :- Execute the specified function.
feval(F,x1,...,xn) evaluates the function specified by a function handle or function name, F, at the given arguments, (x1,...,xn). - SYMS: - Short-cut for constructing symbolic variables
- Integral :- Calculates the area under a curve for given functions within specified bounds
- solve :- Helps us to solve non-linear simultaneous equations
- trapz :- Uses trapazoudal rule to calculate area under a given values os x and y
9)CODE AND ITS EXPLAINATION:
9.1)Function code: This code returns the value of the length of the links of the given mechanism
function [a,c,b,K1,K2,K3] = synt_fun(d,phi,theta)
% using the freudenstiend's equation
% K1.cos(phi)-K2.cos(theta)+K3 = cos(theta-phi)
for i = 1:length(theta)
syms k1 k2 k3 % to consider variables
eqn(i) = k1*cosd(phi(i)) - k2* cosd(theta(i)) + k3 == cosd(theta(i)-phi(i));
end
%% solving the 3 simultanious equations
sol = solve([eqn(1), eqn(2), eqn(3)], [k1, k2, k3]);
K1 = sol.k1;
K2 = sol.k2;
K3 = sol.k3;
%% obtaining the lengths of linkages
% k1 = d/a , k2 = d/c and
% k3 = (a^2+c^2-b^2+d^2)/2.a.c
a = d/K1;
c = d/K2;
b = power((d^2+a^2+c^2)-(2*K3*a*c),0.5);
This returns the values of lengths of the link using freudenstiens equation, by solving three simultaneous equations, which is invoked the below main code
9.2)Main CODE: This code performs the rest of the functions to get the objectives
%% Synthesis of Mechanism
clear all;
close all;
clc
%% required inputs
n = input('Enter the number of precision points: ');
fprintf('\nSpecify the range of the function\n');
x_s = input('Enter the starting point/angle(in deg): ');
x_f = input('Enter the finishing point/angle(in deg): ');
fprintf('the specified range is %d < x < %d\n',x_s,x_f);
fprintf('\n Enter the range of angle for input link \n');
theta_s = input('Starting angle: ');
theta_f = input('Ending angle: ');
d_theta = theta_f - theta_s;
fprintf('\n Enter the range of angle for output link \n');
phi_s = input('Starting angle: ');
phi_f = input('Ending angle: ');
d_phi = phi_f - phi_s;
%% calculating precision points by chebyshev spacing
for j = 1:n
x(j)= 1/2*(x_f+x_s) - 1/2*(x_f-x_s)*cos(pi*(2*j-1)/(2*n));
end
%% calculating value of y from given values of function
yfun = @(x) 5*sind(x) ; %y = f(x)
for i = 1:length(x)
y_s = feval(yfun,x_s);
y(i) = feval(yfun,x(i));
y_f = feval(yfun,x_f);
end
%% displaying all the precision points obtained
disp('The precision points are:-')
for k = 1:length(y)
fprintf('(%f, %f)\n',x(k), y(k));
end
%% calculate angle relationship for function generation
% (theta_f-theta_s)/(x_f-x_s) = d_theta/d_x
d_x = x_f - x_s; %Delta(x)
d_y = y_f - y_s; % Delta(y)
for range = 1:n
theta(range) = theta_s + (d_theta/d_x) * (x(range)- x_s);
phi(range) = phi_s + (d_phi/d_y) * (y(range)- y_s);
end
%% Calculating the lengths of links
% calling the freudinstien function
% a = input link, b = coupler link
% c = output link, d = fixed link
d = 1;
[a, c, b,K1, K2, K3] = synt_fun(d,phi,theta);
a = abs(double(a));
c = abs(double(c));
b = abs(double(b));
fprintf('Input link Length: %f units\n',a);
fprintf('Coupler link Length: %f units\n',b);
fprintf('Output link Length: %f units\n',c);
%% plotting the Function generation
figure(1)
hold on
fplot(yfun,[x_s x_f],'k--');
plot(x,y,'r-')
plot(x,y,'b o')
legend('Required Function','Generated Function','Precision points');
title('Generated Function vs Required Function')
xlabel('x')
ylabel('y = f(x)')
%% Structural error
% the difference between the curves is given as
% the area under required function:
I1 = integral(yfun,x(1),x(n));
% the area under Generated function :
I2 = trapz(x,y);
struct_err = abs(I1-I2)/I1 * 100;
disp(['Structural error is ',num2str(struct_err),' %'])
%% Vusalizing the Mechanism
figure(2)
hold on;
% starting position
plot([0 a*cosd(theta_s)],[0 a*sind(theta_s)],'b-','linewidth',3)
plot([d d+c*cosd(phi_s)],[0 c*sind(phi_s)],'r-','linewidth',3)
plot([a*cosd(theta_s) d+c*cosd(phi_s)],[a*sind(theta_s) c*sind(phi_s)],'g-','LineWidth',3);
line([0 d],[0 0],'LineWidth',3,'color','k')
% ending position
plot([0 a*cosd(theta_f)],[0 a*sind(theta_f)],'b-','linewidth',3)
plot([d d+c*cosd(phi_f)],[0 c*sind(phi_f)],'r-','linewidth',3)
plot([a*cosd(theta_f) d+c*cosd(phi_f)],[a*sind(theta_f) c*sind(phi_f)],'g-','LineWidth',3);
line([0 d],[0 0],'LineWidth',3,'color','k')
legend('Input link','output link','coupler link','grounded link')
title('Positions at starting and ending positions')
% for precision positions
figure(3)
hold on;
title('positions at precision points')
for z = 1:n
X1 = a*cosd(theta(z));
Y1 = a*sind(theta(z));
X2 = d+c*cosd(phi(z));
Y2 = c*sind(phi(z));
plot([0 X1],[0 Y1],'b--','linewidth',3)
plot([d X2],[0 Y2],'r--','linewidth',3)
plot([X1 X2],[Y1 Y2],'g--','LineWidth',3);
line([0 d],[0 0],'LineWidth',3,'color','k')
plot([0 d X1 X2],[0 0 Y1 Y2],'ro','MarkerFaceColor','y','MarkerSize',10)
legend('Input link','output link','coupler link','grounded link')
pause(2)
end
%% making the animation of the motion
figure(4)
ct = 1;
for th=0:0.1:4*pi;
AC=sqrt(a^2+d^2-2*a*d*cos(th));
th1=acos((d^2+(AC^2)-a^2)/(2*d*AC));
th2=acos(((AC^2)+b^2-c^2)/(2*AC*b));
th3=(th2-th1);
plot([0 a*cos(th)], [0 a*sin(th)],'r-');hold on;
plot([a*cos(th) a*cos(th)+b*cos(th3)], [a*sin(th) a*sin(th)+b*sin(th3)], 'r-'); hold on;
plot([0 d], [0 0], 'r-');
hold on;
plot([d a*cos(th)+b*cos(th3)], [0 a*sin(th)+b*sin(th3)], 'r-');
hold off;
pause(0.01);
M(ct) = getframe(gcf);
ct = ct + 1;
end
movie(M);
videofile = VideoWriter('Four_bar.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);
10)RESULTS AND DISCUSSIONS:
These were the data taken for checking the compatability and efficiency of the program (numerical approach)
Hence for testing purpose the function taken was y = sin(x)
No of precision points :3
From range of 0 - 90 (degree)
Starting angle for input link: 105 (degree)
Ending angle for input link : 105+120 (degree)
Starting angle for output link: 66 (degree)
Ending angle for output link : 66+ 60 (degree)
Length of grounded link : 52.5 (units)
- 10.1)Hence the precision points are :
At these points the error is zero, hence these are called as precision points.
- 10.2)The lengths of the link :
fig. lengths of input output and coupler links for the given inputs
- 10.3)The plot for Structural error between the required and generated function is:
fig.Structural error is the error between both the curves.
Hence as the number of precision points increases the structural error decreases.
.
10.4) The visual diagram of synthesized four-bar is :
fig. positions of the linkages at starting and the ending points, theta_s, theta_f, phi_s, phi_f
( refer the legends allocated)
10.5)The positions at given precision points are:
fig. position of linkages at number of precision points within the given range, (here 3 points are taken)
HENCE for same problem statement if we take 10 precision points the results are as following :
fig.Hence the accuracy is improved as number of precision points increase
Fig. These are the positions at 5 precision points
Here is the animation of the four-bar mechanism created:
CONCLUSION:
- From these project we could determine the geometrical paramaters of a four-bar mechanism for a required application
- We synthesize the motion for the gievn input function by the user for a given number of precision points.
- We also visualize the motion of the 4-bar at different positions within the user specified range.
- We also caluclate the structural error in the synthesis and look at the ways to minimize it.
REFERENCES:
https://scholarworks.rit.edu/cgi/viewcontent.cgi?article=5662&context=theses
https://www.researchgate.net/publication/277584753_Analysis_and_Synthesis_of_Four_bar_Mechanism
https://demonstrations.wolfram.com/CouplerCurvesOfAFourBarLinkage/
Theory of Machines text book by R-S KHURMI.
- Manvir Singh DadwalThis content is extremely informative. Appreciate the efforts.