如何解决机器人关节图的绘制位置不起作用
| 我想编写一个命令来显示机器人位置方程及其图形。这是我的命令,但未显示图形:clear;
clc;
% initial position
theta1s=-150;
theta2s=-80;
theta3s=-50;
theta4s=-100;
theta5s=-180;
% final position
theta1f=20;
theta2f=100;
theta3f=80;
theta4f=50;
theta5f=180;
% time taken for movement
tf=input(\'time=\')
% acceleration for every link
acc1=(4.*(20-(-150)))./(tf^2)
acc2=(4.*(100-(-80)))./(tf^2)
acc3=(4.*(80-(-50)))./(tf^2)
acc4=(4.*(50-(-100)))./(tf^2)
acc5=(4.*(180-(-180)))./(tf^2)
% blending time for every link
tb1=((0.5.*(tf))-(0.5.*(sqrt((((tf^2).*acc1)-(4.*(20-(-150))))./acc1))))
t = 0;
for x = 0:tf;
t = t + 0.1;
if 0<t<=tb1;
y = theta1s+((0.5.*acc1).*(t^2));
elseif tb1<t<=tf-tb1;
y = (theta1s-((0.5.*acc1).*(tb1^2)))+(acc1.*tb1.*t);
else tf-tb1<t<=tf;
y = theta1s-((0.5.*acc1).*(tf.*t)^2);
end
plot(x,y,\'r\')
title(\'Position Versus Time\');
xlabel(\'time in s\');
ylabel(\'position in m\');
grid on;
drawnow;
end
disp(y);
解决方法
您可以用plot(x,y,\'r * \')替换plot(x,y,\'r \')。因此,您将能够看到单独的点。
另外,您将需要在绘图功能之后添加\“ hold \\”才能覆盖所有迭代的绘图。
如果要画线而不是分开的点,则最好将可视化文件移出循环。这是修改后的代码:
clear;
clc;
% initial position
theta1s=-150;
theta2s=-80;
theta3s=-50;
theta4s=-100;
theta5s=-180;
% final position
theta1f=20;
theta2f=100;
theta3f=80;
theta4f=50;
theta5f=180;
% time taken for movement
tf=input(\'time=\')
% acceleration for every link
acc1=(4.*(20-(-150)))./(tf^2)
acc2=(4.*(100-(-80)))./(tf^2)
acc3=(4.*(80-(-50)))./(tf^2)
acc4=(4.*(50-(-100)))./(tf^2)
acc5=(4.*(180-(-180)))./(tf^2)
% blending time for every link
tb1=((0.5.*(tf))-(0.5.*(sqrt((((tf^2).*acc1)-(4.*(20-(-150))))./acc1))))
t = 0;
% allocate memory for array
y = zeros(1,tf+1);
for x = 0:tf;
t = t + 0.1;
if 0<t<=tb1;
y(x+1) = theta1s+((0.5.*acc1).*(t^2));
elseif tb1<t<=tf-tb1;
y(x+1) = (theta1s-((0.5.*acc1).*(tb1^2)))+(acc1.*tb1.*t);
else tf-tb1<t<=tf;
y(x+1) = theta1s-((0.5.*acc1).*(tf.*t)^2);
end
end
plot(0:tf,y,\'r\')
title(\'Position Versus Time\');
xlabel(\'time in s\');
ylabel(\'position in m\');
grid on;
drawnow;
disp(y);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。