NUMERICAL CODE FOR DESIGN OF SPUR GEAR IN MATLAB

Numerical Code for design of spur gear in Matlab.

zp=input('no of teeth on pinion=');
zg=input('no of teeth on gear=');
p=input('enter the value of power transmitted=');
np=input('enter the rpm of pinion=');
cs=input('enter the value of service factor=');
sutp=input('ultimate tensile strength of pinion=');
sutg=input('ultimate tensile strength of gear=');
fs=input('enter the factor of safety=');
yp=0.484-(2.85/zp);
yg=0.484-(2.85/zg);
sigbp=sutp*(1/3);
sigbg=sutg*(1/3);
ng=zp/zg*np;
if (sigbp*yp)<(sigbg*yg)
    n=np;z=zp;sut=sutp;
    sigb=sigbp;
    y=yp;
    disp('Pinion is weak. Designing acc. to pinion');
else
    n=ng;z=zg;sut=sutg;
    sigb=sigbg;
 y=yg;

    disp('Gear is weak. Designing acc. to gear');
end
v=5;
cv=3/(3+v);
Mt=(60000000*p)/(2*pi*n);
m=1;
sb=0;
peffa=0;
while(sb<=peffa)
dg=m*zg;
dp=m*zp;
pt=(2*Mt)/dg;
vact=(pi*dg*ng)/60000;
if (vact>20)
    cv=5.6/(5.6+(vact^0.5));
elseif (vact<10)
    cv=3/(3+vact);
else
    cv=6/(6+vact);
end
peffa=(cs*pt)/cv;
b=10*m;
sb=m*b*sigb*y;
if (sb>peffa)
    disp('module=');
    disp(m);
    disp('design is safe');
else
    m=m+1;
end
end
ha=m;
hf=1.25*m;
c=0.25*m;
th=1.5708*m;
fr=0.4*m;
disp('standard properties of designed gear');
disp('adendum=');
disp(ha);
disp('dedendum=');
disp(hf);
disp('tooth thickness=');
disp(th);
disp('clearance=');
disp(c);
disp('fillet radius=');
disp(fr);
n=z;            %Number of teeth
pd=10/m;            %Diametral pitch
phi_d=input('enter the pressure angle=');   %Pressure angle in degrees .
r_fillet=fr/10;     %Radius of the fillet of a tooth.
%Initializes all matrices.
xp=zeros(10,1);yp=zeros(10,1);
xo=zeros(10,1);yo=zeros(10,1);
xr=zeros(2,1);yr=zeros(2,1);
xro=zeros(5,1);yro=zeros(5,1);
xf=zeros(5,1);yf=zeros(5,1);
theta=zeros(10,1);
f=zeros(2,32);
M=[];c=[];e=[];g=[];h=[];
d=n/pd;             %Pitch diameter
phi=phi_d*pi/180;   %Pressure angle in radians
db=d*cos(phi);      %Diameter of the base circle
do=d+2/pd;          %Diameter of the addendum (outside) circle
tt=pi/(2*pd);       %Tooth thickness at the pitch circle
dr=d-2*1.25/pd; %Diameter of dedendum(root) circle
%Calculates the coordinates of the involute profile.
n1=10;
tp=pi*d/(2*n);
for i=1:n1;
    r=do/2-(do-db)*(i-1)/(2*(n1-1));
    pha=acos(db/(2*r));
    t=2*r*(tp/d+(tan(phi)-phi)-(tan(pha)-pha)); %Tooth tickness at an angle phi
                                                                %Involute equation from Shigley's book.
    theta(i)=t/(2*r);
    %Coordinate transformation from polar coordinates to Cartesian coordinates
   xp(i)=r*sin(theta(i));      
   yp(i)=r*cos(theta(i));
end
xp=xp';yp=yp';
%Calculates the addendum arc.
n2=10;
for i=1:n2;
    theta_o=theta(1)*(i-1)/(n2-1);
    xo(i)=(do/2)*sin(theta_o);
    yo(i)=(do/2)*cos(theta_o);
