目录

平面机械臂运动学分析

平面机械臂运动学分析

一 整体概述

1 研究步骤:

1 正向:根据所读取的关节处 角度 ,立刻计算出末端坐标,可随时计算得出当前末端坐标值,方便用于计算。

2 逆向:根据末端 坐标 ,计算出 关节 角度 的值,已知终点坐标,计算出各关节角度写入,以到达指定位置。

3 规划路径曲线点,设置曲线路径,使各关节移动丝滑,稳定、快速的到达指定位置。

4 误差补偿,通过PID等算法,补偿摩擦力重力等环境因素带来的影响,优化精度。


二 正向

1 简介:根据已知 角度杆长 ,计算得出机械臂末端位置的 位置 变化,角度可由传感器采集。

2 效果:输入各个关节的角度值,可以计算出机械臂末端执行器的位置和姿态。

1 几何分析

(1)一种简单几何计方法:

https://i-blog.csdnimg.cn/direct/1bec76177ca14490a8e411ad82527cfd.png

(2) 计算公式

https://i-blog.csdnimg.cn/direct/6123c0622d38434fb4c0115b98ca55f5.png

【X,Y】末端坐标

【l1 l2 l3】 连杆长

【θ1 θ2 θ3 】关节角度


2 matlab 仿真模拟

本节使用matlab制作一个方便查看视觉效果的:简易平面三连杠机械臂模型

(1)实现效果

可修改臂长参数,输入 关节 角度值,快速查看末端 坐标 ,并支持滑块实时测试效果:

https://i-blog.csdnimg.cn/direct/59633831394744e7bec00d89d5902d8c.gif#pic_center

(2)matlab代码:

function forward_direction
%----------------------1 初始参数设置---------------------------
    l1=50; l2=50; l3=50; %已知信息:臂长
    degree1 = deg2rad(0);%各关节角度
    degree2 = deg2rad(0);
    degree3 = deg2rad(0);
    
    %求出4个点坐标
    bx = l1*sin(degree1); % B点坐标,A为(0,0)
	by = l1*cos(degree1);
	cx = bx+l2*sin(degree1+degree2);% C点坐标
	cy = by+l2*cos(degree1+degree2);
	dx = cx+l3*sin(degree1+degree2+degree3);% D点坐标
	dy = cy+l3*cos(degree1+degree2+degree3);
%-----------------------2初始图像设置---------------------------
    x = linspace(0, 150, 1500);  % X轴范围包含所有分段
    y = zeros(size(x));         % 初始化Y数组
    figure('Position', [0 0 600 600]);
    axe = axes('Position', [0.1 0.3 0.8 0.6]);
    sport_plot = plot(x,y,'.', 'LineWidth', 2);
    update();%计算初始参数点,设置分段函数
    set(sport_plot, 'YData', y);
    axis('equal',[0 200 -150 150]); % 设置坐标轴范围 [x1,x2],[y1,y2]
    title('正向运动学分析'); % 标题
    xlabel('X坐标'); % x轴标签
    ylabel('Y坐标'); % y轴标签
    grid on; % 显示网格
%-------------------------3 更新参数点,设置分段函数----------------
    function [] =update()
        bx = l1*sin(degree1); % B点坐标,A为(0,0)
        by = l1*cos(degree1);
        cx = bx+l2*sin(degree1+degree2);% C点坐标
        cy = by+l2*cos(degree1+degree2);
        dx = cx+l3*sin(degree1+degree2+degree3);% D点坐标
        dy = cy+l3*cos(degree1+degree2+degree3);
        y = zeros(size(x));
        %x = linspace(0, dx, 1500);
        idx1 = (x >= 0 ) & (x <= bx);
        idx2 = (x >= bx) & (x <=cx); 
        idx3 = (x >= cx) & (x <=dx);
        idx4 = x >dx;
        y(idx1) = tan(pi/2-degree1)*x(idx1);         % 注意使用 .^
        y(idx2) = tan(pi/2-degree1-degree2)*(x(idx2)-bx)+by;    % 线性计算
        y(idx3) = tan(pi/2-degree1-degree2-degree3)*(x(idx3)-cx)+cy;
        y(idx4) = 999;
        title(axe, ['末端坐标(x,y)=(', num2str(dx), ',', num2str(dy), ')']);
    end
