robotic+toolbox+使用说明

更新时间:2023-11-06 02:41:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

robotic toolbox for matlab工具箱

1. PUMA560的MATLAB仿真

要建立PUMA560的机器人对象,首先我们要了解PUMA560的D-H参数,之后我们可以利用Robotics Toolbox工具箱中的link和robot函数来建立PUMA560的机器人对象。 其中link函数的调用格式:

L = LINK([alpha A theta D])

L =LINK([alpha A theta D sigma]) L =LINK([alpha A theta D sigma offset]) L =LINK([alpha A theta D], CONVENTION) L =LINK([alpha A theta D sigma], CONVENTION) L =LINK([alpha A theta D sigma offset], CONVENTION)

参数CONVENTION可以取‘standard’和‘modified’,其中‘standard’代表采用标准的D-H参数,‘modified’代表采用改进的D-H参数。参数‘alpha’代表扭转角 ,参数‘A’代表杆件长度,参数‘theta’代表关节角,参数‘D’代表横距,参数‘sigma’代表关节类型:0代表旋转关节,非0代表移动关节。另外LINK还有一些数据域:

LINK.alpha %返回扭转角 LINK.A %返回杆件长度 LINK.theta %返回关节角 LINK.D %返回横距 LINK.sigma %返回关节类型 LINK.RP

%返回‘R’(旋转)或‘P’(移动)

LINK.mdh %若为标准D-H参数返回0,否则返回1 LINK.offset %返回关节变量偏移

LINK.qlim %返回关节变量的上下限 [min max] LINK.islimit(q) %如果关节变量超限,返回 -1, 0, +1 LINK.I LINK.m

%返回一个3×3 对称惯性矩阵 %返回关节质量

LINK.r %返回3×1的关节齿轮向量 %返回齿轮的传动比 %返回电机惯性 %返回粘性摩擦 %返回库仑摩擦

return legacy DH row

LINK.G

LINK.Jm LINK.B LINK.Tc LINK.dh

LINK.dyn return legacy DYN row

其中robot函数的调用格式:

ROBOT

%创建一个空的机器人对象

%创建robot的一个副本

%用LINK来创建新机器人对象来代替robot

ROBOT(robot)

ROBOT(robot, LINK)

ROBOT(LINK, ...) %用LINK来创建一个机器人对象 ROBOT(DH, ...) ROBOT(DYN, ...)

%用D-H矩阵来创建一个机器人对象

%用DYN矩阵来创建一个机器人对象

2.变换矩阵

利用MATLAB中Robotics Toolbox工具箱中的transl、rotx、roty和rotz可以实现用齐次变换矩阵表示平移变换和旋转变换。下面举例来说明:

A 机器人在x轴方向平移了0.5米,那么我们可以用下面的方法来求取平移变换后的齐次矩阵: >> transl(0.5,0,0) ans =

1.0000 0 0 0.5000 0 1.0000 0 0 0 0 1.0000 0 0 0 0 1.0000

B 机器人绕x轴旋转45度,那么可以用rotx来求取旋转后的齐次矩阵: >> rotx(pi/4) ans =

1.0000 0 0 0 0 0.7071 -0.7071 0

0 0.7071 0.7071 0

0 0 0 1.0000

C 机器人绕y轴旋转90度,那么可以用roty来求取旋转后的齐次矩阵: >> roty(pi/2) ans =

0.0000 0 1.0000 0 0 1.0000 0 0 -1.0000 0 0.0000 0 0 0 0 1.0000

D 机器人绕z轴旋转-90度,那么可以用rotz来求取旋转后的齐次矩阵: >> rotz(-pi/2) ans =

0.0000 1.0000 0 0 -1.0000 0.0000 0 0 0 0 1.0000 0 0 0 0 1.0000

当然,如果有多次旋转和平移变换,我们只需要多次调用函数在组合就可以了。另外,可以和我们学习的平移矩阵和旋转矩阵做个对比,相信是一致的。

