2007年5月30日 星期三

機動學第十一次作業

b94611029林軍耀

1.本人本週(5/24)有來上課。

2.
使用程式
function plot_dwell(ctheta,s,pattern,range)
%ctheta = cam angle (deg)--can be a matrix
%pattern = denote the type of motion used(a 3 element-row matrix)
% 1:uniform 2:parabolic 3:simple harmonic 4: cycloidal
% 5:polynomial motion
% example [4 3]%range =the degrees the specific motion starts
% Output: y is for displacement, yy is the derivative of the displacement with
% respect to theta, and yyy the second derivative with respect
% to theta.
% Example plot_dwell(0:10:360,2,[4 3],[90 180 240]);figure(1);
clf;
[y,yy,yyy]=dwell(ctheta,range,pattern);
h1=plot(ctheta,y*s,'b-',ctheta,yy*s,'k-',ctheta,yyy*s,'r-');
legend('Displacement','Velocity','Acceleration',3);
xlabel('Elapsed Angle, degrees');
grid;



因為等加速度的位移軌跡
就是拋物線
所以在pattern中輸入2


返程等速
plot_dwell(0:10:360,5,[2 1],[100 200 260]);


返程等加速度
plot_dwell(0:10:360,5,[2 2],[100 200 260]);


返程簡諧
plot_dwell(0:10:360,5,[2 3],[100 200 260]);


返程擺線
plot_dwell(0:10:360,5,[2 4],[100 200 260]);


返程多項式
plot_dwell(0:10:360,5,[2 5],[100 200 260]);



求出各種返程型態之圖形

其中
1:等速運動uniform 2:抛物線parabolic 3:簡諧simple harmonic
4:擺線cycloidal 5:多項式polynomial motion

使用function [y,yy,yyy]=dwell(ctheta,range,pattern)


function [y,yy,yyy]=dwell(ctheta,range,pattern)
%
% This function determines the follower displacement and derivatives
% for a full rotation cam. The routine is set up for the displacement
% schedule in Examples 6.7 and 6.8% The input values are:
%ctheta = individual cam angles (deg)--can be a matrix to be processed
%pattern = denote the types of motion used(a 2 element-row matrix). types
% are:
% 1:uniform 2:parabolic 3:simple harmonic 4: cycloidal
% 5:polynomial motion% e.g. [4 3]:cycloidal motion for rise and harmonic motion for
% return%range =the degrees the specific motion starts(array of 3 elements), e.g.
% [90 180 240] starts to rise at 90 deg. and ends at 180 deg.
% starts to return at 240 deg. and ends at 360 deg.
% Output: y is for displacement, yy is the derivative of the displacement with
% respect to theta, and yyy the second derivative with respect to theta.
% Example dwell(60,[90 180 240],[4 3]);
% Author:DSFon, BIME, NTU Revise Date:May 18, 2007
d2r=pi/180;
theta=ctheta*d2r;range=range*d2r;
dim=length(ctheta);y=zeros(size(ctheta));
yy=y;yyy=y;
for i=1:dim
if theta(i)>=range(3) %for the last motion(downward)
mode=pattern(2);
betax=2*pi-range(3);
switch mode,
case 1, [y(i),yy(i),yyy(i)]=uniform(theta(i), range(3),betax,-1);
case 2, [y(i),yy(i),yyy(i)]=parabolicm(theta(i), range(3),betax,-1);
case 3, [y(i),yy(i),yyy(i)]=harmonicm(theta(i), range(3),betax,-1);
case 4, [y(i),yy(i),yyy(i)]=cycloidm(theta(i), range(3),betax,-1);
case 5, [y(i),yy(i),yyy(i)]=polynorm(theta(i), range(3),betax,-1);
end;
elseif theta(i)>=range(2) % dewell on the top
y(i)=1;elseif theta(i)>=range(1) % for the 1st motion(upward)
mode=pattern(1);betax=range(2)-range(1);
switch mode,
case 1, [y(i), yy(i), yyy(i)]=uniform(theta(i), range(1),betax,+1);
case 2, [y(i), yy(i), yyy(i)]=parabolicm(theta(i), range(1),betax,+1);
case 3, [y(i), yy(i), yyy(i)]=harmonicm(theta(i), range(1),betax,+1);
case 4, [y(i), yy(i), yyy(i)]=cycloidm(theta(i), range(1),betax,+1);
case 5, [y(i), yy(i), yyy(i)]=polynorm(theta(i), range(1),betax,+1);end
end
end
%*********************************************
function [t1, t2, t3]=uniform(th, thinit,beta,direct)
% code = 1 for uniform motion
%th=cam angle, radians%beta=motion range, radians
%thinit=starting cam angle, radians%beta=motion range, radians
%direct=motion type; +1 for upward, -1 for downward
theta=th-thinit;t1=theta/beta;
if direct==-1,t1=1-t1;end;
t2=direct*1/beta;t3=0;
%*********************************************
function [t1, t2, t3]=parabolicm(th,thinit,beta,direct)
% code = 2 for parabolic motion%th=cam angle, radians
%beta=motion range, radians%thinit=starting cam angle, radians
%beta=motion range, radians%direct=motion type; +1 for upward, -1 for downward
theta=th-thinit;thmed=thinit+beta/2;thx=theta/beta;
if direct==1,
if th<thmed
t1=2*thx^2;
t3=4/beta/beta;
t2=t3*th;
else
t1=1-2*(1-thx)^2;
t2=4/beta*(1-thx);
t3=-4/beta/beta;
end
else
if th t1=1-2*thx^2;
t3=-4/beta/beta;
t2=t3*th;
else
t1=2*(1-thx)^2;
t2=-4/beta*(1-th/beta);
t3=4/beta/beta;
end
end
%*********************************************
function [t1, t2, t3]=harmonicm(th,thinit,beta,direct)
% code = 3 for harmonic motion%th=cam angle, radians
%beta=motion range, radians%thinit=starting cam angle, radians
%beta=motion range, radians%direct=motion type; +1 for upward, -1 for downward
theta=th-thinit;t1=0.5*(1-cos(pi*theta/beta));
if direct==-1, t1=1-t1;end;
t2=direct*(0.5*pi/beta)*sin(pi*theta/beta);
t3=direct*0.5*(pi/beta)^2*cos(pi*theta/beta);
%*********************************************
function [t1, t2, t3]=cycloidm(th,thinit,beta,direct)
%% code = 4 for cycloidal motion%th=cam angle, radians
%thinit=starting cam angle, radians%beta=motion range, radians
%direct=motion type; +1 for upward, -1 for downward
theta=th-thinit;
t1=theta/beta-(0.5/pi)*sin(2*pi*theta/beta);
if direct==-1,t1=1-t1;end;
t2=direct*(1-cos(2*pi*theta/beta));
t3=direct*2*pi/beta/beta*sin(2*pi*theta/beta);
%*********************************************
function [t1, t2, t3]=polynorm(th,thinit,beta,direct)
%% code = 5 for polynormial motion%th=cam angle, radians
%thinit=starting cam angle, radians
%beta=motion range, radians%direct=motion type; +1 for upward, -1 for downward
theta=th-thinit;
thx=theta/beta;t1=thx*thx*thx*(10+thx*(-15+thx*6));
if direct==-1, t1=1-t1;end;
t2=direct*(30/beta)*thx*thx*(1+thx*(-2+thx));
t3=direct*(60/beta/beta)*thx*(1+thx*(-3 +2*thx));


