2/6/07

7.5 滑塊四連桿上之點軌跡

滑塊連桿之軌跡


與四連桿之分析相同,在任何桿之延伸點上之位移、速度及加速度等亦可利用sldlink()、body()、fb_sld_linits()及drawlinks()等函數進行分析。利用drawsldpaths()函數則可達到整合的目的。其呼叫之方式如下:

drawsldpaths(r6,th6,r,th1,theta,td2,tdd2,sigma,npts,driver,mode)

輸入參數
  • r : 四連桿之長度,一列向量表示。
  • th1: 第一桿的水平角度(通常為零)。
  • th2: 驅動桿或聯結桿的水平角度。
  • td2, tdd2:驅動桿之角速度及角加速度。
  • Sigma:連桿之組合模式選擇(需為+1或-1)
  • Driver:驅動桿之設定( 0 表示苗桿驅動,1 表示由聯結桿驅動,3滑塊驅動)。
  • Npts: 設定分割的點數或位置。
  • r6,rh6,nlink:桿上特定點之位置,包括桿長,與桿之夾角及附於何桿。
  • Mode:mode=0,畫簡單位置圖;=1 畫所有圖表;=2畫所有圖表,但用簡單位置圖。

程式內容

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;

執行例


(1)桿1驅動


>> drawsldpaths(2,30,[3 4 3 6],0,10,10,1,50,0,2)
Qstart =
48.59
Qstop =
131.41




(2)桿2驅動


>> drawsldpaths(2,30,[3 8 3 6],0,10,10,1,50,1,0)
Qstart =
-41.81
Qstop =
221.81




(2)滑塊驅動



>> drawsldpaths(2,30,[3 8 3 6],0,10,10,1,50,2,0)
Qstart =
-9.2195
Qstop =
9.2195


滑塊連桿之動畫


move_sldpaths函式參數



move_sldpaths(r,r6,th6,nlink,th1,td2,tdd2,sigma,driver,ntimes,npts)

輸入參數:
r : 四連桿之長度,一列向量表示。
th1: 第一桿的水平角度(通常為零)。
th2: 驅動桿或聯結桿的水平角度。
td2, tdd2:驅動桿之角速度及角加速度。
Sigma:連桿之組合模式選擇(需為+1或-1)
Driver:驅動桿之設定( 0 表示苗桿驅動,1 表示由聯結桿驅動,3滑塊驅動)。
Npts: 設定分割的點數或位置。
r6,rh6,nlink:桿上特定點之位置,包括桿長,與桿之夾角及附於何桿。

move_sldpaths程式內容




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;
%%%%%%%%%%%%%%%%%%%%%


執行結果