matlab实现三自由度机械臂旋转

matlab实现三自由度的机械臂旋转

1 内容与要求

根据表一机械臂长度,以及图一机械臂配置为机械臂开发一个控制器,使其能够执行特定的任务。更具体地说,让机械臂的末端执行器移动到特定的点。项目要求:
① 你的控制器应该能够控制一个3 自由度的机械臂到达给定的目的地。
② 你的代码应该要有足够的注释来解释它是怎么工作的。
③你的代码应该包括控制过程的可视化,这表示我们希望你的机械臂在3D
图形环境中移动。
④独立完成,按时提交,有特殊情况请提前说明。

三自由度的机械臂长度如下:
表一 机械臂长度
机械臂相关配置如下:
图一 机械臂配置
matlab源代码robot_hand.m:

startup_rvc
clear;clc;
syms theta1 alpha1 a1 d1 theta2 alpha2 a2 d2 theta3 alpha3 a3 d3 d;%参数变量
%三个方程,三个齐次方程组
A1=[cos(theta1),-sin(theta1)*cos(alpha1),sin(theta1)*sin(alpha1),a1*cos(theta1);
    sin(theta1),cos(theta1)*cos(alpha1),-cos(theta1)*sin(alpha1),a1*sin(theta1);
    0,          sin(alpha1),             cos(alpha1),            d1            ;
    0,          0,                       0,                       1           ];

A2=[cos(theta2),-sin(theta2)*cos(alpha2),sin(theta2)*sin(alpha2),a2*cos(theta2);
    sin(theta2),cos(theta2)*cos(alpha2),-cos(theta2)*sin(alpha2),a2*sin(theta2);
    0,          sin(alpha2),            cos(alpha2),             d2            ;
    0,          0,                      0,                        1           ];

A3=[cos(theta3),-sin(theta3)*cos(alpha3),sin(theta3)*sin(alpha3),a3*cos(theta3);
    sin(theta3),cos(theta3)*cos(alpha3),-cos(theta3)*sin(alpha3),a3*sin(theta3);
    0,          sin(alpha3),            cos(alpha3),             d3            ;
    0,          0,                       0,                       1           ];
%给变量赋值
a1=sym(0.5);alpha1=sym(pi/2);d1=sym(0);
a2=sym(1);alpha2=sym(-pi/2);d2=sym(0);
a3=sym(1);alpha3=sym(0);d3=sym(0);
T=eval(A1*A2*A3)%前三个自由度其次矩阵相乘,得到T(0,3),即末端执行器相对于原点的坐标
%矩阵最右边一列,为末端执行器的X,Y,Z坐标
X_axis=T(1,4)%末端执行器的X坐标
Y_axis=T(2,4)%末端执行器的Y坐标 
Z_axis=T(3,4)%末端执行器的Z坐标

%给定末端执行器的终点,没有加约束条件,会得到复数的解,后期需要修改。
[sola,solu,solv]=solve(X_axis==1,Y_axis==0,Z_axis==0,theta1,theta2,theta3)
%求到一共有4组解,即四组转动的角度,我们只用第一组的解
solutions=[sola,solu,solv]

double_x=double(sign(real(solutions(1,1)))*abs(solutions(1,1)))%原类型为syms,转变为double类型,x坐标,会出现复数的解
double_y=double(sign(real(solutions(1,2)))*abs(solutions(1,2)))%原类型为syms,转变为double类型,y坐标,会出现复数的解
double_z=double(sign(real(solutions(1,3)))*abs(solutions(1,3)))%原类型为syms,转变为double类型,z坐标,会出现复数的解

%D-H参数
L1=Link('d',0,'a',0.5,'alpha',pi/2);%Link类函数
L2=Link('d',0,'a',1,'alpha',-pi/2);
L3=Link('d',0,'a',1,'alpha',0);
robot=SerialLink([L1,L2,L3]);%SerialLink类函数,创建机器人可视化模型
robot.name='旋转的机械臂';%机械臂名字
%robot.manuf='xxxxxxx';%制造商名

init_ang=[0 0 0];%起始的角度
targ_ang=[double_x,double_y,double_z];%结束时转过的角度,我们取齐次方程组的第一组解
step=80;%时间矢量长度T
[q,qd,qdd] = jtraj(init_ang,targ_ang,step);%jtraj函数:计算两点之间一个关节的空间轨迹,利用5阶quintic多项式来表示速度和加速度。
                                           %q为空间轨迹,qd为速度,qdd为加速度
grid on
T=robot.fkine(q);%根据插值,求得末端执行器的位姿                                          
plot3(squeeze(T(1,4,:)),squeeze(T(2,4,:)),squeeze(T(3,4,:)));%画出末端轨迹
hold on
robot.plot(q,'tilesize',2);%动画演示

可能用到的文件robot_tool.m:

disp('Robotics, Vision & Control: (c) Peter Corke 1992-2011 http://www.petercorke.com')

if verLessThan('matlab', '7.0')
    warning('You are running a very old (and unsupported) version of MATLAB.  You will very likely encounter significant problems using the toolboxes but you are on your own with this');
end
tb = false;
rvcpath = fileparts( mfilename('fullpath') );

robotpath = fullfile(rvcpath, 'robot');
if exist(robotpath,'dir')
    addpath(robotpath);
    tb = true;
    startup_rtb
end

visionpath = fullfile(rvcpath, 'vision');
if exist(visionpath,'dir')
    addpath(visionpath);
    tb = true;
    startup_mvtb
end

if tb
    addpath(fullfile(rvcpath, 'common'));
    addpath(fullfile(rvcpath, 'simulink'));
end

clear tb rvcpath robotpath visionpath

机械臂末端旋转到(0.5,1,1)的效果图:
图一 机械臂末端转到(0.5,1,1)
机械臂旋转至(1,0,0)的俯视图
机械臂旋转至(1,0,0)的俯视图
具体实现过程可联系本作者

  • 13
    点赞
  • 127
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值