我有一个6自由度的机械臂模型:
我想计算正向运动学,所以我使用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,然后我可以得到姿态矩阵,我可以通过pose * (0,0,0,1).but得到第四个坐标系中的原点坐标。结果(380.948,382.331,0)似乎不正确,因为它应该沿着x轴而不是y轴移动。我读了很多关于D-H矩阵的书籍和资料,但我不知道它有什么问题。
发布于 2017-10-31 23:46:02
我自己已经弄明白了,真正的问题是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);https://stackoverflow.com/questions/47011849
复制相似问题