基于Robotics Toolbox的机械臂工作空间求解
发布日期:2021-07-01 03:59:50 浏览次数:2 分类:技术文章

本文共 4584 字,大约阅读时间需要 15 分钟。

在这里插入图片描述

简单粗暴,直接上代码!!!

使用工具箱的情况:

代码1:

% By 跃动的风% arm_solve.m% 机械臂可达空间动画求解% 修改:罗伯特祥% using  Robotic Toolbox 10.3clc;clear;L(1) = Link([0,0.08,0,-pi/2]);L(2) = Link([0,0.455,0,pi/2]);L(3) = Link([0,0.0,0,-pi/2]);L(4) = Link([0,0.145,0,pi/2]);L(1).qlim=[0,pi/2];L(2).qlim=[-pi/2,pi/2];L(3).qlim=[-pi/2,pi/2];L(4).qlim=[-pi,pi];base=[ 1 0 0 0;0 0 -1 0;0 1 0 0;0 0 0 1];four_arm = SerialLink(L,'name','fourarm','base',base);teach(four_arm); four_arm.plot([0 0 pi/3 0])hold on;N=30000;    %随机次数%关节角度限制limitmax_1 = 0.0;limitmin_1 = 90.0;limitmax_2 = -90.0;limitmin_2 = 90.0;limitmax_3 = -90.0;limitmin_3 = 90.0;limitmax_4 = -180.0;limitmin_4 = 180.0;theta1=(limitmin_1+(limitmax_1-limitmin_1)*rand(N,1))*pi/180; %关节1限制theta2=(limitmin_2+(limitmax_2-limitmin_2)*rand(N,1))*pi/180; %关节2限制theta3=(limitmin_3+(limitmax_3-limitmin_3)*rand(N,1))*pi/180; %关节3限制theta4=(limitmin_4+(limitmax_4-limitmin_4)*rand(N,1))*pi/180; %关节4限制hold on;for n=1:1:3000    qq=[theta1(n),theta2(n),theta3(n),theta4(n)];    four_arm.plot(qq);%动画显示    Mricx=four_arm.fkine(qq);    plot3(Mricx(1,1).t(1),Mricx(1,1).t(2),Mricx(1,1).t(3),'b.','MarkerSize',0.5);%画出落点endhold off;

代码2:

% By 跃动的风% 机械臂可达空间迅速求解% Robotic Toolbox 9.10clc;clear;L(1) = Link([0,0.08,0,-pi/2]);L(2) = Link([0,0.455,0,pi/2]);L(3) = Link([0,0.0,0,-pi/2]);L(4) = Link([0,0.145,0,pi/2]);L(1).qlim=[0,pi/2];L(2).qlim=[-pi/2,pi/2];L(3).qlim=[-pi/2,pi/2];L(4).qlim=[-pi,pi];base=[ 1 0 0 0;0 0 -1 0;0 1 0 0;0 0 0 1];four_arm = SerialLink(L,'name','fourarm','base',base);teach(four_arm); four_arm.plot([0 0 pi/3 0])hold on;N=30000;    %随机次数    %关节角度限制limitmax_1 = 0.0;limitmin_1 = 90.0;limitmax_2 = -90.0;limitmin_2 = 90.0;limitmax_3 = -90.0;limitmin_3 = 90.0;limitmax_4 = -180.0;limitmin_4 = 180.0;theta1=(limitmin_1+(limitmax_1-limitmin_1)*rand(N,1))*pi/180; %关节1限制theta2=(limitmin_2+(limitmax_2-limitmin_2)*rand(N,1))*pi/180; %关节2限制theta3=(limitmin_3+(limitmax_3-limitmin_3)*rand(N,1))*pi/180; %关节3限制theta4=(limitmin_4+(limitmax_4-limitmin_4)*rand(N,1))*pi/180; %关节4限制qq=[theta1,theta2,theta3,theta4];Mricx=four_arm.fkine(qq);x=reshape(Mricx(1,4,:),N,1);y=reshape(Mricx(2,4,:),N,1);z=reshape(Mricx(3,4,:),N,1);plot3(x,y,z,'b.','MarkerSize',0.5);%画出落点hold on;

不使用工具箱的情况下:

