2007年5月8日 星期二

第八次作業





B94611048 張志鵬本人4月26日曾來上課


題目
有一組四連桿,其桿長分別為r=[4 3 3 5],由桿2驅動設第一固定桿角度theta1=0度角速度 td2=10rad/s角加速度tdd2=0 rad/s^2

問題一 設桿2角度theta2=45度時,求各點之位置、速度與加速度為何?
下面為f4bar()函數之內容可以幫助我們分析四連桿

function [data,form] = f4bar(r,theta1,theta2,td2,tdd2,mode,linkdrive)
%%function [data,form] = f4bar(r,theta1,theta2,td2,tdd2,mode,linkdrive)
% This function analyzes a four-bar linkage when the driving link is
% crank or coupler. The input data are:
% theta1,theta2 are angles in degrees
% r=[r1 r2 r3 r4]= lengths of links(1=frame)
%td2 = crank or coupler angular velocity (rad/sec)%
tdd2 = crank or coupler angular acceleration (rad/sec^2)
%mode = +1 or -1. Identifies assembly mode
%linkdrive = 0 for crank as driver; 1 for coupler as driver
%data (1:4,1) = link positions for 4 links
%data (1:4,2) = link angles in degrees
%data (1:4,3) = link angular velocities
%data (1:4,4) = link angular accelerations
%data (1,5) = velocity of point Q
%data (2,5) = velocity of point P
%data (3,5) = acceleration of point Q
%data (4,5) = acceleration of point P
%data (1,6) = position of Q
%data (2,6) = position of P
%form = assembly status. form = 0, mechanism fails to
% assemble.
% program revised from Waldron's Textbook
% Revised:DSFON, BIME, NTU. Date: Feb. 7, 2007
if nargin<7,linkdrive=0;end mode="1;end" data="zeros(4,6);" linkdrive="=" r="[r(1)" rr="r.*r;d2g=" t1="theta(1);tx=" s1="sin(t1);c1=" sx="sin(tx);cx=" a="2*r(1)*r(4)*c1-2*r(2)*r(4)*cx;" c="rr(1)+rr(2)+rr(4)-rr(3)-2*r(1)*r(2)*(c1*cx+s1*sx);" b="2*r(1)*r(4)*s1-2*r(2)*r(4)*sx;" pos="B*B-C*C+A*A;">=0,
form=1;
% Check for the denominator equal to zero
if abs(C-A)>=1e-5
t4=2*atan((-B+mode*sqrt(pos))/(C-A));
s4=sin(t4);c4=cos(t4);
t3=atan2((r(1)*s1+r(4)*s4-r(2)*sx),(r(1)*c1+r(4)*c4-r(2)*cx));
s3=sin(t3);c3=cos(t3);
else
% If the denominator is zero, compute theta(3) first
A=-2*r(1)*r(3)*c1+2*r(2)*r(3)*cx;
B=-2*r(1)*r(3)*s1+2*r(2)*r(3)*sx;
C=rr(1)+rr(2)+rr(3)-rr(4)-2*r(1)*r(2)*(c1*cx+s1*sx);
pos=B*B-C*C+A*A;
if pos>=0,
t3=2*atan((-B-mode*sqrt(pos))/(C-A));
s3=sin(t3); c3=cos(t3);
t4=atan2((-r(1)*s1+r(3)*s3+r(2)*sx),... (-r(1)*c1+r(3)*c3+r(2)*cx));
s4=sin(t4);c4=cos(t4);
end
end
theta(3)=t3;theta(4)=t4;
%velocity calculation
td(2)=td2;
AM=[-r(3)*s3, r(4)*s4; -r(3)*c3, r(4)*c4];
BM=[r(2)*td(2)*sx;r(2)*td(2)*cx];
CM=AM\BM; td(3)=CM(1);td(4)=CM(2);
%acceleration calculation
tdd(2)=tdd2;
BM=[r(2)*tdd(2)*sx+r(2)*td(2)*td(2)*cx+r(3)*td(3)*td(3)*c3-... r(4)*td(4)*td(4)*c4;r(2)*tdd(2)*cx-r(2)*td(2)*td(2)*sx-... r(3)*td(3)*td(3)*s3+r(4)*td(4)*td(4)*s4];
CM=AM\BM;tdd(3)=CM(1);tdd(4)=CM(2);
%store results in array data
% coordinates of P and Q
if linkdrive==1,
c2=c3;c3=cx;s2=s3;s3=sx;r(2:3)=[r(3) r(2)];theta(2:3)=[theta(3) theta(2)];
td(2:3)=[td(3) td(2)];tdd(2:3)=[tdd(3) tdd(2)];
else
c2=cx;s2=sx;
end
for j=1:4,
data(j,1:4)=[r(j)*exp(i*theta(j)) theta(j)/d2g td(j) tdd(j)] ;
end
% position vectors
data(1,5)=r(2)*td(2)*exp(i*theta(2));%velocity for point Q
data(2,5)=r(4)*td(4)*exp(i*theta(4));%velocity for point P
data(3,5)=r(2)*(i*tdd(2)-td(2)*td(2))*exp(i*theta(2));%acc of Q
data(4,5)=r(4)*(i*tdd(4)-td(4)*td(4))*exp(i*theta(4));%acc of P
data(1,6)=data(2,1);%position of Q, again
data(2,6)=data(1,1)+data(4,1);% position of P
%find the accelerations
else f
orm=0;
if linkdrive==1,
r=[r(1) r(3) r(2) r(4)];
for j=1:4,
data(j,1)=r(j).*exp(i*theta(j));
end % positions
end
end

