程序开始 给定已知参数:L1,L2,L3,L4,W2 设置th2的范围及步长 调用fsolve函数求解th3,th4 求解连杆3两端点坐标值 绘制连杆3的几个位置点 重新设置步长 新步长输入 绘制从动件角位移线图 利用矩阵公式求W3,W4 绘制从动件角速度线图 利用矩阵公式求a3,a4 绘制从动件角加速度线图 输出一个周期内角位移,角速度,角加速度数据 程序结束 图2 程序流程图 7
3.2 M文件编写[16]
首先创建函数aa,函数fsolve通过他确定?3,?4。
function t=aa(th1,th2,L2,L3,L4,L1)
t=[L2*cos(th2)+L3*cos(th(1))-L4*cos(th(2))-L1;L2*sin(th2)+L3*sin(th(1))-L4*sin(th(2))];
主程序如下:
disp ' * * * * * * 平面四杆机构的运动分析 * * * * * *' L1=input('输入机架长度 L1='); L2=input('输入曲柄长度(主动件) L2='); L3=input('输入连杆长度 L3='); L4=input('输入输入从动杆长度 L4='); rs=[L1 L2 L3 L4]; minimum=min(rs); maximum=max(rs);
if (minimum+maximum)>(sum(rs)-minimum-maximum) disp '此机构不满足杆长条件,程序终止',break; end
if L1<=L2&L1<=L3&L1<=L4
disp '此机构为双曲柄机构' elseif L2<=L1&L2<=L3&L2<=L4
disp '此机构为曲柄摇杆机构'
else disp '此机构为双摇杆机构,本例不予考虑',break; end
w2=input('输入主动件角速度 w2='); th2=[0:1/6:2]*pi;
th34=zeros(length(th2),2);
options=optimset('display','off'); for m=1:length(th2)
th34(m,:)=fsolve('aa',[1 1],options,th2(m),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)
plot([x;xx],[y;yy],'k',[0 L1],[0 0],'k--^',x,y,'ko',xx,yy,'ks') title('连杆3的几个位臵点') xlabel('水平方向') ylabel('垂直方向') axis equal
th2=[0:2/72:2]*pi; for m=1:length(th2)
th34(m,:)=fsolve('aa',[1 1],options,th2(m),L2,L3,L4,L1);
8
end
figure(2)
plot(th2*180/pi,th34(:,1),th2*180/pi,th34(:,2))
plot(th2*180/pi,th34(:,1)*180/pi,th2*180/pi,th34(:,2)*180/pi) grid
xlabel('主动件转角\\theta_2(度)') ylabel('从动件角位移(度)') title('角位移线图')
w3=(L2*w2*sin(th34(:,2)-th2'))./(L3*sin(th34(:,1)-th34(:,2))); w4=(L2*w2*sin(th2'-th34(:,1)))./(L4*sin(th34(:,2)-th34(:,1))); figure(3)
plot(th2*180/pi,w3,th2*180/pi,w4); grid
xlabel('主动件转角\\theta_2(度)')
ylabel('从动件角速度(rad\\cdot s^{-1})') title('角速度线图') s32=th34(:,1)-th2';
s43=th34(:,2)-th34(:,1); s24=th2'-th34(:,2);
a3=(L2*w2^2*cos(s24)+L3*w3.^2.*cos(s43)-L4*w4.^2)./(L4*sin(s43)); a4=(L2*w2^2*cos(s32)-L4*w4.^2.*cos(s43)+L3*w3.^2)./(L4*sin(s43)); figure(4)
plot(th2*180/pi,a3,th2*180/pi,a4); grid
xlabel('从动件角加速度')
ylabel('从动件角加速度(rad\\cdot s^{-2})') title('角加速度线图')
disp ' 曲柄转角 连杆转角-从动杆4转角-连杆角速度-从动杆4角速度-连杆加速度-从动杆4加速度'
ydcs=[th2'*180/pi,th34(:,1)*180/pi,th34(:,2)*180/pi,w3,w4,a3,a4]; disp(ydcs)
ex=L2*cos(th2')+L3*cos(th34(:,1))-L4*cos(th34(:,2))-L1; ey=L2*sin(th2')+L3*sin(th34(:,1))-L4*sin(th34(:,2)); ee=norm([ex ey]);
disp ' 曲柄转角 X向偏差 Y向偏差' wc=[th2'*180/pi,ex,ey] disp(wc)
fprintf(1,' 偏差矢量矩阵的模ee=%3.4f\\n',ee) figure(5)
plot(th2*180/pi,ex,th2*180/pi,ey) grid
title('均方根偏差曲线')
xlabel('主动件转角\\theta_2(度)') ylabel('均方根偏差')
9
3.3 程序运行结果输出
* * * * * * 平面四杆机构的运动分析 * * * * * * 输入机架长度 L1=90 输入曲柄长度(主动件) L2=30 输入连杆长度 L3=60 输入输入从动杆长度 L4=70 此机构为曲柄摇杆机构
输入主动件角速度 w2=20
曲柄转角 连杆转角-从动杆4转角-连杆角速度-从动杆4角速度-连杆加速度-从动杆4加速度
Columns 1 through 6
0 71.3707 125.6853 -10.0000 -10.0000 -184.6761 5.0000 68.7629 123.2500 -10.8220 -9.4453 -137.6470 10.0000 65.9802 120.9809 -11.3983 -8.6728 -88.7805 15.0000 63.0843 118.9297 -11.7289 -7.7076 -41.6608 20.0000 60.1349 117.1400 -11.8305 -6.5875 0.7471 25.0000 57.1857 115.6451 -11.7326 -5.3571 36.4813 30.0000 54.2822 114.4668 -11.4719 -4.0626 64.6726 35.0000 51.4601 113.6156 -11.0869 -2.7467 85.3915 40.0000 48.7460 113.0922 -10.6140 -1.4458 99.3671 45.0000 46.1578 112.8890 -10.0848 -0.1885 107.6877 50.0000 43.7061 112.9925 -9.5252 1.0046 111.5547 55.0000 41.3961 113.3848 -8.9547 2.1200 112.1168 60.0000 39.2285 114.0454 -8.3876 3.1497 110.3787 65.0000 37.2012 114.9523 -7.8334 4.0906 107.1673 70.0000 35.3102 116.0832 -7.2979 4.9422 103.1339 75.0000 33.5504 117.4161 -6.7839 5.7066 98.7752 80.0000 31.9164 118.9295 -6.2922 6.3869 94.4624 85.0000 30.4026 120.6028 -5.8217 6.9866 90.4698 90.0000 29.0040 122.4164 -5.3702 7.5098 87.0018 95.0000 27.7161 124.3516 -4.9347 7.9599 84.2148 100.0000 26.5356 126.3905 -4.5114 8.3400 82.2350 105.0000 25.4598 128.5160 -4.0959 8.6527 81.1722 110.0000 24.4874 130.7114 -3.6833 8.8996 81.1294 115.0000 23.6183 132.9604 -3.2680 9.0815 82.2090 120.0000 22.8540 135.2467 -2.8442 9.1985 84.5143 125.0000 22.1975 137.5541 -2.4053 9.2494 88.1462 130.0000 21.6532 139.8658 -1.9444 9.2326 93.1925 135.0000 21.2277 142.1645 -1.4541 9.1452 99.7082 140.0000 20.9293 144.4323 -0.9268 8.9843 107.6830 145.0000 20.7680 146.6503 -0.3554 8.7464 116.9971 150.0000 20.7557 148.7989 0.2662 8.4289 127.3655 155.0000 20.9056 150.8580 0.9422 8.0304 138.2825 160.0000 21.2315 152.8074 1.6737 7.5520 148.9874
10
165.0000 21.7468 154.6277 2.4570 6.9983 158.4813 170.0000 22.4636 156.3010 3.2832 6.3785 165.6267 175.0000 23.3908 157.8125 4.1374 5.7064 169.3344 180.0000 24.5330 159.1513 5.0000 5.0000 168.8014 185.0000 25.8896 160.3113 5.8483 4.2793 163.7155 190.0000 27.4540 161.2915 6.6595 3.5642 154.3353 195.0000 29.2145 162.0954 7.4135 2.8723 141.4095 200.0000 31.1547 162.7307 8.0949 2.2166 125.9711 205.0000 33.2551 163.2074 8.6936 1.6054 109.0995 210.0000 35.4943 163.5374 9.2048 1.0421 91.7321 215.0000 37.8502 163.7324 9.6279 0.5260 74.5640 220.0000 40.3011 163.8041 9.9651 0.0540 58.0308 225.0000 42.8259 163.7627 10.2202 -0.3791 42.3417 230.0000 45.4047 163.6173 10.3977 -0.7793 27.5346 235.0000 48.0186 163.3753 10.5019 -1.1529 13.5312 240.0000 50.6498 163.0425 10.5365 -1.5062 0.1811 245.0000 53.2813 162.6234 10.5045 -1.8451 -12.7055 250.0000 55.8967 162.1207 10.4076 -2.1752 -25.3371 255.0000 58.4798 161.5360 10.2466 -2.5020 -37.9287 260.0000 61.0146 160.8696 10.0212 -2.8303 -50.6938 265.0000 63.4849 160.1204 9.7299 -3.1647 -63.8408 270.0000 65.8738 159.2863 9.3702 -3.5098 -77.5696 275.0000 68.1640 158.3643 8.9388 -3.8695 -92.0672 280.0000 70.3369 157.3500 8.4313 -4.2478 -107.5012 285.0000 72.3729 156.2385 7.8425 -4.6481 -124.0090 290.0000 74.2509 155.0239 7.1668 -5.0734 -141.6810 295.0000 75.9485 153.6996 6.3980 -5.5260 -160.5356 300.0000 77.4417 152.2586 5.5305 -6.0069 -180.4846 305.0000 78.7051 150.6938 4.5590 -6.5156 -201.2871 310.0000 79.7123 148.9987 3.4804 -7.0494 -222.4931 315.0000 80.4363 147.1676 2.2943 -7.6020 -243.3816 320.0000 80.8508 145.1969 1.0048 -8.1633 -262.9044 325.0000 80.9310 143.0864 -0.3776 -8.7178 -279.6556 330.0000 80.6557 140.8404 -1.8347 -9.2440 -291.8984 335.0000 80.0097 138.4691 -3.3385 -9.7140 -297.6852 340.0000 78.9857 135.9908 -4.8512 -10.0942 -295.0989 345.0000 77.5872 133.4326 -6.3261 -10.3473 -282.6143 350.0000 75.8302 130.8308 -7.7105 -10.4360 -259.5197 355.0000 73.7440 128.2310 -8.9510 -10.3277 -226.2782 360.0000 71.3707 125.6853 -10.0000 -10.0000 -184.6761
11