软件没有学过,学校临时的任务,问题真的不会解决,百度、bilibili都查过都搞清楚,
%1已知数据
clear;
l1=0.10;
l2=0.25;
l3=0.17;
l4=0.30;
l5=0.09;
omega1=10;
alpha1=0;
hd=pi/180;
du=180/pi;
%2调用子函数five_bar计算构建角加速度,加速度,滑块位移
for n1=1:361
theta1(n1)=n1*hd;
ll=[l1,l2,l3,l4,l5];
[theta(n1),omega(n1),alpha(n1)]=five_bar(theta1(n1),omega1,alpha1,ll);
end
%3位移,速度加速度和曲柄滑块机构图形输出
figure(1);
n1=1:361;
subplot(2,2,1);%绘制位移线图
[X,H1,H2]=plotyy(theta1*du,theta2*du,theta3*du,theta1*du,s2);
set(get(AX(1),'ylabel'),'string','连杆角位移/\circ')
set(get(AX(2),'ylabel'),'string','滑块位移/mm')
title('位移线图');
xlabel('曲柄转角\theta_1/\circ')
grid on;
hold on;
subplot(2,2,2);%绘制位移线图
[AX,H1,H2]=plotyy(theta1*du,omega4,theta1*du,v5);
title('速度线图');
xlabel('曲柄转角\theta_1/\circ')
ylabel('连杆角速度/rad\cdots^{-1}')
grid on;
subplot(2,2,3);%绘制加速度线图
[AX,H1,H2]=plotyy(theta1*du,alpha4,theta1*du,a5);%a5为构件5的加速度
title('速度线图');
xlabel('曲柄转角、theta_1/\circ')
ylabel('连杆角加速度/rad\cdots^{-2}')
set(get(AX(2),'ylabel'),'string','滑块加速度/mm\cdots^{-2}')
grid on;
subplot(2,2,4);%绘制曲柄滑块机构图
x(1)=l2;
y(1)=0;
x(2)=l1*cos(theta1*hd);
y(2)=l1*sin(theta1*hd);
x(3)=0;
y(3)=0;
x(4)=x(2)+l3*cos(theta2);
y(4)=y(2)+l3*sin(theta2);
x(5)=l5;
y(5)=s2;
x(6)=x(5)-10;
y(6)=y(5)-40;
x(7)=x(5)-10;
y(7)=y(5)+40;
x(8)=x(5)+10;
y(8)=y(5)-40;
x(9)=x(5)+10;
y(9)=y(5)+40;
x(10)=x(3)+40;
y(10)=y(3)+10;
x(11)=x(3)+40;
y(11)=y(3)-10;
x(12)=x(3)-40;
y(12)=y(3)+10;
x(13)=x(3)-40;
y(13)=y(3)-10;
plot(x,y);
grid on;
hold on;
xlabel('mm')
ylabel('mm')
axis([-50 400 -20 130]);
plot(x(1),y(1),'o');
plot(x(2),y(2),'o');
plot(x(3),y(3),'o');
plot(x(4),y(4),'o');
plot(x(5),y(5),'o');
%4曲柄滑块机构运动仿真
figure(2)
for n1=1:5:360
j=j+1;
clf;
x(1)=l2;
y(1)=0;
x(2)=l1*cos(theta1*hd);
y(2)=l1*sin(theta1*hd);
x(3)=0;
y(3)=0;
x(4)=x(2)+l3*cos(theta2);
y(4)=y(2)+l3*sin(theta2);
x(5)=l5;
y(5)=s2;
x(6)=x(5)-10;
y(6)=y(5)-40;
x(7)=x(5)-10;
y(7)=y(5)+40;
x(8)=x(5)+10;
y(8)=y(5)-40;
x(9)=x(5)+10;
y(9)=y(5)+40;
x(10)=x(3)+40;
y(10)=y(3)+10;
x(11)=x(3)+40;
y(11)=y(3)-10;
x(12)=x(3)-40;
y(12)=y(3)+10;
x(13)=x(3)-40;
y(13)=y(3)-10;
plot(x,y);
grid on;
hold on;
plot(x(1),y(1),'o');
plot(x(2),y(2),'o');
plot(x(3),y(3),'o');
plot(x(4),y(4),'o');
plot(x(5),y(5),'o');
axis([-150 450 -150 150]);
xlabel('mm');
ylabel('mm');
m(j)=getframe;
end
movie(m)
fuction [theta,omega,alpha]=five_bar(theta1,omega1,alpha1,ll];
%位移计算
theta2=arctan(l1*sin(theta1)/(l2+l1*cos(theta1)));
s1=sqrt(l1*sin(theta1)*l1*sin(theta1)+(l2+l1*cos(theta1))*(l2+l1*cos(theta1)));
theta3=(arccos(l1*cos(theta1)+l3*cos(theta2)+l5)/l4);
s2=l4*sin(theta3)-l1*sin(theta1)-l3*sin(theta2);
%速度计算
A=[-s1*sin(theta2),0,0,0;-s1*cos(theta2),0,0,0;-l3*cos(theta2),l4*cos(theta3),-1,0;l3*sin(theta2),l4*cos(theta3),0,0];
B=[l1*sin(theta1);l1*cos(theta1);l1*cos(theta1);-l1*sin(theta1)];
omega=A/(omega1*B);
omega2=omega(1);
omega4=omega(2);
vE=omega(3);
%加速度计算
At=[-s1*sin(theta2),0,0,0;-s1*cos(theta2),0,0,0;-l3*cos(theta2),l4*cos(theta3),-1,0;l3*sin(theta2),l4*cos(theta3),0,0];
Bt=[-s1*omega2*cos(theta2),0,0,0;s1*omega2*sin(theta2),0,0,0;l3*omega2*sin(theta2),l4*omega4*sin(theta3),0,0;l3*omega2*cos(theta2),-l4*omega4*sin(theta3),0,0];
Ct=[omega1*l1*cos(theta1);-omega1*l1*sin(theta1);-omega1*l1*sin(theta1);-omega1*l1*sin(theta1)];
alpha=(omega1*Ct-omega*Bt)/At;
alpha2=alpha(1);
alpha4=alpha(2);
aE=alpha(3);