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

transformListener constructor parameters in tf2 and related questions

asked 2021-01-22 09:08:53 -0500

staskikot gravatar image

Can anyone explain what node and spin _ thread parameters exactly mean in the C++ constructor of TransformListener ?

My problem is that when I create TransformListener inside the init() function of my Node with a custom QoS like this

    tf_listener_ = std::make_shared<tf2_ros::TransformListener>(
        * tf_buffer_ // buffer
        , this       // node
        , true       // spin_thread
        , qos  
    );

I get an exception

terminate called after throwing an instance of 'std::runtime_error'
  what():  Node has already been added to an executor.

I guess that ROS tries to run a different copy of my node in a separate thread, which causes this exception.

But then why on earth the basic constructor

 tf_listener_ = std::make_shared<tf2_ros::TransformListener>(
        * tf_buffer_ 
 )

works correctly ? Doesn't it substitute this for node ?

This also works

    tf_listener_ = std::make_shared<tf2_ros::TransformListener>(
        * tf_buffer_ // buffer
        , this       // node
        , false       // spin_thread
        , qos  
    );

but I can't get from the documentation if this code is functional or not.

Also, what is the difference between qos and static_qos ?

Can you use static _ qos if the transformation does not depend on time ?

Will redefining the move-constructor for my Node to change its name when it is copied solve my problem ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-01-25 03:35:15 -0500

staskikot gravatar image

updated 2021-01-25 03:36:55 -0500

Looks that i figured out how to solve the problem by having a look at the source code of tf2_ros: http://docs.ros.org/en/latest/api/tf2...

There are two constructors of TransformListener, one of them initialises the node_ momber and the other does not. This means that in the short constructor the member node_ is initialised by the default node constructor.

Which means that I have to run the constructor this way:

tf_listener_ = std::make_shared<tf2_ros::TransformListener>(
     * tf_buffer_ // buffer
     , std::make_shared<Node>("my_listener")       // node
     , true       // spin_thread
     , qos        // quality of services structure
 );

Which is kind of logical, because as the listener is executed as a separate thread, it should be set up as a ROS Node, and so it is the developer's responsibility to specify its name to avoid creating two nodes with duplicate names.

I wish this was explained in the documentation !

I still don't understand how the short constructor of TransformListener works in ROS2, where there is no Node constructor without arguments. Must be a sort of a miracle. May be the binaries for tf2_ros compiled for a different distribution, which contain this argumentless constructor, are implicated ?

edit flag offensive delete link more

Comments

Perhaps @tfoote can help

gvdhoorn gravatar image gvdhoorn  ( 2021-01-25 03:51:28 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-01-22 09:03:02 -0500

Seen: 406 times

Last updated: Jan 25 '21