任务:四杆机构运动仿真及运动分析。
程序源代码:
%执行脚本
clear all
close all
clc
L1=3,L2=0.8,L3=2,L4=2,th1=0;
k=[L1,L2,L3,L4]; %L1为机架杆
th2=[0:1/50:2]*pi
th34=zeros(length(th2),2);
opt=optimset('display','off');
for m=1:length(th2)
th34(m,:)=fsolve(@FourBarPosition,[5,5],opt,t
h2(m),th1,L2,L3,L4,L1);
end
y=L2*sin(th2)+L3*sin(th34(:,1)');
x=L2*cos(th2)+L3*cos(th34(:,1)');
xx=[L2*cos(th2)];
yy=[L2*sin(th2)];
figure (1)
for i=1:length(x)
plot([0,xx(i)],[0,yy(i)],'-o',[x(i);xx(i)],[y(i);yy(i)],'-k
o',[x(i),L4],[y(i),0],'-ko')
axis equal
axis([-L2-1,L2+L4+0.5,-L3,(L2+L3)/2]);
pause (0.03)
end
xlabel('水平位置')
ylabel('竖直位置')
axis equal
th2=[0:1/50:2]*pi
th34=zeros(length(th2),2);
for m=1:length(th2)
th34(m,:)=fsolve(@FourBarPosition,[5,5],opt,t
h2(m),th1,L2,L3,L4,L1);
end
figure(2)
y=sin(th2-th34(:,1)')./sin(th34(:,2)'-th34(:,1)');
plot(180*th2/pi,y)
title('连杆4端部速度')
v=axis;
v(2)=360;
axis(v)
xlabel(' heta_2(degrees)')
ylabel('v_4/v_2')
w2=4;alph2=5;
w3=(L2*w2*sin(th34(:,2)-th2'))./(L3*sin(th34(:,
1)-th34(:,2)));
w4=(L2*w2*sin(th2'-th34(:,2)))./(L4*sin(th34(:,
2)-th34(:,1)));
s32=th34(:,1)-th2';
s34=th34(:,1)-th34(:,2);
alph4=(L2*alph2*sin(s32)-L2*w2^2*cos(s32)+
L4*w4.^2.*cos(s34)...
-L3*w3.^2)./(L4*sin(s34));
figure (3)
plot(180*th2/pi,alph4)
title('连杆4端部加速度')
v=axis;
v(2)=360;
axis(v)
xlabel(' heta_2(degrees)')
ylabel('plha_4')
调用函数代码: