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

tf2 example?

asked 2014-07-22 10:30:51 -0500

arennuit gravatar image

Hi all,

Trying to learn ROS, I understand tf is deprecated and tf2 is the currently maintained version. Now the tutorials for tf2 are rather wrong as stated here and here (and as I actually experienced just now). Is there a simple example somewhere I can rely on to know how to listen and broadcast frames?

Thanks,

Antoine.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2014-07-23 18:38:31 -0500

Ok.... huh...

I just was trying to implement this, when I saw your question. So I will try to help you, or at least show you my solution which seams to work. It is done in C++.

So you need following headers:

#include <tf2_ros/transform_listener.h>
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>

Than initialise all variables:

tf2_ros::Buffer tfBuffer;
tf2_ros::TransformListener tfListener(tfBuffer);
geometry_msgs::TransformStamped transform;

Ant than the magic line:

  try{
    transform = tfBuffer.lookupTransform("base_link", frame_id, ros::Time(0));
  }
  catch (tf2::TransformException ex ){
            ROS_ERROR("%s",ex.what());
  }

To this solution I came by searching code of geometry_experimental stack on GitHub.

edit flag offensive delete link more

Comments

Hello destogl, this is a good to help me start with, thanks for your answer ;)

arennuit gravatar image arennuit  ( 2014-07-24 00:45:34 -0500 )edit

There is also code examples now in C++ and Python, please check this pull request: https://github.com/ros/geometry_tutorials/pull/6

destogl gravatar image destogl  ( 2014-07-25 18:39:55 -0500 )edit

Interesting! Thanks a lot , this will help indeed!

arennuit gravatar image arennuit  ( 2014-07-28 08:53:30 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2014-07-22 10:30:51 -0500

Seen: 2,868 times

Last updated: Jul 23 '14