Ask Your Question
1

Transfer a point(x,y,z) between frames

asked 2017-10-16 19:14:19 -0500

BhanuKiran.Chaluvadi gravatar image
 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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-10-17 09:19:03 -0500

borgcons gravatar image

updated 2017-10-17 09:48:25 -0500

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;
    }
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2017-10-16 19:14:19 -0500

Seen: 562 times

Last updated: Oct 17 '17