3 轨迹规划

利用Robotics Toolbox提供的ctraj、jtraj和trinterp函数可以实现笛卡尔规划、关节空间规划和变换插值。 其中ctraj函数的调用格式:

TC = CTRAJ(T0, T1, N) TC = CTRAJ(T0, T1, R)

参数TC为从T0到T1的笛卡尔规划轨迹,N为点的数量,R为给定路径距离向量,R的每个值必须在0到1之间。 其中jtraj函数的调用格式:

[Q QD QDD] = JTRAJ(Q0, Q1, N)

[Q QD QDD] = JTRAJ(Q0, Q1, N, QD0, QD1)

[Q QD QDD] = JTRAJ(Q0, Q1, T)

[Q QD QDD] = JTRAJ(Q0, Q1, T, QD0, QD1)

参数Q为从状态Q0到Q1的关节空间规划轨迹,N为规划的点数,T为给

定的时间向量的长度,速度非零边界可以用QD0和QD1来指定。QD和QDD为返回的规划轨迹的速度和加速度。 其中trinterp函数的调用格式:

TR = TRINTERP(T0, T1, R)

参数TR为在T0和T1之间的坐标变化插值,R需在0和1之间。

要实现轨迹规划,首先我们要创建一个时间向量,假设在两秒内完成某个动作,采样间隔是56ms,那么可以用如下的命令来实现多项式轨迹规划:t=0:0.056:2; [q,qd,qdd]=jtraj(qz,qr,t);

其中t为时间向量,qz为机器人的初始位姿,qr为机器人的最终位姿,q为经过的路径点,qd为运动的速度,qdd为运动的加速度。其中q、qd、qdd都是六列的矩阵,每列代表每个关节的位置、速度和加速度。如q(:,3)代表关节3的位置,qd(:,3)代表关节3的速度,qdd(:,3)代表关节3的加速度。 4 运动学的正问题

利用Robotics Toolbox中的fkine函数可以实现机器人运动学正问题的求解。 其中fkine函数的调用格式:

TR = FKINE(ROBOT, Q)

参数ROBOT为一个机器人对象,TR为由Q定义的每个前向运动学的正解。

以PUMA560为例,定义关节坐标系的零点qz=[0 0 0 0 0 0],那么fkine(p560,qz)将返回最后一个关节的平移的齐次变换矩阵。如果有了关节的轨迹规划之后,我们也可以用fkine来进行运动学的正解。比如: t=0:0.056:2; q=jtraj(qz,qr,t); T=fkine(p560,q);

返回的矩阵T是一个三维的矩阵,前两维是4×4的矩阵代表坐标变化,第三维是时间。

5 运动学的逆问题

利用Robotics Toolbox中的ikine函数可以实现机器人运动学逆问题的求解。 其中ikine函数的调用格式:

Q = IKINE(ROBOT, T) Q = IKINE(ROBOT, T, Q) Q = IKINE(ROBOT, T, Q, M)

参数ROBOT为一个机器人对象,Q为初始猜测点(默认为0),T为要反解的变换矩阵。当反解的机器人对象的自由度少于6时,要用M进行忽略某个关节自由度。

有了关节的轨迹规划之后,我们也可以用ikine函数来进行运动学逆问题的求解。比如:

t=0:0.056:2; T1=transl(0.6,-0.5,0); T2=transl(0.4,0.5,0.2); T=ctraj(T1,T2,length(t)); q=ikine(p560,T);

我们也可以尝试先进行正解,再进行逆解,看看能否还原。 Q=[0 –pi/4 –pi/4 0 pi/8 0]; T=fkine(p560,q); qi=ikine(p560,T); 6 动画演示

有了机器人的轨迹规划之后,我们就可以利用Robotics Toolbox中的plot函数来实现对规划路径的仿真。

puma560;T=0:0.056:2; q=jtraj(qz,qr,T); plot(p560,q);

