2007年4月26日 星期四

作業7

本人(4/19)有上課
7.1
t=[1 2 3 4 5]
X1x(t)=33*cos(0.2*t);
X1y(t)=33*sin(0.2*t);
X2x(t)=33*cos(0.2*t)+38*cos(0.5+0.1*t);
X2y(t)=33*sin(0.2*t)+38*sin(0.5+0.1*t);
X3x(t)=33*cos(0.2*t)+38*cos(0.5+0.1*t)+28*cos(0.3+0.2*t);
X3y(t)=33*sin(0.2*t)+38*sin(0.5+0.1*t)+28*sin(0.3+0.2*t);
for i=1:5
line([0 X1x(i)],[0 X1y(i)]);
line([X1x(i) X2x(i)],[X1y(i) X2y(i)]);
line([X2x(i) X3x(i)],[X2y(i) X3y(i)]);
end
axis([0 100 0 100]);
grid on;
xlabel('x軸');
ylabel('y軸');
圖示:

7.2
t=1:5;
V1x=33*0.2*sin(0.2*t);
V1y=33*0.2*cos(0.2*t);
V2x=33*0.2*sin(0.2*t)+38*(0.5+0.1*t).*sin(0.5+0.1*t);
V2y=33*0.2*cos(0.2*t)+38*(0.5+0.1*t).*cos(0.5+0.1*t);
V3x=33*0.2*sin(0.2*t)+38*(0.5+0.1*t).*sin(0.5+0.1*t)+28*(0.3+0.2*t).*sin(0.3+0.2*t);
V3y=33*0.2*cos(0.2*t)+38*(0.5+0.1*t).*cos(0.5+0.1*t)+28*(0.3+0.2*t).*cos(0.3+0.2*t);
V1=(V1x.^2+V1y.^2).^0.5;
V2=(V2x.^2+V2y.^2).^0.5;
V3=(V3x.^2+V3y.^2).^0.5;
A1=0*t;
A2x=38*0.1*sin(0.5+0.1*t);
A2y=38*0.1*cos(0.5+0.1*t);
A3x=38*0.1*sin(0.5+0.1*t)+28*0.2*sin(0.3+0.2*t);
A3y=38*0.1*cos(0.5+0.1*t)+28*0.2*cos(0.3+0.2*t);
A2=(A2x.^2+A2y.^2).^0.5;
A3=(A3x.^2+A3y.^2).^0.5;
plot3(A1',V1',t');hold on;
plot3(A2',V2',t');hold on;
plot3(A3',V3',t');
axis([-10 50 -10 100 0 6]);
grid on;
xlabel('加速度');
ylabel('速度');
zlabel('時間');
圖示:

7.3
先建立函數
linkxy.m
linkrobot.m

linkxy.m:
function [x,y]=linkxy(A,B,d)
if nargin==2,d=1;end;
d=abs(d);
AB=(B(1)+j*B(2))-(A(1)+j*A(2));
D=abs(AB);th=angle(AB);
t=linspace(pi/2,2.5*pi,20);
Cout=max(d/2,0.2)*exp(j*t');Cin=Cout/2;
if d>0,
P=[0;Cin;Cout(1:10);D+Cout(11:20);D+Cin;D+Cout(20);Cout(1)];
else
P=[Cin;0;D;D+Cin];
end
xx=real(P);yy=imag(P);
x=xx*cos(th)-yy*sin(th)+A(1);
y=xx*sin(th)+yy*cos(th)+A(2);

linkrobot.m:
function link_robot(lens,angle,omega,a)
lens:手臂長
angle:起始角度
omega:角速度,rad/s
a;角加速度
time:[stop delt]
if nargin<4,w=1;end
if nargin<3,omega=1;end;
lens=lens(:);angle=angle(:);omega=omega(:);a=a(:);
if length(omega)==1,
omega=ones(size(lens))*omega;
end
t=0;nn=length(lens);clf;
for i=1:nn,
h(i)=line('xdata',[],'ydata',[],'erasemode','xor');
end
mm=sum(lens)-min(lens);
axis([-mm mm -mm mm]);axis equal;axis off;
title('Hit ctr-C to stop');
while 1
th=cumsum(angle+(omega+a*t)*t)*pi/180;
x=[0;cumsum(lens.*cos(th))];
y=[0;cumsum(lens.*sin(th))];
for i=1:nn
[xi,yi]=linkxy([x(i) y(i)],[x(i+1) y(i+1)],5);
set(h(i),'xdata',xi,'ydata',yi);
end
drawnow;
pause(0.1)
t=t+1;if t>1000,t=0;end
end

再執行
linkrobot([33 38 28],[0 0 0],[0.2 0.4 0.3],[0 0.1 0.2])
*各桿之對應長度=[33 38 28]
*各桿之對應起始角度=[0, 0, 0]
*各桿之對應角速度為=[0.2,0.5,0.3]rad/s
*各桿之對應角加速度為=[0,0.1,0.2]rad/s^2
動畫:

沒有留言: