# 【机器人学】1-3.六自由度机器人工作空间 【附MATLAB代码】

20 篇文章 18 订阅

### 前言

分析机械臂工作空间的方法有以下三种：几何构建法、解析法和数值计算法。

蒙特卡洛法就是数值计算法的其中一种，该方法是随机选取大量的采样点，来尽可能构建出机器人完整的工作空间。

### 蒙特卡洛法

• 机械臂的各关节是在其相应取值范围内工作；
• 所有关节在相应取值范围内随机遍历取值；
• 末端点的所有随机值的集合就构成了机械臂的工作空间

### 机器人工作空间

% 求齐次变换矩阵
function T = DHTrans(alpha, a, d, theta)
T= [cos(theta)             -sin(theta)            0            a;
sin(theta)*cos(alpha)  cos(theta)*cos(alpha)  -sin(alpha)  -sin(alpha)*d;
sin(theta)*sin(alpha)  cos(theta)*sin(alpha)  cos(alpha)   cos(alpha)*d;
0                      0                      0            1];
end

function Rxyz=RotMat_AxisAngle(R)
theta = acos((R(1,1)+R(2,2)+R(3,3)-1)/2);
r = 1/2/sin(theta)*[R(3,2)-R(2,3);R(1,3)-R(3,1);R(2,1)-R(1,2)];
Rxyz=theta*r;
end
% 输入机器人q1,q2,q3,q4,q5,q6的角度
% 输出末端位姿的轴线表示
function position = modelRobot(theta)
th(1) = theta(1); d(1) = 0.1607; a(1) = 0; alp(1) = 0;
th(2) = theta(2); d(2) = 0; a(2) = 0; alp(2) = pi/2;
th(3) = theta(3); d(3) = 0; a(3) = 0.425; alp(3) = 0;
th(4) = theta(4); d(4) = 0.1133; a(4) = 0.393; alp(4) = 0;
th(5) = theta(5); d(5) = 0.099; a(5) = 0; alp(5) = -pi/2;
th(6) = theta(6); d(6) = 0.0936; a(6) = 0; alp(6) = pi/2;

T01 = DHTrans(alp(1), a(1), d(1), th(1));
T12 = DHTrans(alp(2), a(2), d(2), th(2)+pi/2);
T23 = DHTrans(alp(3), a(3), d(3), th(3));
T34 = DHTrans(alp(4), a(4), d(4), th(4)-pi/2);
T45 = DHTrans(alp(5), a(5), d(5), th(5));
T56 = DHTrans(alp(6), a(6), d(6), th(6));

T06=T01*T12*T23*T34*T45*T56;
axis = RotMat_AxisAngle(T06)/pi*180;
position = [T06(1:3,4:4),axis];
end


clc;clear;
theta1min = -360;theta1max = 360;
theta2min = -360 ;theta2max = 360 ;
theta3min = -360 ;theta3max = 360 ;
theta4min = -360;theta4max = 360;
theta5min = -360;theta5max = 360;
theta6min = -360;theta6max = 360;
%
n = 300000;
x = zeros;y = zeros;z = zeros;
for i = 1:n

theta1 = theta1min*(pi/180) + (theta1max-theta1min)*(pi/180)*rand;
theta2 = theta2min*(pi/180) + (theta2max-theta2min)*(pi/180)*rand;
theta3 = theta3min*(pi/180) + (theta3max-theta3min)*(pi/180)*rand;
theta4 = theta4min*(pi/180) + (theta4max-theta4min)*(pi/180)*rand;
theta5 = theta5min*(pi/180) + (theta5max-theta5min)*(pi/180)*rand;
theta6 = theta6min*(pi/180) + (theta6max-theta6min)*(pi/180)*rand;

Tws = modelRobot([theta1,theta2,theta3,theta4,theta5,theta6]);
x(i) = Tws(1,1);
y(i) = Tws(2,1);
z(i) = Tws(3,1);
end
figure('color',[1 1 1]);
plot3(x,y,z,'b.','MarkerSize',0.5)
hold on
xlabel('x轴(millimeter)','color','r','fontsize',15);
ylabel('y轴(millimeter)','color','r','fontsize',15);
zlabel('z轴(millimeter)','color','r','fontsize',15);
grid on

11-08
03-29 1万+
12-25
02-18
11-19
05-10
01-31
03-30
03-25 2874

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。