用Matlab绘制推程为简谐运动,回程为等减速运动的凸轮,要求基圆半径80mm,滚子半径10mm,偏置距离10mm,形成距离30mm,角速度0.08mm,推成运动角130°,远休止角25°,回城运动角145°,进休止角60°,从动件长度50mm,要求图中标出各个从动件位置的压力角,标出最大压力角以及最小压力角的位置,使Matlab最终实现凸轮廓线显示的gif图和压力角a的变化曲线的gif图,并给出最大最小压力角值。
时间: 2023-09-30 20:04:48 浏览: 50
好的,我将为您提供具体的代码实现。
首先,我们需要定义凸轮的几何参数和运动规律:
```matlab
r_b = 80; % 基圆半径
r_c = 10; % 滚子半径
e = 10; % 偏置距离
h = 30; % 形成距离
w = 0.08; % 角速度
theta_p = 130/180*pi; % 推程角
theta_r = 145/180*pi; % 回程角
theta_pz = 25/180*pi; % 远休止角
theta_rz = 60/180*pi; % 进休止角
l = 50; % 从动件长度
```
接下来,我们可以计算凸轮的几何参数和各个从动件的位置和压力角:
```matlab
% 计算凸轮的运动规律
theta = 0:0.01:2*pi; % 角度范围
r = r_b + h/2*(1-cos(theta_p))*ones(size(theta));
r(theta>=theta_p & theta<theta_r) = r_b + h/2*(1+cos(theta(theta>=theta_p & theta<theta_r)-theta_p))...
-h/2*(1-cos(theta_p));
r(theta>=theta_r & theta<theta_r+theta_pz) = r_b + h/2*(1+cos(theta_r-theta_p))...
-h/2*(1-cos(theta_p)) - (theta(theta>=theta_r & theta<theta_r+theta_pz)-theta_r)/theta_pz*h/2;
r(theta>=theta_r+theta_pz & theta<theta_p+theta_r+theta_rz) = r_b - e + h - h/2*(1+cos(theta(theta>=theta_r+theta_pz &...
theta<theta_p+theta_r+theta_rz)-theta_r-theta_pz)) - (theta(theta>=theta_r+theta_pz & theta<theta_p+theta_r+theta_rz)...
-theta_r-theta_pz)/theta_rz*h/2;
r(theta>=theta_p+theta_r+theta_rz & theta<=2*pi) = r_b - e;
% 计算从动件的位置和压力角
x = r.*cos(theta);
y = r.*sin(theta);
phi = atan2(y,x-e) - acos((x-e)./sqrt((x-e).^2+y.^2));
```
然后,我们可以绘制凸轮的轮廓线和压力角的变化曲线:
```matlab
% 绘制凸轮的轮廓线
figure(1);
plot(x,y);
xlabel('x (mm)');
ylabel('y (mm)');
title('凸轮的轮廓线');
axis equal;
% 标注从动件位置的压力角
hold on;
for i = 1:length(phi)
if phi(i) <= 0
text(x(i),y(i),num2str(round(phi(i)/pi*180)), 'HorizontalAlignment','center','VerticalAlignment','middle');
else
text(x(i),y(i),num2str(round(phi(i)/pi*180)), 'HorizontalAlignment','center','VerticalAlignment','middle', 'Color', 'r');
end
end
% 绘制压力角a的变化曲线
theta_deg = theta/pi*180;
phi_deg = phi/pi*180;
a = acos((x-e)./sqrt((x-e).^2+y.^2)) - phi;
figure(2);
plot(theta_deg,a/pi*180);
xlabel('\theta (°)');
ylabel('a (°)');
title('压力角a的变化曲线');
% 标注最大压力角和最小压力角的位置
hold on;
[max_a, max_idx] = max(a);
[min_a, min_idx] = min(a);
plot(theta_deg(max_idx), max_a/pi*180, 'ro');
plot(theta_deg(min_idx), min_a/pi*180, 'ro');
text(theta_deg(max_idx), max_a/pi*180+5, ['max a = ' num2str(round(max_a/pi*180,1)) '°']);
text(theta_deg(min_idx), min_a/pi*180-20, ['min a = ' num2str(round(min_a/pi*180,1)) '°']);
```
最后,我们可以使用Matlab中的函数生成凸轮轮廓线的gif图和压力角a的变化曲线的gif图:
```matlab
% 生成凸轮轮廓线的gif图
fig1 = figure(1);
filename1 = 'cam_profile.gif';
for i = 1:length(theta)
plot(x(1:i),y(1:i), 'b');
xlabel('x (mm)');
ylabel('y (mm)');
title('凸轮的轮廓线');
axis equal;
hold on;
plot(x(i),y(i), 'ro');
text(x(i),y(i),num2str(round(phi(i)/pi*180)), 'HorizontalAlignment','center','VerticalAlignment','middle');
frame1 = getframe(fig1);
im1 = frame2im(frame1);
[imind1,cm1] = rgb2ind(im1,256);
if i == 1
imwrite(imind1,cm1,filename1,'gif', 'Loopcount',inf, 'DelayTime',0.01);
else
imwrite(imind1,cm1,filename1,'gif', 'WriteMode','append', 'DelayTime',0.01);
end
hold off;
end
% 生成压力角a的变化曲线的gif图
fig2 = figure(2);
filename2 = 'a_curve.gif';
for i = 1:length(theta_deg)
plot(theta_deg(1:i),a(1:i)/pi*180, 'b');
xlabel('\theta (°)');
ylabel('a (°)');
title('压力角a的变化曲线');
hold on;
plot(theta_deg(i),a(i)/pi*180, 'ro');
text(theta_deg(i),a(i)/pi*180+5,num2str(round(a(i)/pi*180,1)), 'HorizontalAlignment','center','VerticalAlignment','middle');
plot([theta_deg(i) theta_deg(i)], [min(a)/pi*180 max(a)/pi*180], 'k--');
text(theta_deg(max_idx), max_a/pi*180+5, ['max a = ' num2str(round(max_a/pi*180,1)) '°']);
text(theta_deg(min_idx), min_a/pi*180-20, ['min a = ' num2str(round(min_a/pi*180,1)) '°']);
hold off;
frame2 = getframe(fig2);
im2 = frame2im(frame2);
[imind2,cm2] = rgb2ind(im2,256);
if i == 1
imwrite(imind2,cm2,filename2,'gif', 'Loopcount',inf, 'DelayTime',0.01);
else
imwrite(imind2,cm2,filename2,'gif', 'WriteMode','append', 'DelayTime',0.01);
end
end
```
最终,我们可以得到凸轮的轮廓线和压力角a的变化曲线的gif图,并且可以得到最大压力角和最小压力角的位置和值。
阅读全文