当然,我们也可以来调节PUMA560的六个旋转角,来实现动画演示。 drivebot(p560)

一 摘要

本文主要是利用Robotics Toolbox工具箱和GUIDE编程来实现对六自由度串联机器人PUMA560进行系统仿真,其中涉及到动力学、运动学和轨迹规划的分析。并且整个系统可以演示出六自由度串联机器人打磨的过程动画和打磨过程的轨迹。

二 仿真系统的概貌及结构

仿 真系统的开发遵循以下原则:一、基于微机;二、交互式,仿真时各种参数以及仿真类型选择都是由用户通过人机对话方式进行的,通过改变参数,就可对各种不同 的机器人进行仿真;三、软件模块化,这便于软件移植、修改和扩展,通过调用不同的子程序模块,就可完成不同的仿真研究。

三 构建机器人对象

利用Robotics Toolbox进行构建机器人对象,首先需要通过构建各个关节来,然后通过关节的组合来实现构建整个机器人对象。如果要完整的构建一个机器人对象,需要D-H参数、关节类型(移动或转动关节)、关节质量、库伦摩擦、粘性摩擦和齿轮传动比等。

构建机器人对象主要在于构建各个关节,而构建关节时,会用到Robotics Toolbox中的LINK函数:

L = LINK([alpha A theta D]) L =LINK([alpha A theta D sigma]) L =LINK([alpha A theta D sigma offset]) L =LINK([alpha A theta D], CONVENTION) L =LINK([alpha A theta D sigma], CONVENTION) L =LINK([alpha A theta D sigma offset], CONVENTION)

参数CONVENTION可以取‘standard’和‘modified’,其中‘standard’代表采用标准的D-H参数,‘modified’代表采用改进的D-H参数。参数‘alpha’代表扭转角 ,参数‘A’代表杆件长度,参数‘theta’代表关节角,参数‘D’代表横距,参数‘sigma’代表关节类型:0代表旋转关节,非0代表移动关节。

四 运动学的正问题与逆问题

运动学处理运动的几何学以及与时间有关的量,而不考虑引起运动的力。位置运动学则只处理运动的几何学,而不考虑运动的时间。机器人的位置运动学存在有两类问题:一、根据关节变量求手部位姿是位置运动学正问题;二、根据手部位姿求关节变量是位置运动学逆问题。

速度运动学问题重要是因为操作机不仅需要达到某个(或一系列的)位置,而且常需要它按给定的速度达到这些位置。

利用Robotics Toolbox来求解机器人的运动学的正问题和逆问题,需要用到FKINE和IKINE两个函数,它们的调用格式:

TR = FKINE(ROBOT, Q)

参数ROBOT为一个机器人对象,TR为由Q定义的每个前向运动学的正解。

Q = IKINE(ROBOT, T)

参数ROBOT为一个机器人对象,T为要反解的变换矩阵。

五 动力学的正问题和逆问题

动力学正问题:已知机械手各关节的作用力或力矩,求各关节的位移、速度和加速度。

利用Robotics Toolbox进行动力学正问题的求解,需要用到其中的FDYN函数和ACCEL函数,它们的调用格式:

[T Q QD] = FDYN(ROBOT, T0, T1)

参数ROBOT为构建的机器人对象。T0和T1为运动的开始时间和停止时间。T为返回的时间向量,Q为返回的关节位置向量,QD为返回的关节速度向量。

QDD = ACCEL(ROBOT, Q, QD, TORQUE)

参数ROBOT为构建的机器人对象。Q为关节位置向量。QD为关节速度响亮。TORQUE为关节力矩向量。QDD为返回关节加速度向量。

动力学逆问题:已知机械手的运动轨迹,几个关节的位移、速度和加速度,求各关节所需要的驱动力或力矩。

利用Robotics Toolbox进行动力学逆问题的求解,需要用到其中的RNE函数,它的调用格式:TAU = RNE(ROBOT, Q, QD, QDD)

