Getting name of node with message event

asked 2021-02-01 02:14:43 -0500

automatic_engineer gravatar image

updated 2021-02-01 06:54:39 -0500

[UPDATED] Hi, I'm trying to use the MessageEvent but without any luck. My goal is to create a subscriber that can get the name of the node that published the topic. Now doing as specified in https://github.com/ros2/message_filte... (line 70) I get the following error

--- stderr: topic_interface                             
In file included from /usr/include/c++/7/ext/alloc_traits.h:36:0,
                 from /usr/include/c++/7/bits/stl_construct.h:61,
                 from /usr/include/c++/7/memory:64,
                 from /opt/ros/dashing/include/rclcpp/rclcpp.hpp:142,
                 from /opt/ros/dashing/include/message_filters/subscriber.h:38,
                 from /home/giuseppe/dev_ws/src/topic_interface/src/plc_receiver.cpp:1:
/usr/include/c++/7/bits/alloc_traits.h: In instantiation of ‘struct std::allocator_traits<std::allocator<const message_filters::MessageEvent<const std_msgs::msg::String_<std::allocator<void> > >&> >’:
/opt/ros/dashing/include/rclcpp/message_memory_strategy.hpp:46:67:   required from ‘class rclcpp::message_memory_strategy::MessageMemoryStrategy<const message_filters::MessageEvent<const std_msgs::msg::String_<std::allocator<void> > >&, std::allocator<void> >’
/opt/ros/dashing/include/rclcpp/node_impl.hpp:115:1:   required by substitution of ‘template<class MessageT, class CallbackT, class AllocatorT, class SubscriptionT> std::shared_ptr<SubscriptionT> rclcpp::Node::create_subscription(const string&, const rclcpp::QoS&, CallbackT&&, const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT>&, typename rclcpp::message_memory_strategy::MessageMemoryStrategy<typename rclcpp::subscription_traits::has_message_type<CallbackT>::type, AllocatorT>::SharedPtr) [with MessageT = message_filters::MessageEvent<std_msgs::msg::String_<std::allocator<void> > >; CallbackT = std::_Bind<void (MinimalSubscriber::*(MinimalSubscriber*, std::_Placeholder<1>))(const message_filters::MessageEvent<const std_msgs::msg::String_<std::allocator<void> > >&)>; AllocatorT = std::allocator<void>; SubscriptionT = rclcpp::Subscription<const message_filters::MessageEvent<const std_msgs::msg::String_<std::allocator<void> > >&, std::allocator<void> >]’
/home/giuseppe/dev_ws/src/topic_interface/src/plc_receiver.cpp:17:75:   required from here
/usr/include/c++/7/bits/alloc_traits.h:392:27: error: forming pointer to reference type ‘const message_filters::MessageEvent<const std_msgs::msg::String_<std::allocator<void> > >&’
       using pointer = _Tp*;
                           ^
/usr/include/c++/7/bits/alloc_traits.h:395:39: error: forming pointer to reference type ‘const message_filters::MessageEvent<const std_msgs::msg::String_<std::allocator<void> > >&’
       using const_pointer = const _Tp*;
                                       ^
In file included from /usr/include/c++/7/memory:80:0,
                 from /opt/ros/dashing/include/rclcpp/rclcpp.hpp:142,
                 from /opt/ros/dashing/include/message_filters/subscriber.h:38,
                 from /home/giuseppe/dev_ws/src/topic_interface/src/plc_receiver.cpp:1:
/usr/include/c++/7/bits/unique_ptr.h: In instantiation of ‘struct std::default_delete<const message_filters::MessageEvent<const std_msgs::msg::String_<std::allocator<void> > >&>’:
/opt/ros/dashing/include/rclcpp/message_memory_strategy.hpp:135:18:   required from ‘class rclcpp::message_memory_strategy::MessageMemoryStrategy<const message_filters::MessageEvent<const std_msgs::msg::String_<std::allocator<void> > >&, std::allocator<void> >’
/opt/ros/dashing/include/rclcpp/node_impl.hpp:115:1:   required by substitution of ‘template<class MessageT, class CallbackT, class AllocatorT, class SubscriptionT> std::shared_ptr<SubscriptionT> rclcpp::Node::create_subscription(const string&, const rclcpp::QoS&, CallbackT&&, const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT>&, typename rclcpp::message_memory_strategy::MessageMemoryStrategy<typename rclcpp::subscription_traits::has_message_type<CallbackT>::type, AllocatorT>::SharedPtr) [with MessageT = message_filters::MessageEvent<std_msgs::msg::String_<std::allocator<void> > >; CallbackT = std::_Bind<void (MinimalSubscriber::*(MinimalSubscriber*, std::_Placeholder<1>))(const message_filters::MessageEvent<const std_msgs::msg::String_<std::allocator<void> > >&)>; AllocatorT = std::allocator<void>; SubscriptionT = rclcpp::Subscription<const message_filters::MessageEvent<const std_msgs::msg::String_<std::allocator<void> > >&, std::allocator<void> >]’
/home/giuseppe/dev_ws/src/topic_interface/src/plc_receiver.cpp:17:75:   required from here ...
(more)
edit retag flag offensive close merge delete

Comments

Usual ROS practise is decoupling publisher from subscriber, so maybe rethink what you are trying to achieve. If you have a good reason to be able to identify the publisher you can add a 'source' field in your message.

crnewton gravatar image crnewton  ( 2021-02-01 02:21:51 -0500 )edit

Thanks for the answer, but I'm trying to use the standard message, cause when I publish the topic I don't want to specify anything more that is already defined in the standard message. I thought that the message event would solve the problem.

automatic_engineer gravatar image automatic_engineer  ( 2021-02-01 02:41:40 -0500 )edit

It is possible to do it using the messageEvent, no experience using it in ROS2

crnewton gravatar image crnewton  ( 2021-02-01 02:50:39 -0500 )edit

Ok thanks a lot

automatic_engineer gravatar image automatic_engineer  ( 2021-02-01 03:03:21 -0500 )edit

I'm sorry to have to do this for something so seemingly unimportant, but please don't post screenshots of terminal text in question on ROS Answers. It's all text, so there is no need. Just copy-paste the text from the terminal into your question text. Do make sure to format it properly by selecting the text and pressing ctrl+k (or clicking the Preformatted Text button (the one with 101010 on it)).

You don't need to post a new question, just edit your curent one. You can use the edit button/link for this.

After you replace the screenshot with the error message itself, we can re-open your question.

gvdhoorn gravatar image gvdhoorn  ( 2021-02-01 03:11:40 -0500 )edit

Sorry, my bad

automatic_engineer gravatar image automatic_engineer  ( 2021-02-01 03:21:38 -0500 )edit

But now the problem is in ROS1 there is the function getPublisherName() that here is missing. Is there another way to get the name?

I'm not sure about that. The line 72 of message_event.hhttps://github.com/ros2/message_filte... hints that this should be possible but as you said this function is currently missing.

There is an issue related to the missing getPublisherName()https://github.com/ros2/message_filte... but it was closed for not being related to message_filters, but I doubt that this is case.

Federico Ciuffardi gravatar image Federico Ciuffardi  ( 2021-08-30 12:20:02 -0500 )edit

How did you manage to use MessageEvent in a callback?

I did not find the example at https://github.com/ros2/message_filte...

Federico Ciuffardi gravatar image Federico Ciuffardi  ( 2021-08-30 13:29:13 -0500 )edit