[val,form]=f4bar([4 3 3 5],0,45,10,0,-1,0)
四連桿之角度為:
第一桿 第二桿 第三桿 第四桿
0 45.0000 69.4856 99.5246
各桿之速度則為:
第一桿 第二桿 第三桿 第四桿
0 10.0000 16.2681 4.9677
各桿之加速度為:
第一桿 第二桿 第三桿 第四桿
0 0 491.4428 383.6120
P點的 位置 速度 加速度
2.1213 + 2.1213i 0.0212 + 0.0212i -0.2121 - 0.2121i
Q點的 位置 速度 加速度
3.1726 + 4.9311i 0.0041 - 0.0245i -1.8712 - 0.4391i

問題二 繪出此四連桿之相關位置及標明各點之速度方向及大小
程式drawlinks之目的即是利用MATLAB繪製四連桿之相關位置。
所以程式本身會呼叫f4bar.m函數以計算四連桿之向量位置,然後加以繪圖。

function [values]=drawlinks(r,th1,th2,mode,linkdrive)
%function drawlinks(r,th1,th2,mode,linkdrive)
%draw the positions of four-bar links
%call f4bar funcion
%r: row vector for four links
%th1: frame angle
%th2: crank angle or couple angle
%mode: assembly mode
%linkdrive: 0 for crank, 1 for coupler
%clf;
if nargin<5,linkdrive=0;end mode="1;end" rr="values(:,1);rr(3,1)=" rx="real(rr(:,1));rx(4)=" ry="imag(rr(:,1));ry(4)=" b="=" linkdrive="=" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs_XAqnlzgujB0onb96zWoaaf3oMVZBRNlALHQ5d_x-tziETX1heySgyYNs2obGpwUqOybYeTqcd5J4jZmHYzXoS2BZTtzOj4Vgo7teXZmLcSJNEM-_9ahABQpdVEyLgkTU-FWQawPIpPu/s1600-h/b94611048-matlabpic-HW8-1-2.jpg">
第三題 當桿2迴轉時,求出此組四連桿之限制角度,並繪出其位置
function [Ang1, Ang2]=fb_angle_limits(r,theta1,linkdrive)
%%function [Ang1, Ang2]=fb_angle_limits(r,theta1,linkdrive)
% Find initital & final angles for the driving link
% linkdrive= (0 for crank; 1 for coupler as the driver).
% Variables:
% r=linkage row vector (cm)
% theta1=frame angle(degree);
% Ang1,Ang2=initial & final angles of the driving link(deg)
%Program
if nargin<3,linkdrive=0;end theta1="0;end" linkdrive="=" r="[r(1)" r1="r(1);r2=" r3="r(3);r4=" rmin="min(r);rmax=" rtotal="sum(r);Ang1=" ang2="2*pi;">(r3+r4)& abs(r1-r2)(r3+r4)& abs(r1-r2)>=abs(r3-r4)
Ang1=acos((r2^2-(r4+r3)^2+r1^2)/(2*r1*r2));
Ang2=-Ang1;
end
% if (r1+r2)<=(r3+r4)&abs(r1-r2)>=abs(r3-r4)
% Ang1=0;
% Ang2=2*pi;
% end
if (r1+r2)<=(r3+r4)&abs(r1-r2)< ang1="acos((r2^2-(r4-r3)^2+r1^2)/(2*r1*r2));" ang2="2*pi-Ang1;" adjst =" (Ang2-Ang1)*1e-8;" ang1="theta1+(Ang1+adjst)*180/pi;" ang2="theta1+(Ang2-adjst)*180/pi;" tt="Ang1;Ang1=" ang2="TT;end" qstart =" 28.9550" qstop =" 331.0450" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKjNMCI-_92A8-6ernZ2tyBvuqmCOXld5LerL2BNJOzwIH8RfxmxOaFppb9oPdO4BXs7md4y6G_-uYLw7GnzfJcKVm3jZmKy6HCMXrbN6_mDLq3S96o1N3MfQ_NJkDJuz2sd3JRvwGIpwI/s1600-h/b94611048-matlabpic-HW8-1-3.jpg">




