0

I have a 6-DOF robot arm model:

robot arm structure

I want to calculate forward kinematics, so I uses the D-H matrix. the D-H parameters are:

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};

and the calculation :

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;
}

the problem I have is that, I can't get the correct result, for example, I want to calculate the transformation matrix from first joint to the 4th joint, I will change the for loop 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.

CXC_SCUT
  • 1
  • 2

1 Answers1

0

I have figured it out by myself, the real problem behind is glm::mat, glm::mat is col-type which means columns will be initialized before rows,I changed the code and get the correct result:

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));
}

then I can get the position by:

auto pos = pose * glm::vec4(x,y,z,1);
CXC_SCUT
  • 1
  • 2