平面连杆机构运动分析 - 图文

机械原理大作业 机电学院05011303班

四、计算源程序

4.1主程序 %输入已知数据 clear l1=0.0240; l2=0.1056; l3=0.0675; l4=0.0875; l5=0.0344; l6=0.025; l22=0.065; xg=0.1535; yg=0.0417; omega1=1; alph1=0; hd=pi/180; du=180/pi; t1=1:10:361; theta2=1:10:361; theta3=1:10:361; theta5=1:10:361; theta6=1:10:361; omega2=1:10:361; omega3=1:10:361; omega5=1:10:361; omega6=1:10:361; alph2=1:10:361; alph3=1:10:361; alph5=1:10:361; alph6=1:10:361; xe=1:10:361; ye=1:10:361; V=1:10:361; a=1:10:361; theta1=0;

options=gaoptimset('PopulationSize',100,'Generations',10000,'StallGenLimit',500,'TolFun',1e-100);

theta0=ga(@(thet) weiyi_0(thet,theta1),4,options); if theta0(1)<0

theta0(1)=theta0(1)+2*pi;end

第4页

机械原理大作业 机电学院05011303班 if theta0(1)>2*pi

theta0(1)=theta0(1)-2*pi;end if theta0(2)<0

theta0(2)=theta0(2)+2*pi;end if theta0(2)>2*pi

theta0(2)=theta0(2)-2*pi;end if theta0(3)<0

theta0(3)=theta0(3)+2*pi;end if theta0(3)>2*pi

theta0(3)=theta0(3)-2*pi;end if theta0(4)<0

theta0(4)=theta0(4)+2*pi;end if theta0(4)>2*pi

theta0(4)=theta0(4)-2*pi; end

%调用子函数Fun_jixie计算该六杆机构的各杆角位移、角速度、角加速度以及E点的角位移、角速度、角加速度

for n1=1:10:361 theta1=(n1-1)*hd; t1(n1)=theta1*du;

theta=fsolve(@(thet) weiyi(thet,theta1),theta0); if theta(1)<0

theta(1)=theta(1)+2*pi;end if theta(1)>2*pi

theta(1)=theta(1)-2*pi;end if theta(2)<0

theta(2)=theta(2)+2*pi;end if theta(2)>2*pi

theta(2)=theta(2)-2*pi;end

if theta(3)<0

theta(3)=theta(3)+2*pi;end if theta(3)>2*pi

theta(3)=theta(3)-2*pi;end if theta(4)<0

theta(4)=theta(4)+2*pi;end if theta(4)>2*pi

theta(4)=theta(4)-2*pi;end

[xe(n1),ye(n1)]=weiyi_E(theta1,theta,l1,l2,l22);

[omega,alph] = Fun_jixie(theta1,omega1,l1,l2,l3,l5,l6,l22,theta);

[V(n1),a(n1)]=sudu_jasudu_E(omega(1),alph(1),theta,theta1,omega1,l1,l2,l22,alph1);

theta2(n1)=theta(1);theta3(n1)=theta(2);theta5(n1)=theta(3);theta6(n1)=theta

第5页

机械原理大作业 机电学院05011303班 (4);omega2(n1)=omega(1);omega3(n1)=omega(2);omega5(n1)=omega(3);omega6(n1)=omega(4);

alph2(n1)=alph(1);alph3(n1)=alph(2);alph5(n1)=alph(3);alph6(n1)=alph(4); theta0=theta; end

%绘制各杆件的角位移、角速度、角加速度 n2=1:10:361; n1=1:10:361; figure(1);%%%%%%

subplot(2,2,1)%绘制位移线图

plot((n1-1),theta2(n2)*du,'r-',(n1-1),theta3(n2)*du,'g-',(n1-1),theta5(n2)*du,'y-',(n1-1),theta6(n2)*du,'k-','LineWidth',1.5); title('各杆角位移线图');

xlabel('原动件1\\theta_1/\\circ'); ylabel('角位移/\\circ'); grid on;hold on; text(200,60,'θ2'); text(200,150,'θ3'); text(200,350,'θ5'); text(200,260,'θ6'); %%%%%%

subplot(2,2,2)%绘制角速度线图

plot((n1-1),omega2(n2),'r-',(n1-1),omega3(n2),'g-',(n1-1),omega5(n2),'y-',(n1-1),omega6(n2),'k-','LineWidth',1.5); title('各杆角速度线图');

xlabel('原动件1\\theta_1/\\circ'); ylabel('角速度/rad\\cdots^{-1}'); grid on;hold on; %%%%%%

subplot(2,2,3)%绘制角加速度线图

plot((n1-1),alph2(n2),'r-',(n1-1),alph3(n2),'g-',(n1-1),alph5(n2),'y-',(n1-1),alph6(n2),'k-','LineWidth',1.5); title('各杆角加速度线图');

xlabel('原动件1\\theta_1/\\circ'); ylabel('角加速度/rad\\cdots^{-2}'); grid on;hold on; %%%%%%% %求E点的位移 figure(2) subplot(2,2,1)

plot(xe(n1),ye(n1),'r-','LineWidth',1.5); title('E的位移线图'); xlabel('E在x方向位移'); ylabel('E在y方向位移');

第6页

机械原理大作业 机电学院05011303班 grid on;hold on; %求E点角速度与角加速度

subplot(2,2,2)%绘制E点角速度

plot((n1-1),V(n1),'r-','LineWidth',1.5); title('E点角速度');

xlabel('原动件1\\theta_1/\\circ'); ylabel('E点角速度/rad\\cdots^{-1}'); grid on;hold on;

subplot(2,2,3)%绘制E点角加速度

plot((n1-1),a(n1),'r-','LineWidth',1.5); title('E点角加速度');

xlabel('原动件1\\theta_1/\\circ'); ylabel('E点角加速度/rad\\cdots^{-2}'); grid on;hold on;

%将数据输出到Exel表shuju1.xls中

xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',t1(n1)','sheet1','A1');

xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',theta2(n1)'*du,'sheet1','B1'); xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',theta3(n1)'*du,'sheet1','C1'); xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',theta5(n1)'*du,'sheet1','D1'); xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',theta6(n1)'*du,'sheet1','E1'); xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',omega2(n1)','sheet1','F1'); xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',omega3(n1)','sheet1','G1'); xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',omega5(n1)','sheet1','H1'); xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',omega6(n1)','sheet1','I1'); xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',alph2(n1)','sheet1','J1');

xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',alph3(n1)','sheet1','K1');

xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',alph5(n1)','sheet1','L1');

xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',alph6(n1)','sheet1','M1');

xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序\\shuju3.xls',V(n1)','sheet1','N1');

xlswrite('E:\\机械原理大作业\\平面六杆机构\\Matlab程序

第7页

联系客服:779662525#qq.com(#替换为@)