0
$\begingroup$

Rosanswers logo

 geometry_msgs::PointStamped initial_pt; 
 ros::Publisher odom_pub = node.advertise<geometry_msgs::vector3>("/visualization_marker", 1);
 tf2_ros::Buffer tfBuffer; 
 tf2_ros::TransformListener tfListener(tfBuffer);

ros::Rate rate(10.0);
while (node.ok()){

geometry_msgs::TransformStamped transformStamped;
try{
  transformStamped = tfBuffer.lookupTransform("/base_1", "/base_2", ros::Time(0));
}
catch (tf2::TransformException &ex) {
  ROS_WARN("%s",ex.what());
  ros::Duration(1.0).sleep();
  continue;
}

geometry_msgs::PointStamped  transformed_pt ; 
?
? 
?

Hi, I am trying to transfer a point from frame base_1 to base_2. Went through online search but not convinced how to proceed after this . tf2 listener tutorial Any help would be greatly appreciated.


Originally posted by BhanuKiran.Chaluvadi on ROS Answers with karma: 241 on 2017-10-16

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I have not tried this yet but this is what I would do:

geometry_msgs::PointStamped initial_pt; 
ros::Publisher odom_pub = node.advertise<geometry_msgs::vector3>("/visualization_marker", 1);
tf2_ros::Buffer tfBuffer; 
tf2_ros::TransformListener tfListener(tfBuffer);

ros::Rate rate(10.0);
while (node.ok()){

  geometry_msgs::TransformStamped transformStamped;
  try{
    transformStamped = tfBuffer.lookupTransform("/base_2", "/base_1", ros::Time(0));
    geometry_msgs::PointStamped  transformed_pt ; 

    tf2_geometry_msgs::do_transform(initial_pt, transformed_pt, transformStamped);
    geometry_msgs::vector3 v;

     v.x = transformed_pt.point.x;
     v.y = transformed_pt.point.y;
     v.z = transformed_pt.point.z;

     odom_pub.publish(v);
  }
  catch (tf2::TransformException &ex) {
    ROS_WARN("%s",ex.what());
    ros::Duration(1.0).sleep();
    continue;
}

from http://docs.ros.org/diamondback/api/tf2_geometry_msgs/html/namespacetf2.html

or extracting a snippet from http://wiki.ros.org/tf2/Tutorials/Using%20stamped%20datatypes%20with%20tf2%3A%3AMessageFilter

geometry_msgs::PointStamped initial_pt; 
ros::Publisher odom_pub = node.advertise<geometry_msgs::vector3>("/visualization_marker", 1);
tf2_ros::Buffer tfBuffer; 
tf2_ros::TransformListener tfListener(tfBuffer);

ros::Rate rate(10.0);
initial_pt.header.frame_id = "/base1";

while (node.ok()){

  try 
    {
      tbuffer_.transform(initial_pt, transformed_pt, "/base2");
  
      geometry_msgs::vector3 v;

      v.x = transformed_pt.point.x;
      v.y = transformed_pt.point.y;
      v.z = transformed_pt.point.z;

      odom_pub.publish(v);
    }
    catch (tf2::TransformException &ex) 
    {
      ROS_WARN("Failure %s\n", ex.what()); //Print exception which was caught
      continue;
    }
}

Originally posted by borgcons with karma: 176 on 2017-10-17

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.