MatlabRobotic Toolbox工具箱学习笔记(一)

xiaoxiao2021-02-28  91

MatlabRobotic Toolbox工具箱学习笔记(一)

转自http://blog.sina.com.cn/s/blog_a16714bf0101hygu.html

软件:matlab2013a

工具箱:Matlab Robotic Toolboxv9.8

Matlab RoboticToolbox工具箱学习笔记根据Robot Toolbox demonstrations目录,将分三大部分阐述:

1、General(Rotations,Transformations,Trajectory)

2、Arm(Robot,Animation,Forwarwkinematics,Inverse kinematics,Jacobians,Inverse dynamics,Forwarddynamics,Symbolic,Code generation)

3、Mobile(Driving to apose,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);

%旋转矩阵用四元数表示

(6)q =Quaternion(R);

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

(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, [0 1 2], [2 1 0], 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);%动画演示坐标系自初始点运动到目标点的过程

转载请注明原文地址: https://www.6miu.com/read-76676.html

最新回复(0)