【发布时间】:2019-01-25 17:49:52
【问题描述】:
我得到一个 4x4 的机器人姿势,其中 z 轴朝前,x 轴朝东(右),y 轴朝下。
现在,为了提取机器人的航向,我使用了以下函数
void inline mat2xyh(Matrix4f& pose, float &x, float &y, float &heading){
heading = atan2(-pose(2, 0), sqrt(pose(2, 1) * pose(2, 1) + pose(2,2) * pose(2,2)) );
x = pose(0, 3);
y = pose(2, 3);
};
为了验证,我设置了下面的代码。当我检查分解的矩阵角度和我用来构造旋转矩阵的角度时,它们不匹配!
这是当我发现音高有两种独特的解决方案,或者音高的范围是-PI/2 < pitch < PI/2。
现在我不知道机器人是面向 45 度还是 135 度,有什么办法可以解决这个问题吗?
Vector4f v(0, 0, 1, 0);
MatrixXf rotation = AngleAxisf(135 * M_PI/180., Vector3f::UnitY()).toRotationMatrix();
float x,y,h;
Matrix4f pose1 = Matrix4f::Identity();
pose1.topLeftCorner<3,3>() = rotation;
mat2xyh(pose1, x,y,h);
cout << pose1 << endl;
cout << rad2deg(h) << endl;
cout << "Pose: \n" << pose1 * v << endl;
cout << "====================" << endl;
MatrixXf rotation2 = AngleAxisf(45 * M_PI/180., Vector3f::UnitY()).toRotationMatrix();
Matrix4f pose2 = Matrix4f::Identity();
pose2.topLeftCorner<3,3>() = rotation2;
mat2xyh(pose2, x,y,h);
cout << pose2 << endl;
cout << rad2deg(h) << endl;
cout << pose2 * v << endl;
结果
-0.707107 0 0.707107 0
0 1 0 0
-0.707107 0 -0.707107 0
0 0 0 1
heading: 45
Pose:
0.707107
0
-0.707107
0
====================
0.707107 0 0.707107 0
0 1 0 0
-0.707107 0 0.707107 0
0 0 0 1
heading:45
Pose:
0.707107
0
0.707107
0
【问题讨论】:
-
您能否提供有关您的坐标系的更多详细信息?具体是机器人身体固定还是世界固定?您使用的术语不一致,因此很难说 XYZ 对应于 EDN(东、下、北)还是 RDF(右、下、前)。当机器人旋转时,差异很重要。
-
围绕下 (Y) 轴的旋转也是偏航,而不是俯仰。这可能会导致您的困惑。
-
嗨尼尔,谢谢你的回复。是的,我的意思是偏航。我不熟悉这些术语,但让我详细说明一下。我使用的数据集来自 Kitti,地图坐标系定义为机器人在时间 t=0 的第一个姿势。这有帮助吗?
标签: linear-algebra eigen rotational-matrices