2007年6月1日 星期五

機動學作業十一

作業十一 B94611034 張延瑋

1.我有上本週(5/24)的機動學課程
2.參考老師提供的parabol_cam
編寫出一函式test 可做出
位移,速度,加速度-角度關係圖

程式如下:
function test
% 計算返程對應點之資料:位移,速度及加速度
theta=0:10:100;
for i=1:length(theta)%共11項
ss(i)=0
vv(i)=0
aa(i)=0
end;
%(theta:對應角度; ss:位移, vv:速度, aa:加速度)
theta=0:10:200;
for i=11:[length(theta)] %共11
[ss(i),vv(i),aa(i)]=parabol_cam(theta(i),100,100,1,5,0);
end;
%(theta:對應角度; ss:位移, vv:速度, aa:加速度)
theta=0:10:260;
for i=22:[length(theta)] %共6項
ss(i)=5
vv(i)=0
aa(i)=0
end;
%(theta:對應角度; ss:位移, vv:速度, aa:加速度)
theta=0:10:360;
for i=27:[length(theta)] %共11項
[ss(i), vv(i), aa(i)]=parabol_cam(theta(i),260,100,-1,5,0);
end;
%(theta:對應角度; ss:位移, vv:速度, aa:加速度)
[theta' ss' vv' aa'] %列出來
axis([0 360 -40 20]); %固定座標軸
plot(theta,ss,' b-','LineWidth',3.5) %繪出角度與位移之關係圖(藍色)
hold on;
plot(theta,vv,'r:','LineWidth',2.5) %繪出角度與速度之關係圖(紅色)
hold on;
plot(theta,aa,'g+','LineWidth',1.5) %繪出角度與加速度之關係圖(綠色)
hold on;
axis([0 360 -40 20]);
title('B94611034位移,速度,加速度-角度');

function createlegend(axes1)
legend1 = legend(axes1,{'位移','速度','加速度'},'Position',[0.1312 0.1091 0.1607 0.1444]);

3.
使用程式pincam 可做出如下的圖
其將運動的型式分成5種 可以不同代號輸入二元素之列矩陣
而升程及返程之範圍,以三元素列矩陣表示
凸輪半徑為15公分,順時針方向旋轉,梢型從動件梢型,垂直接觸,長為10公分
參照第二題的運動形式
輸入[x y]=pincam([0:10:360],15,5,0,10,[100 200 260],[2 2],-1)
可得 凸輪之工作曲線

4.
將程式pincam 最後部份
加入rotate
顏色部分以三原色做調配
編改後程式如下
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;
for i=1:length(cth)
t=th(i)*cw;
A=[cos(t) -sin(t);sin(t) cos(t)]; %此為A點座標(s0,e)
s0=sqrt(r0*r0-e*e); %從動中心線與偏置圓之切點至A點之距離為s0
[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',[0.5 0.3 0]) %梢型從動件垂直於工作曲線(棕色)
end
hold on;
ok=plot([0 x],[0 y],'ro',x,y,'color',[0.4 1 0.5]) %將各點連接在一起而成工作曲線(綠色)
axis equal
for n=1:360 %分成360等份旋轉
rotate(ok,[0 0 1],-1,[0 0 0]) %ok為物件工作曲線
pause(0.0034)
end;
如此一來 就能跑出凸輪迴轉動畫