end
xo=xo';yo=yo';
%Calculates the non-involute portion of the curve which is between the base circle and
% the dedendum circle. In this case, a straight line segment represents the non-involute 
% portion which is parallel to the y axis and connects to the fillet arc .
for i=1:2;
    theta0=asin((xp(1,n1)+r_fillet)/(dr/2));
    %Calculates theta0, the angle between the central line (y-axis) and the line from 
    % the origin to the last point of the involute curve.
    xr(i)=xp(1,10);
    yr(i)=yp(1,10)-(yp(1,10)-r_fillet-(dr/2)*cos(theta0))*i/2;
    %yr(2)=(dr/2)*cos(theta0)+r_fillet
end
xr=xr';yr=yr';
%Calculates the dedendum arc.
n3=5;
for i=1:n3;
   thetar=theta0+(pi/n-theta0)*(i-1)/(n3-1);   
   %(pi/n-theta0) is the angle subtended of the dededem arc.
   xro(i)=dr*sin(thetar)/2; %xro(1) is the beginning point of the arc.
    yro(i)=dr*cos(thetar)/2;
end
xro=xro';yro=yro';
%Calculates the coordinates of the fillet of a tooth.
%Draws one quarter of a circle from the last point of the non-involute part
%  of the curve to the first point of the dedenum arc.
n4=5;
for i=1:n4;
xf(i)=xro(1)-r_fillet*cos((i-1)*pi/(2*n4-2));
   yf(i)=yro(1)+r_fillet*(1-sin((i-1)*pi/(2*n4-2)));    %yf(5)=yro(1)-r_fillet*sin(4*pi/8)
end
xf=xf';yf=yf';
%Appends each piece of curve defined earlier to generate a one-half profile of a tooth.
c=[c,xo,xp,xr,xf,xro];
e=[e,yo,yp,yr,yf,yro];
g=[c',e'];
g=g';                       %One-half tooth profile
%Reflectes the involute curve about y axis to get the whole tooth.
ff=[-1 0;0 1]*g;        %Reflects the first half to generate the second half.
n5=n1+n2+n3+n4+2;
for i=1:n5;             %n4 points =n1(involute)+n2(addendum)+n4(fillet)
                        %           +2(noninvolute)+n3(dedendum)
   f(1,i)=ff(1,n5+1-i); %Reverses the order of the points on the second half so that 
    f(2,i)=ff(2,n5+1-i);    % it is easy to plot when joining the first half.
end
h=[h,f,g];              %The whole tooth profile.
%Rotates and appends one tooth to generate n teeth.
for i=1:n;
    kk=[cos(2*pi*(i-1)/n) sin(2*pi*(i-1)/n);-sin(2*pi*(i-1)/n) cos(2*pi*(i-1)/n)];
                    %Rotation matrix
mm=kk*h;        %Rotates.
    M=[M,mm];   %Appends.
end
M=[M,h(:,1)];   %Add the first point, so the curve returns to the original point.
%Plots involute curve and basic circle
p=zeros(3,2);
x=[-2,2;0,0];  %Defines lines to draw x-axis and y-axis.
circle=[]; invo=[];
%Draws base circle.
for a=2*pi:-0.01:0;
p(1,1)=db*cos(a)/2;
p(2,1)=db*sin(a)/2;
circle=[circle, p(:,1)];
end
a0=2*pi/n+(pi/pd/2+n/pd*(tan(phi)-phi))/d+pi/2;
%Draws the invoulte curve.
for a=a0:-0.01*pi:a0-3*pi/4;
p(1,1)=db*cos(a)/2;         %Starting point of the involute curve.
p(2,1)=db*sin(a)/2;
len=db*(a0-a)/2;                %Arc length
p(1,2)=p(1,1)-len*sin(a);   %End point of the involute curve.
p(2,2)=p(2,1)+len*cos(a);
invo=[invo, p(:,2)];
plot(M(1,:),M(2,:), x(1,:),x(2,:),'k', x(2,:),x(1,:),'k', circle(1,:),circle(2,:), p(1,:),p(2,:),'--', invo(1,:),invo(2,:))
axis('equal');
axis ([-15 15 -15 15]);
drawnow; %Completes pending drawing events and updates the figure window.
end
axis('equal');  



Comments