Matlab Robotic Toolbox工具箱学习笔记.docx

上传人:b****8 文档编号:9533336 上传时间:2023-02-05 格式:DOCX 页数:16 大小:1.08MB
下载 相关 举报
Matlab Robotic Toolbox工具箱学习笔记.docx_第1页
第1页 / 共16页
Matlab Robotic Toolbox工具箱学习笔记.docx_第2页
第2页 / 共16页
Matlab Robotic Toolbox工具箱学习笔记.docx_第3页
第3页 / 共16页
Matlab Robotic Toolbox工具箱学习笔记.docx_第4页
第4页 / 共16页
Matlab Robotic Toolbox工具箱学习笔记.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

Matlab Robotic Toolbox工具箱学习笔记.docx

《Matlab Robotic Toolbox工具箱学习笔记.docx》由会员分享,可在线阅读,更多相关《Matlab Robotic Toolbox工具箱学习笔记.docx(16页珍藏版)》请在冰豆网上搜索。

Matlab Robotic Toolbox工具箱学习笔记.docx

MatlabRoboticToolbox工具箱学习笔记

MatlabRoboticToolbox工具箱学习笔记

(一)

软件:

matlab2013a

工具箱:

MatlabRoboticToolboxv9.8

MatlabRoboticToolbox工具箱学习笔记根据RobotToolbox

demonstrations目录,将分三大部分阐述:

1、General(Rotations,Transformations,Trajectory)

2、Arm(Robot,Animation,Forwarwkinematics,Inverse

kinematics,Jacobians,Inversedynamics,Forwarddynamics,Symbolic,Code

generation)

3、Mobile(Drivingtoa

pose,Quadrotor,Braitenberg,Bug,D*,PRM,SLAM,Particlefilter)

General/Rotations

%绕x轴旋转pi/2得到的旋转矩阵

(1)r=rotx(pi/2);

%matlab默认的角度单位为弧度,这里可以用度数作为单位

(2)R=rotx(30,'deg')*roty(50,'deg')*rotz(10,'deg');

%求出R等效的任意旋转变换的旋转轴矢量vec和转角theta

(3)[theta,vec]=tr2angvec(R);

%旋转矩阵用欧拉角表示,R=rotz(a)*roty(b)*rotz(c)

(4)eul=tr2eul(R);

%旋转矩阵用roll-pitch-yaw角表示,R=rotx(r)*roty(p)*rotz(y)

(5)rpy=tr2rpy(R);