第四題
設theta2=[0:20:360],試繪出此組四連桿之重疊影像,解釋為何有些沒有值
clf;
for i=0:20:360,
drawlinks([4 3 3 5],0,i,-1,0); end




結果:
Combination of links fail at degrees 0.0
Combination of links fail at degrees 20.0
Combination of links fail at degrees 340.0
Combination of links fail at degrees 360.0

在第三題時 我們求出四連桿之限制角度
從28.955到331.045間才可做旋轉其他角度是不可能發生的



第五題 若將問題三考慮在內,只在可迴轉的範圍內迴轉,請問你能讓此組四連桿作成動畫方式迴轉嗎
下面這程式真的很精彩!!! 可以繪出所有的軌蹪

function move_4paths(r,r6,th6,nlink,th1,td2,tdd2,sigma,driver,ntimes,npts)
%%function move_4paths(r,r6,th6,nlink,th1,td2,tdd2,sigma,driver,ntimes,npts)
%%draw the positions of four-bar links
%call f4bar.m funcion, f4limits.m, fb_angle_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
% ntimes: no. of cycles
% npts: number of points divided
% r6,rh6,nlink:additional length and angle for nlink link.
%example:
% move_4paths([4 2 3 4],2,-30,3,0,10,0,1,0,4,100)
%%clf;
if nargin<10, ntimes="3;npts=" npoint="abs(npts);" th2="linspace(Qstart,Qstop,npoint);" val="zeros(6,npoint);" i="1:npoint," x="real(val);y=" h="f4limits(r,th1,sigma,driver);" range="1.2*([min(min(x))" i="2:4,set(h(i),'erasemode','xor');end" h0="patch('xdata',[],'ydata',[],'erasemode','xor','facecolor','r',..." i="0;s=" m="1:ntimes" s="-s;" i="0;s=" i="i+s;">npointi==0,break;end;
set(h(2),'xdata',[0 x(2,i)], 'ydata',[ (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(h0,'xdata',[x(4:6,i)], 'ydata',[y(4:6,i)]);
drawnow;
%flush the draw buffer
pause(0.1); end
end
% for m loop


move_4paths([4 3 3 5],0,0,3,0,10,0,1,0,4,150)



下面是我的影片

1 則留言:

不留白老人 提到...

輸入參數應多作說明
動畫應先宣告axis equal