%--------------------------4 滑块-----------------------------------------
    % 添加degree1滑块
    uicontrol('Style', 'slider', ...
        'Position', [190 110 200 20], ...
        'Min', 0, 'Max', 180, 'Value', degree1, ...
        'Callback', @updatedegree1);
    uicontrol('Style', 'text', ...
        'Position', [140 110 42 15], ...
        'String', 'degree1');
    % 回调函数1
    function updatedegree1(hObj, ~)
        tem = hObj.Value; 
        degree1=deg2rad(hObj.Value);%更新角度
        update();
        set(sport_plot, 'YData', y);
        uicontrol('Style','text','String',num2str(tem),'Position',[400 110 40 15]);
    end

 % 添加degree2滑块
    uicontrol('Style', 'slider', ...
        'Position', [190 60 200 20], ...
        'Min', 0, 'Max', 180, 'Value', degree2, ...
        'Callback', @updatedegree2);
    uicontrol('Style', 'text', ...
        'Position', [140 60 42 15], ...
        'String', 'degree2');
    % 回调函数1
    function updatedegree2(hObj, ~)
        tem = hObj.Value; 
        degree2=deg2rad(hObj.Value);%更新角度
        update();
        set(sport_plot, 'YData', y);
        uicontrol('Style','text','String',num2str(tem),'Position',[400 60 40 15]);
    end

% 添加degree3滑块
    uicontrol('Style', 'slider', ...
        'Position', [190 13 200 20], ...
        'Min', 0, 'Max', 180, 'Value', degree3, ...
        'Callback', @updatedegree3);
    uicontrol('Style', 'text', ...
        'Position', [140 13 42 15], ...
        'String', 'degree3');
    % 回调函数1
    function updatedegree3(hObj, ~)
        tem = hObj.Value; 
        degree3=deg2rad(hObj.Value);%更新角度
        update();
        set(sport_plot, 'YData', y);
        uicontrol('Style','text','String',num2str(tem),'Position',[400 13 40 15]);
    end
%------------------------------5 文本框输入------------------------------
    uicontrol('Style', 'text', ...
        'Position', [450 430 100 20], ...
        'String', 'set 1:');
    uicontrol('Style', 'edit', ...
        'Position', [450 400 100 30], ...
        'String', '0', ...
        'Callback', @setdegree1);

    % 定义回调函数
    function setdegree1(src, ~)
        % 获取输入值
        input_str = get(src, 'String');
        input_num = str2double(input_str);
        % 验证输入
        if isnan(input_num)
            errordlg('请输入有效数字!', '输入错误');
            return;
        end
        % 更新全局变量
        degree1 = deg2rad(input_num);
        update();
        set(sport_plot, 'YData', y);
    end

	uicontrol('Style', 'text', ...
        'Position', [450 370 100 20], ...
        'String', 'set 2:');
	uicontrol('Style', 'edit', ...
        'Position', [450 340 100 30], ...
        'String', '0', ...
        'Callback', @setdegree2);

    % 定义回调函数
    function setdegree2(src, ~)
        % 获取输入值
        input_str = get(src, 'String');
        input_num = str2double(input_str);
        % 验证输入
        if isnan(input_num)
            errordlg('请输入有效数字!', '输入错误');
            return;
        end
        % 更新全局变量
        degree2 = deg2rad(input_num);
        update();
        set(sport_plot, 'YData', y);
    end

	uicontrol('Style', 'text', ...
        'Position', [450 310 100 20], ...
        'String', 'set 3:');
	uicontrol('Style', 'edit', ...
        'Position', [450 280 100 30], ...
        'String', '0', ...
        'Callback', @setdegree3);

    % 定义回调函数
    function setdegree3(src, ~)
        % 获取输入值
        input_str = get(src, 'String');
        input_num = str2double(input_str);
        % 验证输入
        if isnan(input_num)
            errordlg('请输入有效数字!', '输入错误');
            return;
        end
        % 更新全局变量
        degree3 = deg2rad(input_num);
        update();
        set(sport_plot, 'YData', y);
    end

