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

Revision history [back]

click to hide/show revision 1
initial version

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;
  }
}