clc;clear;figure( 'Name', 'ROBOT工作空间求解');%连杆DH参数输入a0=0;a1=0;a2=-240;a3=-195;a4=0;a5=0;alpha0=0;alpha1=pi/2;alpha2=0;alpha3=0;alpha4=pi/2;alpha5=-pi/2;d1=70;d2=0;d3=0;d4=102.3;d5=102.3;d6= 62;%蒙特卡洛随机点th1=(0+(180-(0))*rand(1,20000))*pi/180;%a为关节角下限,b为关节角上限th2=(-90+(90-(-90))*rand(1,20000))*pi/180;th3=(-90+(90-(-90))*rand(1,20000))*pi/180;th4=(-180+(180-(-180))*rand(1,20000))*pi/180;th5=(-180+(180-(-180))*rand(1,20000))*pi/180;th6=(-180+(180-(-180))*rand(1,20000))*pi/180;%循环求解正运动学for i=1:1:20000;theta1=th1(i);theta2=th2(i);theta3=th3(i);theta4=th4(i);theta5=th5(i);theta6=th6(i);T01=[cos(theta1),-sin(theta1),0,a0;    sin(theta1)*cos(alpha0),cos(theta1)*cos(alpha0),-sin(alpha0),-sin(alpha0)*d1;    sin(theta1)*sin(alpha0),cos(theta1)*sin(alpha0),cos(alpha0),cos(alpha0)*d1;    0,0,0,1]T12=[cos(theta2),-sin(theta2),0,a1;    sin(theta2)*cos(alpha1),cos(theta2)*cos(alpha1),-sin(alpha1),-sin(alpha1)*d2;    sin(theta2)*sin(alpha1),cos(theta2)*sin(alpha1),cos(alpha1),cos(alpha1)*d2;    0,0,0,1]T23=[cos(theta3),-sin(theta3),0,a2;    sin(theta3)*cos(alpha2),cos(theta3)*cos(alpha2),-sin(alpha2),-sin(alpha2)*d3;    sin(theta3)*sin(alpha2),cos(theta3)*sin(alpha2),cos(alpha2),cos(alpha2)*d3;    0,0,0,1]T34=[cos(theta4),-sin(theta4),0,a3;    sin(theta4)*cos(alpha3),cos(theta4)*cos(alpha3),-sin(alpha3),-sin(alpha3)*d4;    sin(theta4)*sin(alpha3),cos(theta4)*sin(alpha3),cos(alpha3),cos(alpha3)*d4;    0,0,0,1]T45=[cos(theta5),-sin(theta5),0,a4;    sin(theta5)*cos(alpha4),cos(theta5)*cos(alpha4),-sin(alpha4),-sin(alpha4)*d5;    sin(theta5)*sin(alpha4),cos(theta5)*sin(alpha4),cos(alpha4),cos(alpha4)*d5;    0,0,0,1]T56=[cos(theta6),-sin(theta6),0,a5;    sin(theta6)*cos(alpha5),cos(theta6)*cos(alpha5),-sin(alpha5),-sin(alpha5)*d4;    sin(theta6)*sin(alpha5),cos(theta6)*sin(alpha5),cos(alpha5),cos(alpha5)*d4;    0,0,0,1]T=T01*T12*T23*T34*T45*T56;%px,py,pz计算公式px(i)=T(1,4);py(i)=T(2,4);pz(i)=T(3,4);end;%打印空间坐标点subplot(221);scatter3(px,py,pz,'.');title('工作空间三维图');xlabel('x轴');%x轴坐标ylabel('y轴');%y轴坐标zlabel('z轴');%z轴坐标subplot(222);scatter3(px,py,pz,'.');view(0,90);%视图调整title('工作空间XY平面');xlabel('x轴');%x轴坐标ylabel('y轴');%y轴坐标zlabel('z轴');%z轴坐标subplot(223);scatter3(px,py,pz,'.');view(0,0);%视图调整title('工作空间XZ平面');xlabel('x轴');%x轴坐标ylabel('y轴');%y轴坐标zlabel('z轴');%z轴坐标subplot(224);scatter3(px,py,pz,'.');view(90,0);%视图调整title('工作空间YZ平面');xlabel('x轴');%x轴坐标ylabel('y轴');%y轴坐标zlabel('z轴');%z轴坐标

转载地址:https://miracle.blog.csdn.net/article/details/102734315 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:常用的一些伺服电机参数
下一篇:关于机械臂的模仿学习

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月30日 06时59分14秒