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

Which constructor of tf2_ros::TransformListener should I use?

asked 2020-03-19 03:25:08 -0500

pauljurczak gravatar image

updated 2020-03-19 03:56:50 -0500

There are two constructors of tf2_ros::TransformListener:

  1. TransformListener(tf2::BufferCore& buffer, const ros::NodeHandle& nh, bool spin_thread)

  2. TransformListener(tf2::BufferCore& buffer, bool spin_thread)

It seems that nh parameter in the first one is ignored, so they are equivalent. Is it accurate?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2020-03-19 13:23:14 -0500

tfoote gravatar image

If you pass in the NodeHandle it will use that nodehandle passed. If you don't pass one it will default construct a NodeHandle to be used.

For most common use cases where the user has a default constructed NodeHandle, it will not make a difference. However by passing in the NodeHandle you have more control of things like the Callback Queue and other NodeHandle level settings that can be modified on the passed in NodeHandle.

edit flag offensive delete link more

Comments

Just from glancing at it -- the nodehandle is only used to create subscribers. If the /tf is globally namespaced, what other nodehandle parameterizations would effect the listener? I genuinely don't see where it could be used unless the / in the topic was removed.

stevemacenski gravatar image stevemacenski  ( 2020-03-19 14:34:48 -0500 )edit
1

As I mentioned above the first thing that comes to mind is being able to control the threading via the use of custom callback queues. For example if you set it up right you can run the whole system in a single thread or at the other end enable a multi threaded callback queue.

tfoote gravatar image tfoote  ( 2020-03-19 15:02:23 -0500 )edit
0

answered 2020-03-19 12:58:32 -0500

updated 2020-03-19 12:59:25 -0500

If you look at the source code: https://github.com/ros/geometry2/blob...

You'll see that we copy the nodehandle into node_. If that isn't supplied in the constructor, the default constructor (in the default namespace) is used. But you bring up a good question since the topic is /tf and not tf, so even applying the namespacing to the nodehandle, it wouldn't make a difference. The nodehandle is only used to create subscriptions so it really... doesn't matter?

Maybe that actually should be removed if we are correct, but it also may be there for legacy reasons. Good question. You will not go wrong using the TransformListener(tf2::BufferCore& buffer, bool spin_thread) constructor unless you are using multi-robot same-ros-core applications.

edit flag offensive delete link more

Comments

See @tfoote's answer -- is better

stevemacenski gravatar image stevemacenski  ( 2020-03-19 15:41:40 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2020-03-19 03:25:08 -0500

Seen: 367 times

Last updated: Mar 19 '20