3.

利用[x y]=pincam([0:10:360],15,s,0,10,[100 200 260],[2 1],-1)
以及[s]=drawcam(15,y,1)
作出圖形
與第四小題的動畫一同呈現

4.

利用上面的程式
[s]=drawcam(15,y,1)

再用
for i=1:1:360
x2=s(:,1);
y2=s(:,2);
x3=x2*cosd(i)-y2*sind(i);
y3=x2*sind(i)+y2*cosd(i);
axis([-30 30 -30 30]);
plot(x3,y3);
pause(0.01);
axis([-30 30 -30 30]);
axis equal;
grid on;
end;

作出動畫


附件1
function [x,y]=pincam(cth,r0,s,e,L,range,pattern,cw)
%Find the pin type cam with an offsect e%Inputs:
% cth:angle of cam, degrees% r0:radius of base circle
% e:offset% s:stroke
% L:length of pin
% cw:rotation direction of cam(-counterclockwise,+clockwise
%pattern = denote the type of motion used(a 3 element-row matrix)
% 1:uniform 2:parabolic 3:simple harmonic 4: cycloidal
% 5:polynomial motion% example [4 3]
%range =the degrees the specific motion starts, eg.[90 180 240]
% Example: [x y]=pincam([10 60],5,2,1,10,[90 180 240],[4 3],-1)
figure(1);
clf;
th=cth*pi/180;
s0=sqrt(r0*r0-e*e);
for i=1:length(cth)
t=th(i)*cw;
A=[cos(t) -sin(t);sin(t) cos(t)];
[ym,yy,yyy]=dwell(cth(i),range,pattern);
x0=s0+ym*s;
Sx=[0 x0 x0+L;e e e];
X=A\Sx;
x(i)=X(1,2)
y(i)=X(2,2)
line(X(1,1:2),X(2,1:2));
line(X(1,2:3),X(2,2:3),'linewidth',3,'color','red')
end
hold on;
plot([0 x],[0 y],'ro',x,y,'k-')

附件2
function [rp,rb]=drawcam(r0,y,direct)
% To draw a cam profile with base radius of r0 and rise in y
% The program may work with P8_11% Input: direct: +1 for clockwise; -1 for counterclockwise
%
% Example: [s,T]=drawcam(35,y)
d2r=pi/180;nn=length(y);
LM=max(y+r0);figure(2);
line([-LM LM]',[0 0]');
line([0 0]',[-LM LM]');
if direct==1,
theta=linspace(0,360,nn)'*d2r;
else
theta=linspace(360,0,nn)'*d2r;
end
theta=theta+pi/2;
rb=[r0*cos(theta) r0*sin(theta)];
rp=[(r0+y').*cos(theta) (r0+y').*sin(theta)];
line(rb(:,1),rb(:,2),'color','r');
line(rp(:,1),rp(:,2));
axis equal;
grid on;

1 則留言:

曾智威 提到...

這次作業我發現的時候已經遲交了
所以就...
不過看了你的部落格也讓我學到了很多
很詳盡