参数ROBOT为构建的机器人对象。Q为关节位置向量。QD为关节速度向量。QDD为关节加速度向量。TAU为返回的力矩向量。

六 轨迹规划问题

机器人轨迹规划的任务就是根据机器人手臂要完成的一定任务,譬如要求手从一点运动到另一点或沿一条连续轨迹运动,来设计机器人各关节的运动规律。目前进行轨迹规划的方案主要有两种:基于关节空间方案和基于直角坐标方案。 A 基于关节空间方案

机器人移动物体时,一般不能直接地、水平地将物体从一点移动到另一点,它必须先将物体举起,然后再按一定形状移动到终点位置上,因此当机器人手爪按PTP方式运动时,规划出的轨迹必须满足起点和终点的位置、速度、加速度的要求以及抬起点和下降点的位置坐标条件。

利用Robotics Toolbox进行基于关节空间方案的轨迹规划时,需要用到JTRAJ函数,调用格式:[Q QD QDD] = JTRAJ(Q0, Q1, N)

参数Q0和Q1为起始点和终止点,N为采样点。Q为返回的关节位置向量。QD为返回的关节速度向量。QDD为返回的关节加速度向量。 B 基于直角坐标方案

这 种方案的轨迹是以作为时间的函数的直角坐标位置和姿势来描述的。因此,这种方案适用于连续轨迹运动,即不仅要求机器人到达目标点,而且必须沿着我们所希望 的路径在一定精度范围内移动。为了保证这一点,就必须以轨迹更新的速率来反复求解运动学逆问题,以求得期望的关节转角和关节角增量,这就使计算量比较大。

利用Robotics Toolbox进行基于直角坐标方案的轨迹规划时,需要用到CTRAJ函数,调用格式:TC = CTRAJ(T0, T1, N)

参数T0和T1为笛卡尔空间中的起始点和终止点,N为采样点的数目。TC为返回的笛卡尔空间的各点。

七 仿真程序

程序运行界面如下: A 运动学正问题仿真

假定从点[0 0 0 0 0 0]到点[0 pi/2 –pi/2 0 0 0]的时间为2秒,采样时间为56毫秒。 B 运动学逆问题仿真

假定手坐标的起始点坐标是(0.6,-0.5,0),终止点坐标是(0.4,0.5,0.2),运动时间是2秒,采样时间是56毫秒。 C 动力学正问题仿真 D 动力学逆问题

假定从点[0 0 0 0 0 0]到点[0 pi/2 –pi/2 0 0 0]的时间为2秒,采样时间为56毫秒。

Robotics Toolbox for Matlab

1 Transformations

% In the field of robotics there are many possible ways of representing % positions and orientations, but the homogeneous transformation is well % matched to MATLAB’s powerful tools for matrix manipulation.

% Homogeneous transformations describe the relationships between Cartesian % coordinate frames in terms of translation and orientation.

% A pure translation of 0.5m in the X direction is represented by transl(0.5, 0.0, 0.0) ans =

1.0000 0 0 0.5000 0 1.0000 0 0 0 0 1.0000 0 0 0 0 1.0000

% a rotation of 90degrees about the Y axis by roty(pi/2) ans =

0.0000 0 1.0000 0 0 1.0000 0 0

-1.0000 0 0.0000 0 0 0 0 1.0000

% and a rotation of -90degrees about the Z axis by rotz(-pi/2) ans =

0.0000 1.0000 0 0 -1.0000 0.0000 0 0 0 0 1.0000 0 0 0 0 1.0000

% these may be concatenated by multiplication

t = transl(0.5, 0.0, 0.0) * roty(pi/2) * rotz(-pi/2) t =

0.0000 0.0000 1.0000 0.5000 -1.0000 0.0000 0 0

-0.0000 -1.0000 0.0000 0 0 0 0 1.0000