end

几何法正向分析比较简单,且此处仅以二维为例


3 DH矩阵计算法

DH参数:

  • 连杆长度(a)、 【连杆长度】
  • 连杆转角(alpha)【连杆转角】
  • 连杆偏移(d) 【关节偏移】
  • 关节角(theta) 【关节角】

1 对于旋转关节,theta是变量,而d是固定的;

2 对于移动关节,d是变量,theta固定。平面机械臂通常是【旋转关节】,所以theta会是变量。

3 平面二维机械臂只需考虑:连杆长度(a)与 关节角(theta)


(1)计算公式

  • <1> 每个关节的 坐标系变换 可通过 齐次变换矩阵 表示,通用形式为:

    https://i-blog.csdnimg.cn/direct/59844ca3f4aa4f8d84635fafbc38fff6.png

  • <2> 正运动 学末端执行器的位置姿态 计算公式 为:

    https://i-blog.csdnimg.cn/direct/f35f869c2b444ba8add043a5b2d2c79e.png

    Ti 每一项分别对应关节的变换矩阵,各连杆长度与角度参数带入公式<1>即可,如下图:

https://i-blog.csdnimg.cn/direct/af896bc7819a400a80f70c52df1a91b0.png

(2)计算结果验证

角度为:30,50,15

臂长:60,50,40

矩阵计算结果:Tend=T1 *T2 *T3:

https://i-blog.csdnimg.cn/direct/541875c2e9ed48b08333a090e0b2bce8.png

几何法对比

https://i-blog.csdnimg.cn/direct/70e6e6615c1445bb803f1143bfb645d4.png

如图可知,结果验证无误

xy坐标 颠倒 原因是:所用几何法、与齐次矩阵变换中 关节角度 的选取方式不同,即θ设置不同,但计算数值大小一致。

(3)Tend矩阵末端位姿数据提取

  • 最终的4x4齐次矩阵Tend可分解为:3x3 旋转矩阵R 和 3x1 位置向量P

    https://i-blog.csdnimg.cn/direct/d9f8182ba36c4968b8678683bf19f9ae.png

  • 以上一步计算出的 最终其次矩阵 Tend为例:

    https://i-blog.csdnimg.cn/direct/602422914f7044dbaa8333d4166c28b5.png

从Tend矩阵中可提取对应位置信息,与旋转信息

(4)matlab计算代码

l1=60; l2=50; l3=40;  %已知信息:臂长
degree1 = deg2rad(30);%各关节角度设置
degree2 = deg2rad(50);
degree3 = deg2rad(15);
%DH参数:
%a=L   臂长  
%α=0  连杆转角
%d=0   连杆偏移
%sitar=degree 关节角
T1=[cos(degree1)  -sin(degree1)*cos(0)    sin(degree1)*sin(0)   l1*cos(degree1)
    sin(degree1)  cos(degree1)*cos(0)     -cos(degree1)*sin(0)  l1*sin(degree1)
     0     sin(0)            cos(0)       0
     0      0               0            1];
T2=[cos(degree2)  -sin(degree2)*cos(0)    sin(degree2)*sin(0)  l2*cos(degree2)
    sin(degree2)  cos(degree2)*cos(0)     -cos(degree2)*sin(0) l2*sin(degree2)
     0     sin(0)            cos(0)       0
     0      0               0            1];
T3=[cos(degree3)  -sin(degree3)*cos(0)    sin(degree3)*sin(0)   l3*cos(degree3)
    sin(degree3)   cos(degree3)*cos(0)     -cos(degree3)*sin(0)  l3*sin(degree3)
     0     sin(0)            cos(0)       0
     0      0               0            1];
 Tend = T1*T2*T3   %齐次变换矩阵计算公式,末位位姿

三 逆向

DH参数模型:

https://i-blog.csdnimg.cn/direct/21ef42f7c1244bc2a49258c183afc7d1.png

公式为:

https://i-blog.csdnimg.cn/direct/eaa46b3a4b884d33bfe9b7f4393aeda7.png +

(x,y)为已知末端坐标, 求解三个关节角度

(待补充)