使用D-H矩阵计算正向运动学

问题描述 投票:0回答:1

我有一个6自由度机械臂模型:

robot arm structure

我想计算正向运动学,所以我使用D-H矩阵。 D-H 参数为:

static const std::vector<float> theta = {
0,0,90.0f,0,-90.0f,0};

// d
static const std::vector<float> d = {
380.948f,0,0,-560.18f,0,0};

// a
static const std::vector<float> a = {
-220.0f,522.331f,80.0f,0,0,94.77f};

// alpha
static const std::vector<float> alpha = {
90.0f,0,90.0f,-90.0f,-90.0f,0};

和计算:

glm::mat4 Robothand::armForKinematics() noexcept
{
    glm::mat4 pose(1.0f);
    float cos_theta, sin_theta, cos_alpha, sin_alpha;

    for (auto i = 0; i < 6;i++)
    {
        cos_theta = cosf(glm::radians(theta[i]));
        sin_theta = sinf(glm::radians(theta[i]));
        cos_alpha = cosf(glm::radians(alpha[i]));
        sin_alpha = sinf(glm::radians(alpha[i]));

        glm::mat4 Ai = {
cos_theta, -sin_theta * cos_alpha,sin_theta * sin_alpha, a[i] * cos_theta,      
sin_theta, cos_theta * cos_alpha, -cos_theta * sin_alpha,a[i] * sin_theta,
0,         sin_alpha,             cos_alpha,             d[i],
0,         0,                     0,                     1 };

    pose = pose * Ai;
    }

return pose;
}

我遇到的问题是,我无法得到正确的结果,例如,我想计算从第一个关节到第四个关节的变换矩阵,我会改变for循环i< 3,then I can get the pose matrix, and I can the origin coordinate in 4th coordinate system by pose * (0,0,0,1).but the result (380.948,382.331,0) seems not correct because it should be move along x-axis not y-axis. I have read many books and materials about D-H matrix, but I can't figure out what's wrong with it.

c++ robotics kinematics
1个回答
0
投票

我自己已经弄清楚了,背后真正的问题是glm::mat,glm::mat是col类型,这意味着列将在行之前初始化,我更改了代码并得到了正确的结果:

for (int i = 0; i < joint_num; ++i)
{
    pose = glm::rotate(pose, glm::radians(degrees[i]), glm::vec3(0, 0, 1));
    pose = glm::translate(pose,glm::vec3(0,0,d[i]));
    pose = glm::translate(pose, glm::vec3(a[i], 0, 0));
    pose = glm::rotate(pose,glm::radians(alpha[i]),glm::vec3(1,0,0));
}

然后我可以通过以下方式获得职位:

auto pos = pose * glm::vec4(x,y,z,1);
© www.soinside.com 2019 - 2024. All rights reserved.