% If this transformation represented the origin of a new coordinate frame with respect

% to the world frame origin (0, 0, 0), that new origin would be given by t * [0 0 0 1]' ans = 0.5000 0

0

1.0000

% the orientation of the new coordinate frame may be expressed in terms of % Euler angles tr2eul(t) ans =

0 1.5708 -1.5708

% or roll/pitch/yaw angles tr2rpy(t) ans =

-1.5708 0.0000 -1.5708

% It is important to note that tranform multiplication is in general not % commutative as shown by the following example rotx(pi/2) * rotz(-pi/8) ans =

0.9239 0.3827 0 0

-0.0000 0.0000 -1.0000 0 -0.3827 0.9239 0.0000 0 0 0 0 1.0000

rotz(-pi/8) * rotx(pi/2) ans =

0.9239 0.0000 -0.3827 0 -0.3827 0.0000 -0.9239 0 0 1.0000 0.0000 0 0 0 0 1.0000

2 Trajectory

% The path will move the robot from its zero angle pose to the upright (or % READY) pose.

% First create a time vector, completing the motion in 2 seconds with a % sample interval of 56ms. t = [0:.056:2];

% A polynomial trajectory between the 2 poses is computed using jtraj() q = jtraj(qz, qr, t);

% For this particular trajectory most of the motion is done by joints 2 and 3, % and this can be conveniently plotted using standard MATLAB operations subplot(2,1,1) plot(t,q(:,2)) title('Theta')

xlabel('Time (s)'); ylabel('Joint 2 (rad)') subplot(2,1,2) plot(t,q(:,3))

xlabel('Time (s)');

ylabel('Joint 3 (rad)')

% We can also look at the velocity and acceleration profiles. We could

% differentiate the angle trajectory using diff(), but more accurate results % can be obtained by requesting that jtraj() return angular velocity and % acceleration as follows

[q,qd,qdd] = jtraj(qz, qr, t);

% which can then be plotted as before subplot(2,1,1) plot(t,qd(:,2)) title('Velocity') xlabel('Time (s)');

ylabel('Joint 2 vel (rad/s)') subplot(2,1,2) plot(t,qd(:,3)) xlabel('Time (s)');

ylabel('Joint 3 vel (rad/s)') pause(2)

% and the joint acceleration profiles subplot(2,1,1) plot(t,qdd(:,2))

title('Acceleration') xlabel('Time (s)');

ylabel('Joint 2 accel (rad/s2)') subplot(2,1,2) plot(t,qdd(:,3)) xlabel('Time (s)');

ylabel('Joint 3 accel (rad/s2)')

3 Forward kinematics

% Forward kinematics is the problem of solving the Cartesian position and % orientation of a mechanism given knowledge of the kinematic structure and % the joint coordinates.

% Consider the Puma 560 example again, and the joint coordinates of zero, % which are defined by qz qz qz =

0 0 0 0 0 0

% The forward kinematics may be computed using fkine() with an appropropriate % kinematic description, in this case, the matrix p560 which defines % kinematics for the 6-axis Puma 560. fkine(p560, qz) ans =

1.0000 0 0 0.4521 0 1.0000 0 -0.1500

0 0 1.0000 0.4318 0 0 0 1.0000

% returns the homogeneous transform corresponding to the last link of the % manipulator

% fkine() can also be used with a time sequence of joint coordinates, or % trajectory, which is generated by jtraj() t = [0:.056:2]; % generate a time vector

q = jtraj(qz, qr, t); % compute the joint coordinate trajectory

% then the homogeneous transform for each set of joint coordinates is given by T = fkine(p560, q);

% where T is a 3-dimensional matrix, the first two dimensions are a 4x4 % homogeneous transformation and the third dimension is time. % For example, the first point is T(:,:,1) ans =

1.0000 0 0 0.4521 0 1.0000 0 -0.1500 0 0 1.0000 0.4318 0 0 0 1.0000

