0

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

机械臂结构

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

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,然后我可以得到姿势矩阵,我可以通过姿势*(0,0,0,1)在第四坐标系中的原点坐标。但是结果(380.948,382.331,0)似乎不正确,因为它应该沿着x轴而不是y-移动轴。我已经阅读了很多关于 DH 矩阵的书籍和资料,但我无法弄清楚它有什么问题。

4

1 回答 1

0

我自己想通了,真正的问题是 glm::mat,glm::mat 是 col-type,这意味着列将在行之前初始化,我更改了代码并得到了正确的结果:

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);
于 2017-10-31T15:46:01.897 回答