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

How to get the transformation matrix from translation and rotation

asked 2020-10-02 11:25:19 -0500

antibus gravatar image

From tf.Transformer.lookupTransform() I get the translation and rotation. Is there a convenient way to get the 4x4 transformation matrix from those vectors?

edit retag flag offensive close merge delete

Comments

Similar question but for python https://answers.ros.org/question/3324...

lucasw gravatar image lucasw  ( 2023-01-08 08:30:53 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2020-10-04 06:36:01 -0500

bob-ROS gravatar image

By 4x4 Transformation matrix, I assume you want an affine 3d transformation.

#include <tf2_eigen/tf2_eigen.h>  // I think is the only needed additional dependency

bool getTfTransformMatrix(Eigen::Affine3d &transform_matrix, const std::string source_frame, const std::string target_frame)
{
  try{
    geometry_msgs::TransformStamped transform_to_robot = tf_buffer.lookupTransform(target_frame, source_frame,ros::Time::now(),ros::Duration(0.05));
    transform_matrix = tf2::transformToEigen(transform_to_robot);
    return true;
  }
  catch (tf2::TransformException &ex){
    ROS_WARN("%s",ex.what());
    return false;
  }
}
edit flag offensive delete link more

Comments

1

Wow I did not know you could get both the rotation and translation that succinctly into one matrix. For anyone unfamiliar with Eigen::Affine3D check out this link that I just found. I did not test the above code, but I like it.

JackB gravatar image JackB  ( 2020-10-04 08:44:59 -0500 )edit

Strictly speaking I'm look for an Isometry transform. But an Affine transform is a Super-Super-set of Isometry, so it is kind of true if you consider Affine transform with properties implied from Isometry.

I was actually looking for Python code. I found the solution already. fromTranslationRotation from tf.TransformerROS does the trick. But thx anyway.

antibus gravatar image antibus  ( 2020-10-04 13:32:44 -0500 )edit

Question Tools

4 followers

Stats

Asked: 2020-10-02 11:25:19 -0500

Seen: 2,379 times

Last updated: Oct 04 '20