%旋转矩阵用四元数表示

)(q=Quaternion(R);6

%将四元数转化为旋转矩阵

(7)q.R;

界面,可以是“rpy”,“eluer”角度单位为度。

%

(8)tripleangle('rpy');

General/Transformations

%沿x轴平移0.5,绕y轴旋转pi/2,绕z轴旋转-pi/2

(1)t=transl(0.5,0.0,0.0)*troty(pi/2)*trotz(-pi/2)

%将齐次变换矩阵转化为欧拉角

(2)tr2eul(t)

%将齐次变换矩阵转化为roll、pitch、yaw角

(3)tr2rpy(t)

General/Trajectory

clear;

clc;

p0=-1;%定义初始点及终点位置

p1=2;

p=tpoly(p0,p1,50);%取步长为50

figure

(1);

plot(p);%绘图,可以看到在初始点及终点的一、二阶导均为零

[p,pd,pdd]=tpoly(p0,p1,50);%得到位置、速度、加速度

%p为五阶多项式,速度、加速度均在一定范围内

figure

(2);

subplot(3,1,1);plot(p);xlabel('Time');ylabel('p');

subplot(3,1,2);plot(pd);xlabel('Time');ylabel('pd');

subplot(3,1,3);plot(pdd);xlabel('Time');ylabel('pdd');

%另外一种方法:

[p,pd,pdd]=lspb(p0,p1,50);

figure(3);

subplot(3,1,1);plot(p);xlabel('Time');ylabel('p');

subplot(3,1,2);plot(pd);xlabel('Time');ylabel('pd');%可以看到速度是呈梯形

subplot(3,1,3);plot(pdd);xlabel('Time');ylabel('pdd');

%三维的情况:

p=mtraj(@tpoly,[012],[210],50);

figure(4);

plot(p)

%对于齐次变换矩阵的情况

T0=transl(0.4,0.2,0)*trotx(pi);%定义初始点和目标点的位姿

T1=transl(-0.4,-0.2,0.3)*troty(pi/2)*trotz(-pi/2);

T=ctraj(T0,T1,50);

first=T(:

:

1);%初始位姿矩阵

tenth=T(:

:

10);%第十个位姿矩阵

figure(5);

tranimate(T);%动画演示坐标系自初始点运动到目标点的过程

MatlabRoboticToolbox工具箱学习笔记

(二)

Arm/Robots

机器人是由多个连杆连接而成的,机器人关节分为旋转关节和移动关节。

创建机器人的两个最重要的函数是:

Link和SerialLink。

1、Link类

一个Link包含了机器人的运动学参数、动力学参数、刚体惯性矩参数、电机和传动参数。

操作函数:

%A连杆变换矩阵

%RP关节类型:

'R'或'P'

%friction摩擦力

%nofriction摩擦力忽略

%dyn显示动力学参数

%islimit测试关节是否超出软限制

%isrevolute测试是否为旋转关节

%isprismatic测试是否为移动关节

%display连杆参数以表格形式显示

%char转为字符串

运动学参数:

%theta关节角度

%d连杆偏移量

%a连杆长度

%alpha连杆扭角

%sigma旋转关节为0,移动关节为1

%mdh标准的D&H为0,否则为1

%offset关节变量偏移量

%qlim关节变量范围[minmax]

动力学参数:

%m连杆质量

%r连杆相对于坐标系的质心位置3x1

%I连杆的惯性矩阵(关于连杆重心)3x3

%B粘性摩擦力(对于电机)1x1或2x1

%Tc库仑摩擦力1x1或2x1

电机和传动参数:

%G齿轮传动比

%Jm电机惯性矩(对于电机)

2、SerialLink类

操作函数:

%plot以图形形式显示机器人

%teach驱动机器人

%isspherical测试机器人是否有球腕关节

%islimit测试机器人是否抵达关节极限

%fkine前向运动学求解

%ikine6s6旋转轴球腕关节机器人的逆向运动学求解

%ikine33旋转轴机器人的逆向运动学求解

%ikine采用迭代方法的逆向运动学求解

%jacob0在世界坐标系描述的雅克比矩阵

%jacobn在工具坐标系描述的雅克比矩阵

%maniplty可操纵性度

%jtraj关节空间轨迹

%accel关节加速度

%coriolis关节柯氏力

%dyn显示连杆的动力学属性

%fdyn关节运动

%friction摩擦力

%gravload关节重力

%inertia关节惯性矩阵

%nofriction设置摩擦力为0

%rne关节的力/力矩

%payload在末端坐标系增加负载

%perturb随机扰动连杆的动力学参数

属性:

%links连杆向量(1xN)

%gravity重力的方向[gxgygz]

%base机器人基座的位姿(4x4)

%tool机器人的工具变换矩阵[T6totooltip](4x4)

%qlim关节范围[qminqmax](Nx2)

%offset偏置(Nx1)

%name机器人名字(在图形中显示)

%manuf注释,制造商名

%comment注释,总评

%plotoptoptionsforplot()method(cellarray)

%n关节数

%config机器人结构字符串,例如'RRRRRR'

%mdh运动学中约定的布尔数(0=DH,1=MDH)

怎样创建一个机器人?

%Link调用格式:

%{

(1)L=Link()创建一个带默认参数的连杆

(2)L=Link(L1)复制连杆L1

(3)L=Link(OPTIONS)创建一个指定运动学、动力学参数的连杆

OPTIONS可以是:

%'theta',THjointangle,ifnotspecifiedjointisrevolute

%'d',Djointextension,ifnotspecifiedjointisprismatic

%'a',Ajointoffset(default0)

%'alpha',Ajointtwist(default0)

%'standard'definedusingstandardD&Hparameters(default).

%'modified'definedusingmodifiedD&Hparameters.

%'offset',Ojointvariableoffset(default0)

%'qlim',Ljointlimit(default[])

%'I',Ilinkinertiamatrix(3x1,6x1or3x3)

%'r',Rlinkcentreofgravity(3x1)

%'m',Mlinkmass(1x1)

%'G',Gmotorgearratio(default0)

%'B',Bjointfriction,motorreferenced(default0)

%'Jm',Jmotorinertia,motorreferenced(default0)

%'Tc',TCoulombfriction,motorreferenced(1x1or2x1),(default[00])

%'revolute'forarevolutejoint(default)

%'prismatic'foraprismaticjoint'p'

%'standard'forstandardD&Hparameters(default).

%'modified'formodifiedD&Hparameters.

%'sym'considerallparametervaluesassymbolicnotnumeric

注:

不能同时指定“theta”和“d”

连杆的惯性矩阵(3x3)是对称矩阵,可以写成3x3矩阵,也可以是[IxxIyyIzzIxyIyz

Ixz]

所有摩擦均针对电机而不是负载

齿轮传动比只用于传递电机的摩擦力和惯性矩给连杆坐标系。

%}

%SerialLink调用格式:

%{

(1)R=SerialLink(LINKS,OPTIONS),OPTIONS可以是:

'name'、'comment'、'manufacturer'

'base'、'tool'、'gravity'、'plotopt'

(2)R=SerialLink(DH,OPTIONS),矩阵DH的构成:

每个关节一行,每一行为[thetad

aalpha]

(默认为旋转关节),第五列(sigma)为可选列,sigma=0(默认)为旋转关节,sigma=1为移动关节

R=SerialLink(OPTIONS))没有连杆的机器人3(

(4)R=SerialLink([R1R2...],OPTIONS)机器人连接,将R2的基座连接到R1的末端.

(5)R=SerialLink(R1,options)复制机器人R1

%}

L1=Link('d',0,'a',1,'alpha',pi/2);%定义连杆1,没有写theta说明theta为关节变量

L1.a;%查看a的值

L1.d;%查看d的值

%还可以L1.RP,L1.display,L1.mdh,L1.isprismatic,L1.isrevolute等等,这样就可以查看一些默认值

L2=Link('d',0,'a',1,'alpha',0);

bot=SerialLink([L1L2],'name','myrobot');

bot.n;%查看连杆数目

bot.fkine([0.10.2]);%前向运动学

bot.plot([0.10.2]);%绘制机器人

定义完连杆和机器人便可以求机器人前和逆向运动学、动力学等等。

L1.参数或属性():

查看连杆的参数或属性

L1.操作函数(参数):

操作连杆参数

bot.属性():

查看机器人的属性

bot.操作函数(参数):

操作机器人,可以进行前向、逆向运动学求解等

实例:

StanfordManipulator

D-H参数表:

clear;

clc;

L1=Link('d',0,'a',0,'alpha',-pi/2);%定义连杆

L2=Link('d',1,'a',0,'alpha',pi/2);

L3=Link('theta',0,'a',0,'alpha',0);

L4=Link('d',0,'a',0,'alpha',-pi/2);

L5=Link('d',0,'a',0,'alpha',pi/2);

L6=Link('d',1,'a',0,'alpha',0);

bot=SerialLink([L1L2L3L4L5L6]);%连接连杆

bot.display();%显示D-H参数表

forward_kinematics=bot.fkine([-0.20.1100.112])%前向运动学

求出末端的齐次变换矩阵:

clear;

clc;

L1=Link('d',0,'a',0,'alpha',-pi/2,'sym');%定义连杆

L2=Link('d','d2','a',0,'alpha',pi/2,'sym');

L3=Link('theta',0,'a',0,'alpha',0,'sym');

L4=Link('d',0,'a',0,'alpha',-pi/2,'sym');

L5=Link('d',0,'a',0,'alpha',pi/2,'sym');

L6=Link('d','d6','a',0,'alpha',0,'sym');

bot=SerialLink([L1L2L3L4L5L6]);%连接连杆

symstheta1theta2d3theta4theta5theta6;

forward_kinematics=bot.fkine([theta1theta2d3theta4theta5theta6])%前向运动学

Stanfordarm的运动学逆解:

clear;

clc;

clearL

%thdaalpha

L

(1)=Link([000-pi/20]);%定义连杆

L

(2)=Link([010pi/20]);

L(3)=Link([00001]);

L(4)=Link([000-pi/20]);

L(5)=Link([000pi/20]);

L(6)=Link([01000]);

bot=SerialLink(L,'name','Stanfordarm');%连接连杆

T=transl(1,2,3)*trotz(60,'deg')*troty(30,'deg')*trotz(90,'deg')

inverse_kinematics=bot.ikine(T,'pinv');%逆向运动学

theta1=inverse_kinematics

(1);

theta2=inverse_kinematics

(2);

d3=inverse_kinematics(3);

theta4=inverse_kinematics(4);

theta5=inverse_kinematics(5);

theta6=inverse_kinematics(6);

forward_kinematics=bot.fkine([theta1theta2d3theta4theta5theta6])%前向运动学,验证结果的准确性.

%求解结果为T与forward_kinematics一致。

正确。

求解Stanfordarm在世界坐标系描述的雅克比矩阵

clear;

clc;

clearL

%thdaalpha

L

(1)=Link([000-pi/20]);%定义连杆

L

(2)=Link([010pi/20]);

L(3)=Link([00001]);

L(4)=Link([000-pi/20]);

L(5)=Link([000pi/20]);

L(6)=Link([01000]);

bot=SerialLink(L,'name','Stanfordarm');%连接连杆

symstheta1theta2d3theta4theta5theta6;

J0=vpa(bot.jacob0([theta1theta2d3theta4theta5theta6]),4)

求平面二自由度机器人在世界坐标系描述的雅克比矩阵

D-H参数表:

clear;

clc;

clearL

L

(1)=Link('d',0,'a','a1','alpha',0,'sym');%定义连杆

L

(2)=Link('d',0,'a','a2','alpha',0,'sym');

bot=SerialLink(L,'name','Planar2-dofrobot');%连接连杆

symstheta1theta2;

J0=bot.jacob0([theta1theta2]);

J0=simplify(J0)

求得:

J0=

[-a2*sin(theta1+theta2)-a1*sin(theta1),-a2*sin(theta1+theta2)]

[a2*cos(theta1+theta2)+a1*cos(theta1),a2*cos(theta1+theta2)]

[0,0]

[0,0]

[0,0]

[1,1]

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 育儿理论经验

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1