% and the tenth point is T(:,:,10) ans =

1.0000 -0.0000 0 0.4455 -0.0000 1.0000 0 -0.1500 0 0 1.0000 0.5068 0 0 0 1.0000

% Elements (1:3,4) correspond to the X, Y and Z coordinates respectively, and % may be plotted against time subplot(3,1,1)

plot(t, squeeze(T(1,4,:))) xlabel('Time (s)'); ylabel('X (m)') subplot(3,1,2)

plot(t, squeeze(T(2,4,:))) xlabel('Time (s)'); ylabel('Y (m)') subplot(3,1,3)

plot(t, squeeze(T(3,4,:))) xlabel('Time (s)'); ylabel('Z (m)')

% or we could plot X against Z to get some idea of the Cartesian path followed % by the manipulator. subplot(1,1,1)

plot(squeeze(T(1,4,:)), squeeze(T(3,4,:)));

xlabel('X (m)') ylabel('Z (m)') grid

4 Animation

% The trajectory demonstration has shown how a joint coordinate trajectory % may be generated

t = [0:.056:2]'; % generate a time vector

q = jtraj(qz, qr, t); % generate joint coordinate trajectory

% the overloaded function plot() animates a stick figure robot moving % along a trajectory. plot(p560, q);

% The drawn line segments do not necessarily correspond to robot links, but % join the origins of sequential link coordinate frames.

% A small right-angle coordinate frame is drawn on the end of the robot to show % the wrist orientation.

% A shadow appears on the ground which helps to give some better idea of the % 3D object.

% We can also place additional robots into a figure.

% Let's make a clone of the Puma robot, but change its name and base location p560_2 = p560;

p560_2.name = 'another Puma';

p560_2.base = transl(-0.5, 0.5, 0); hold on

plot(p560_2, q);

% We can also have multiple views of the same robot clf

plot(p560, qr); figure

plot(p560, qr); view(40,50) plot(p560, q)

% Sometimes it's useful to be able to manually drive the robot around to % get an understanding of how it works. drivebot(p560)

% use the sliders to control the robot (in fact both views). Hit the red quit % button when you are done.

5 Inverse kinematics

% Inverse kinematics is the problem of finding the robot joint coordinates, % given a homogeneous transform representing the last link of the manipulator. % It is very useful when the path is planned in Cartesian space, for instance % a straight line path as shown in the trajectory demonstration.

% First generate the transform corresponding to a particular joint coordinate, q = [0 -pi/4 -pi/4 0 pi/8 0] q =

0 -0.7854 -0.7854 0 0.3927 0 T = fkine(p560, q);

% Now the inverse kinematic procedure for any specific robot can be derived % symbolically and in general an efficient closed-form solution can be % obtained. However we are given only a generalized description of the

% manipulator in terms of kinematic parameters so an iterative solution will % be used. The procedure is slow, and the choice of starting value affects % search time and the solution found, since in general a manipulator may % have several poses which result in the same transform for the last

% link. The starting point for the first point may be specified, or else it % defaults to zero (which is not a particularly good choice in this case) qi = ikine(p560, T); qi' ans = 0.0000 -0.7854 -0.7854 0.0000 0.3927 -0.0000

% Compared with the original value q q =

0 -0.7854 -0.7854 0 0.3927 0

% A solution is not always possible, for instance if the specified transform % describes a point out of reach of the manipulator. As mentioned above % the solutions are not necessarily unique, and there are singularities % at which the manipulator loses degrees of freedom and joint coordinates % become linearly dependent.

% To examine the effect at a singularity lets repeat the last example but for a % different pose. At the `ready' position two of the Puma's wrist axes are % aligned resulting in the loss of one degree of freedom. T = fkine(p560, qr); qi = ikine(p560, T); qi' ans = -0.0000 1.5238 -1.4768 -0.0000 -0.0470

本文来源:https://www.bwwdw.com/article/68r2.html

Top