ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

TF creating transforms seems to be wrong

asked 2023-01-03 03:43:15 -0500

dennisch gravatar image

Hi all, I already found something like this in a post here. But it is not directly what I am looking for. Maybe the solution for my problem is the inverse, but see yourself.

I want to create the coordinate frames "parent_frame" and "c4". Which uses the transformation matrix:

  0   -1    0
-0.707 0 -0.707
-0.707 0 -0.707

which transforms from the parent frame to the c4 frame. The quaternion vector for this equals q=(0.653282, -0.653282, 0.2705967, 0.2705967) with q=(qx,qy,qz,qw). The translation should be t=(1, 0, 1). However, if I set this via the command:

ros2 run tf2_ros static_transform_publisher 0.707 0 0.707 0.653282 -0.653282 0.2705967 0.2705967 parent_frame c4

Rviz shows the not the thing I expected. It shows the right translation, but the inverse rotation matrix. If I do enter the inverse rotation:

ros2 run tf2_ros static_transform_publisher 0.707 0 0.707 0.653282 -0.653282 0.2705967 -0.2705967 parent_frame c4

I get the correct coordinates in rviz. However, when I am reading with tf echo or lookupTransform, I also get the inverse rotation. Can it be, that the TF is always storing the inverse transform?

Do I alsways have to invert the rotation and keep the translation. I am really confused and I think this could be done better or do I missed something? I didn't find a good explanation for that and it seems only to be the case when using quaternions instead of axes angles.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2023-01-04 07:36:39 -0500

Mike Scheutzow gravatar image

You need to distinguish between two different ideas: 1) you can specify the rotation & translation of a child frame relative to a parent frame, or 2) you can specify a matrix (for multiplication) that transforms a specific point (pose) in the parent frame to the equivalent point (pose) in the child frame. These two matrices for (1) and (2) are not the same, but linear algebra tells us that they have a known relationship to each other: one is the matrix inverse of the other.

The ROS TF messages contain data in form (1). So if you have been given (2), then you need to take the inverse to obtain (1).

Note: in your example above, you show a rotation matrix (3x3). In robotics, we typically use a homogeneous matrix (4x4). If you are given only rotation information, your static broadcaster should properly be using x=0 y=0 z=0 for the 3 translation arguments.

edit flag offensive delete link more

Question Tools



Asked: 2023-01-03 03:43:15 -0500

Seen: 214 times

Last updated: Jan 04 '23