最近在使用ros中的一个运动学正解函数getGlobalLinkTransform()时碰到了如上问题,官方文档中该函数的返回值是Eigen::Isometry3d,因此定义了对应的数据类型来接受该返回值,但是编译报错,告诉我出现了类型转换的错误, 明明是同一种类型哪来的类型转换?
- getGlobalLinkTransform() 官方文档:

- 调用:
const Eigen::Isometry3d& end_effector_state = kinematic_state->getGlobalLinkTransform("wrist_3_link");
error: static assertion failed: you_performed_an_invalid_transformation_conversion
- 虽然百思不得骑姐,但还是无聊的查看了一下函数的输出类型:
竟然是Eigen::Affine3d!!!
const Eigen::Affine3d& end_effector_state = kinematic_state->getGlobalLinkTransform("wrist_3_link");
ROS_INFO("use datatype Affine3d");
ROS_INFO_STREAM("Translation: \n" << end_effector_state.translation() << "\n");
ROS_INFO_STREAM("Rotation: \n" << end_effector_state.rotation() << "\n");
- 编译通过,并且能正确输出Affine3d的translation和rotation。
既然是这个问题,那就类型转换一下吧,没想到还是坑。。。
概括来说,Affine3d转换成Isometry3d必须遵循如下格式:
Eigen::AffineCompact3f a;
Eigen::Isometry3f b;
b.translation() = a.translation();
b.linear() = a.rotation();
这个Isometry3d的旋转矩阵赋值还必须是用linear,不能用rotation,因为rotation是只读属性,而输出的时候用rotation或者linear都行。
这点破事…一下午,都是泪…