MATLAB机器人工具箱(记一次轨迹生成2)

1、前记:

        这篇博文是为验证Baxter逆解时的一个记录,同 MATLAB机器人工具箱使用(记一次轨迹生成1)中一样,规划好轨迹后,机器人在运动时留下末端运动的轨迹。俩者不同点就进行末端笛卡尔轨迹规划时采用的方式不一样,即生成的末端轨迹点集的位姿矩阵不一样。上一个是直接使用机器人工具箱的jtraj()函数生成的末端轨迹,然后逆解求出关节角再plot出运动轨迹。这里采用的是 Robotics System Toolbox中的机器人运动(2)---圆的轨迹跟踪中的方式生成的末端轨迹。

         其中需要注意的就是末端点集如何生成齐次变换矩阵,然后调用逆解求出各关节角度、、、、关于坐标系变换与姿态表示方式的详细可以参看机器人中的坐标转换关系(个人记录学习)

2、代码:

%% =========================我是分割线===============================%%
%Left Arm建立机器人模型
%             Theta d     a                                  alpha r/p  theta offset
Ll(1) = Link ([0    0.27035  0.069                             -pi/2  0    0], 'standard'); % start at joint s0 and move to joint s1
Ll(2) = Link ([0    0        0                                  pi/2  0    pi/2], 'standard');        % start at joint s1 and move to joint e0
Ll(3) = Link ([0    0.36435  0.0690                            -pi/2  0    0], 'standard'); % start at joint e0 and move to joint e1
Ll(4) = Link ([0    0        0                                  pi/2  0    0], 'standard');           % start at joint e1 and move to joint w0
Ll(5) = Link ([0    0.37429  0.010                             -pi/2  0    0], 'standard');  % start at joint w0 and move to joint w1
Ll(6) = Link ([0    0        0                                  pi/2  0    0], 'standard');           % start at joint w1 and move to joint w2
Ll(7) = Link ([0    0.229525 0                                  0     0    0], 'standard');         % start at joint w2 and move to end-effector

Baxter_Left = SerialLink(Ll, 'name', 'Baxter Left Arm', 'base' , ...
                      transl(0.024645, 0.219645, 0.118588) * trotz(pi/4)...
                      * transl(0.055695, 0, 0.011038));
%% =========================我也是分割线=============================%%
%% 定义圆
t = (0:0.5:100)'; 
count = length(t);
center = [0.3 -0.2 -0.05];
radius = 0.16;
theta = t*(2*pi/t(end));
points =(center + radius*[cos(theta) sin(theta) zeros(size(theta))])';  
%% 期望的圆轨迹
figure
title("规划的末端运动轨迹");
xlabel('x/米','FontSize',12);
ylabel('y/米','FontSize',12);
zlabel('z/米','FontSize',12); 
for i = 1:size(points,2)
axis([-0.8 0.8 -1 1 -1 1.5])
hold on
xlabel('x/米','FontSize',12);
ylabel('y/米','FontSize',12);
zlabel('z/米','FontSize',12);  
plot3(points(1,:),points(2,:),points(3,:),'r')
grid on
end
%% 使用Peter工具箱逆解进行轨迹重现       
figure
axis([-0.5 1 -0.8 1 -0.6 0.8])
% utuck=[-0.08, -1.0, -1.19, 1.94,  0.67, 1.03, -0.50]
% Baxter_Left.teach(utuck)
% Baxter_Left.fkine(utuck)
title("工具箱机器人模型末端运动轨迹");
xlabel('x/米','FontSize',12);
ylabel('y/米','FontSize',12);
zlabel('z/米','FontSize',12); 
for i = 1:size(points,2)
    pause(0.01)
    bx = points(1,i); 
    by = points(2,i);
    bz =-0.08;
targetPos = [bx by bz];
% Q=[1 0 1 0];四元数表示
% tform = quat2tform(Q)
%EUL=[-119.5,-177.1,178.5];
% EUL=[-150,-170,170];
% R = eul2tr(EUL, 'deg');
targetOr = [0.02 -0.14 0.99 -0.01]
tform = quat2tform(targetOr)
TR=transl(targetPos)*tform;
hold on
grid on
plot3(bx,by,bz,'*','LineWidth',2);
q=Baxter_Left.ikine(TR)
pause(0.01)
Baxter_Left.plot(q);%动画演示
end

3、结果

后记:轨迹点集的方式有很多收到,像上述的直接代码规划,可以利用MATLAB鼠标事件应用(记录)中使用鼠标产生轨迹,也可以使用视觉跟踪的/自主规划的,也可以利用其他传感器获得等等。虽然机器人的逆解可以直接调用工具箱函数,但在实际应用中逆解往往存在无解,多解的情况,其中的逆解选择也是一个重点难点,这就是机器人发展如此成熟下,依然有一定难度的一个小小小小方面。

如下是笔记本自带相机拍的个人头像生成的一个头像点集。人脸分割与轮廓提取质量有些差。

注:(数据多,逆解慢,执行费时)

猜你喜欢

转载自blog.csdn.net/weixin_39090239/article/details/94167419