Getting name of node with message event
[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 ...
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.
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.
It is possible to do it using the messageEvent, no experience using it in ROS2
Ok thanks a lot
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 with101010
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.
Sorry, my bad
I'm not sure about that. The line 72 of
message_event.h
https://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 tomessage_filters
, but I doubt that this is case.How did you manage to use MessageEvent in a callback?
I did not find the example at https://github.com/ros2/message_filte...