function [Qstart, Qstop]=sld_angle_limits(r,theta1,linkdrive) % %function [Qstart, Qstop]=sld_angle_limits(r,theta1,linkdrive) %Find initital & final angles of driving link for slider % linkdrive= 0 for crank; 1 for coupler as the driver, with % Qstart & Qstop as the limit angles of driving link. % linkdrive=2 for slider as input, with Qstart & Qstop as its % initial & final positions of r1 % Variables % r= linkage row vector (cm) % Examples:[Qst,Qsp]=sld_angle_limits([1 5 3 1],30,0) r1=r(1);r2=r(2);r3=r(3);r4=r(4); g2d=180/pi; switch linkdrive case 0 %crank if r3+r4<r2 & r4>=0 & r3>r4 Qstart=asin((r4-r3)/r2);Qstop=asin((r4+r3)/r2); elseif r3+r4>=r2 & r4>=r3 & r3>=0 Qstart=asin((r4-r3)/r2);Qstop=pi-asin((r4-r3)/r2); elseif r3-r4<=r2 & r4<0 & r3>=-r4 Qstart=asin((r4-r3)/r2);Qstop=asin((r4+r3)/r2); elseif r3-r4>=r2 & r3>=0 & -r4>=r3 Qstart=-pi-asin((r4+r3)/r2);Qstop=asin((r4+r3)/r2); else Qstart=0;Qstop=2*pi; end case 1 %coupler if r2-r4<=r3 & r4>=0 & r2>=r4 Qstart=asin((r4-r2)/r3);Qstop=pi-asin((r4-r2)/r3); elseif r2+r4<r3 & r4>=0 Qstart=asin((r4-r2)/r3);Qstop=asin((r4+r2)/r3); elseif r2+r4<=r3 & r4<=0 & r2+r4>=0 Qstart=-pi-asin((r4+r2)/r3); Qstop=asin((r4+r2)/r3); elseif r2-r4<r3 & r4<=0 Qstart=asin((r4-r2)/r3);Qstop=asin((r4+r2)/r3); else %r2>=(r3+abs(r4)) Qstart=0;Qstop=2*pi; end case 2 %slider displacement Qstart=0;Qstop=0; arg2=(r2+r3)^2-r4^2; if abs(r2-r3)>=r4 arg1=(r2-r3)^2-r4^2; if arg1>0,Qstart=sqrt(arg1);end; Qstop=sqrt(arg2); else if arg2<0, return; end Qstart=sqrt(arg2);Qstop=-sqrt(arg2); end theta1=0;g2d=1; end %case if Qstop<Qstart,TT=Qstart;Qstart=Qstop;Qstop=TT;end adjust=(Qstop-Qstart)*1e-8; Qstart=theta1+(Qstart+adjust)*g2d; Qstop=theta1+(Qstop-adjust)*g2d;
function [coords] = sldbox(length,height,x0,y0,theta) % %function [coords] = sldbox(length,height,x0,y0,theta) % Determines the coordinates of points for the block. % The input: % length,height = length & height of the block % [x0,y0] = coordinates of the central block % theta = rotation angle relative to the horizontal x axis (deg) % The results are returned in the vector "coords". theta=theta*pi/180;dx=abs(length)/2;dy=abs(height)/2; if dy==0, coords=[-dx,0;dx,0]; else coords=[-dx,-dy;+dx,-dy;+dx,+dy;-dx,+dy;-dx,-dy]; end c=cos(theta);s=sin(theta); trsf=[c s;-s c]; coords=coords*trsf; coords(:,1)=coords(:,1)+x0; coords(:,2)=coords(:,2)+y0;
function drawsldlimits(r,th1,sigma,driver) %function drawlmits(r,th1,sigma,driver) %draw the positions of slide-crank links %call sldlink.m funcion %r: row vector for four links % th1: frame angle % sigma: assembly mode % driver: 0 for crank, 1 for coupler,3 for block move % Example: % drawsldlimits([1 2 3 4],10,1,0) % g2d=180/pi; [Qstart, Qstop]=sld_angle_limits(r,th1,driver) if Qstart==0 & Qstop==0, return; end switch driver case 0 %Link 2 as driving link [rr]=drawsldlinks(r,th1,Qstart,sigma,driver); text(real(rr(2,1)/2),imag(rr(2,1)/2),['s1=' num2str(Qstart,'%6.1f')]); [rr]=drawsldlinks(r,th1,Qstop,sigma,driver); text(real(rr(2,1)/2),imag(rr(2,1)/2),['s2=' num2str(Qstop,'%6.1f')]); case 1 %Link 3 as driving link [rr]=drawsldlinks(r,th1,Qstart,sigma,driver); text(real(rr(2,1)+rr(3,1)/2),imag(rr(2,1)+rr(3,1)/2),... ['s1=' num2str(Qstart,'%6.1f')]); [rr]=drawsldlinks(r,th1,Qstop,sigma,driver); text(real(rr(2,1)+rr(3,1)/2),imag(rr(2,1)+rr(3,1)/2),... ['s1=' num2str(Qstop,'%6.1f')]); case 2 %Slide as driving link if abs(r(2)-r(3))<r(4) angx=asin((r(2)+r(3))/r(4))*g2d; tmax=th1+angx; tmin=th1+180-angx; else tmin=th1+asin((r(2)+r(3))/r(4))*g2d; tmax=th1+asin((r(2)-r(3))/r(4))*g2d; end r(1)=Qstart;offr=0.1*Qstart; [rr]=drawsldlinks(r,th1,tmin,sigma,driver); text(real(rr(1,1)/2),imag(rr(1,1)/2)+offr,['r1=' num2str(Qstart,'%6.1f')]); r(1)=Qstop; [rr]=drawsldlinks(r,th1,tmax,sigma,driver); text(real(rr(1,1)/2),imag(rr(1,1)/2)-offr,['r1=' num2str(Qstop,'%6.1f')]); end axis equal grid on
function drawsldpaths(r6,th6,r,th1,td2,tdd2,sigma,npts,driver,mode) % %drawsldpaths(r6,th6,nlink,r,th1,td2,tdd2,sigma,npts,driver,mode) % To draw sets of positions of slider-crank links %Author:D.S.Fon, BIME, NTU. Dated April 11, 2003 %call sldlink.m, drawsldlinks.m, sld_angle_limits.m & body.m % %Inputs: % r: row vector for four links % th1, th2: frame and driving link angle, in degrees % td2,tdd2:angular velocity and acceleration of the driving link. % sigma: assembly mode % driver: 0 for crank, 1 for coupler, 2 for slider % npts: number of points divided % r6,rh6,nlink:additional length and angle for nlink link. % mode=0 simple position graph only. % =1 all 3 graphs. =2 simple graph+velocity graph % =3 all 3 graphs but with simple position graph %Example: % drawsldpaths(2,30,[4 2 3 4],0,10,10,1,50,0,0) % clf; figure(1); warning off; r(abs(r)<eps)=eps; [Qstart, Qstop]=sld_angle_limits(r,th1,driver) npoint=abs(npts); th2=linspace(Qstart,Qstop,npoint); val=zeros(11,npoint); for i=1:npoint, if driver==2, r(1)=th2(i);end [vr b]=sldlink(r,th1,th2(i),td2,tdd2,sigma,driver); [para]=body(r6,th6,vr,3); if mod(i,5)==0¦i==1¦i==npoint, drawsldlinks(r,th1,th2(i),sigma,driver); patch('xdata',real(para(1:3)),'ydata',imag(para(1:3)),... 'facecolor','r','facealpha',0.6,'marker','o');hold on; plot(para(2),'bo');text(real(para(2)),imag(para(2)),' A'); end val(1:3,i)=[vr(1,1)+vr(4,1);vr(2,1);para(2)];%Sq,Sp,Sa switch driver case 0 val(4:7,i)=[abs(vr(1,1));vr(3,2);vr(3,3);vr(3,4)]; case 1 val(4:7,i)=[abs(vr(1,1));vr(2,2);vr(2,3);vr(2,4)]; case 2 val(4:7,i)=[abs(vr(2,2));vr(3,2);vr(2,3);vr(3,3)]; end val(8:11,i)=[vr(1,5);para(4);vr(4,6);para(5);]; %Vs, Va, As, Aa end warning on; plot(val(1,:),'k-','LineWidth',1.5,'linestyle',':');% path of Q plot(val(2,:),'k-','LineWidth',1.5);% path of P plot(val(3,:),'g-','LineWidth',1.5);% path of A axis equal if mode==0, return;end; % th2=th2(3:end-3);val=val(:,3:end-3); title0={'Crank Angle','Coupler Angle','Slider Pos'}; title1={'\Theta3(r) & r1(k)', '\Theta2(r) & r1(k)',... '\Theta2(r) & \Theta3(k)' }; title2={'Vel of A (r) & Slider(k)',... 'Acc of A(r) & Slider(k)' }; title3={'\omega(r) & \alpha(b) of Coupler',... '\omega(r) & \alpha(b) of Crank',... '\omega of Crank(r) & Coupler(b)'}; intitle=title0(driver+1); val(abs(val)>10e+5)=NaN; val(8:11,:)=abs(val(8:11,:)); figure(2); clf; subplot(2,2,1); plot(th2,val(4,:),'k-');%crank angle or r1 hold on;fact=round(max(val(5,:))/max(val(4,:))*10)/10; plot(th2,val(5,:)/fact,'r-');% crank or coupler angle xlabel(intitle);ylabel(title1(driver+1)); grid on % subplot(2,2,2); plot(th2,val(6,:),'r-');%Omega of crank fact=round(max(val(7,:))/max(val(6,:))*10)/10; hold on;plot(th2,val(7,:)/fact,'b-');%Omega of coupler xlabel(intitle);ylabel(title3(driver+1)); grid on; % subplot(2,2,3); plot(th2,val(8,:),'k-');% vel of slider hold on;plot(th2,val(9,:),'r-');% vel of A xlabel(intitle);ylabel(title2(1)); grid on; % subplot(2,2,4); plot(th2,val(10,:),'k-');%Acc of slider hold on;plot(th2,val(11,:),'r-');% Acc of A xlabel(intitle);ylabel(title2(2)); grid on;
function move_sldpaths(r,r6,th6,nlink,th1,td2,tdd2,sigma,driver,ntimes,npts) % % draw_sldpaths(r,r6,th6,nlink,th1,td2,tdd2,sigma,driver,ntimes,npts) % To animate the positions of a slider link % Author: D.S.Fon, BIME, NTU, date: Feb. 14, 2007 % call sldlink.m,drawsldlinks.m,fb_sld_limits.m & body.m % %Inputs: % r: row vector for four links % th1: frame angle % th2: crank angle or couple angle % td2,tdd2:angular velocity and acceleration of the driving link. % sigma: assembly mode % driver: 0 for crank, 1 for coupler, 2 for slider % ntimes: no. of cycles % npts: number of points divided % r6,rh6,nlink:additional length and angle for nlink link. %example: % move_sldpaths([4 2 3 4],2,-30,3,0,10,0,1,0,4,100) % clf; warning off; if nargin<10, ntimes=3;npts=100;end; figure(1); [Qstart, Qstop]=sld_angle_limits(r,th1,driver); npoint=abs(npts); th2=linspace(Qstart,Qstop,npoint); val=zeros(9,npoint); for i=1:npoint, [vr b]=sldlink(r,th1,th2(i),td2,tdd2,sigma,driver); [para]=body(r6,th6,vr,nlink); val(1:3,i)=[vr(1,1);vr(2,1);vr(1,1)+vr(4,1)]; val(4:6,i)=[para(1);para(3);para(2)]; end drawsldlimits(r,th1,sigma,driver); x=real(val);y=imag(val); line(x(5,:),y(5,:),'color','k','linestyle',':'); line(x(4,:),y(4,:),'color','b','linestyle','-.'); line(x(6,:),y(6,:),'color','c','linewidth',3); range=1.2*([min(min(x)) max(max(x)) min(min(y)) max(max(y))]); axis(range);axis image;grid off; h(1)=patch('xdata',[],'ydata',[],'facecolor','r'); h(2)=line(0,0,'linewidth' ,4,'color', 'b');% Crank h(3)=line(0,0,'linewidth' ,4, 'color', 'r');% Rocker h(4)=line(0,0,'linewidth' ,1,'color', 'k','linestyle',':');% rocker h(5)=line(0,0,'linewidth' ,2,'erasemode','xor','color','r');% block h(6)=line(0,0,'linewidth' ,4,'color', 'k');% boxline for i=1:4,set(h(i),'erasemode','xor','marker','o');end boxlen=max(abs(r(2:3))); i=0;s=-1; for m=1:ntimes s=-s;sound(1,2); if abs(Qstop-Qstart-360)<1,i=0;s=1;end; while 1, i=i+s; if i>npoint|i==0,break;end;
%%%%%%%%%%%%%%%%%%%%%% %set(link5, 'xdata',x(5,i), 'ydata',y(5,i))%marker set(h(2),'xdata',[0 x(2,i)],'ydata',[0 y(2,i)]);%crank set(h(3),'xdata',[x(2,i) x(3,i)],'ydata',[y(2,i) y(3,i)]);%coupler set(h(4),'xdata',[x(1,i) x(3,i)],'ydata',[y(1,i) y(3,i)]);%Rocker set(h(1),'xdata',x(4:6,i),'ydata',y(4:6,i)); [coords] = sldbox(.20*boxlen,.15*boxlen,x(3,i),y(3,i),th1); set(h(5),'xdata',coords(:,1), 'ydata',coords(:,2)); [coords] = sldbox(.20*boxlen,0,x(3,i),y(3,i)-0.075*boxlen,th1); set(h(6),'xdata',coords(:,1), 'ydata',coords(:,2)); switch driver case 0 set(h(2),'Color','blue');%crank set(h(3),'Color','red');%coupler case 1 set(h(2),'Color','red');%crank set(h(3),'Color','blue');%coupler case 2 set(h(3),'Color','red');%coupler set(h(2),'Color','red');%crank end
drawnow; %flush the draw buffer % Do meaningless calculation to slow down the linkage pause(0.1); end end % for m loop hold off;warning on; %%%%%%%%%%%%%%%%%%%%%
利用MATLAB程式slider_ solve (),可以計算任意曲柄角度之對應連結桿角度及水平距離,公式4.24與4.25,如程式4.8。其呼叫函數如下: function [d,theta3]=slider_solve(theta2,R,L,e,mode)
其參數之定義詳如程式內容。
程式4.8 function [d,theta3]=slider_solve(theta2,R,L,e,mode) % P4.8 [d,theta3]=slider_solve(theta2,R,L,e) % % Find the block coordinate and angle of connecting rod in a slider-crank system % Input:R,L lengths of crank & connecting rod; e the offset of block % theta2: angles of crank, cane be a matrix % Output: d:distance of the block from the origin. % theta3:angle of the connecting rod, % Examples: % [d,theta3]=slider_solve(45,5,10,3) % % Designed by D.S. Fon, BIME, NTU, Date:Fegruary 9,2003. if nargin<5, mode=0;end d2g=pi/180; theta=theta2*d2g; cc=(e-R.*sin(theta))./L; if mode>=0, theta3=asin(cc); else theta3=asin(-cc)+pi; end d=L.*cos(theta3)+R.*cos(theta); theta3=theta3/d2g;
程式4.7 function [s,theta21,theta22]=slider_limit(R,L,e) % P4.7 [s,th1,th2]=slider_limit(r) % % Find the stroke, extreme angles of link 2 in a slider mechanism system % Input:R,L lengths of crank & connecting rod; e the offset of block % Output: s:stroke, theta21:angle for the right position, % theta22:angle for the left position % Examples: % [s,th1,th2]=slider_limit(5,12,3) % % Designed by D.S. Fon, BIME, NTU, Date:October 17,2002. d2g=pi/180; th1=asin(e./(R+L)); th2=asin(e./abs(R-L)); s=(R+L).*cos(th1)-abs(R-L).*cos(th2); theta21=th1/d2g; theta22=th2/d2g;