Quantcast
Channel: Gazebo: Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 7017

Topic name or index in Subscriber callback

$
0
0
Hi, I am creating a model plugin that subscribes to many topics (same name, but only a number changes) and I want all the subscribers to call the same callback. However, if I do that I am not able to identify which subscriber (or topic name) triggered the callback at a given time. In [ROS I saw that it is possible](http://answers.ros.org/question/63991/how-to-make-callback-function-called-by-several-subscriber/) to do this using `boost::bind` but I cannot make it work in Gazebo, basically because I think the API does not allow it. Can somebody verify that this is not possible? Or much better, tell me how to identify which subscriber triggers the callback? EDIT: Posting the code I have tried and corresponding error: std::vector _subs; size_t n = 10; for (size_t i = 0; i < n; ++i) { std::stringstream ss; ss << "~/ns/base_link/sensor_" << i; _subs.emplace_back( nh->Subscribe(ss.str(), boost::bind(&MyClass::cb, this, _1, i)) ); } And the error (removed verbose data): error: no matching function for call to gazebo::transport::Node::Subscribe(std::basic_stringstream::__string_type, boost::_bi::bind_t&, long unsigned int>, boost::_bi::list3, boost::arg<1>, boost::_bi::value>>) i))); ^ note: candidates are: template gazebo::transport::SubscriberPtr gazebo::transport::Node::Subscribe(const string&, void (T::*)(const boost::shared_ptr&), T*, bool) SubscriberPtr Subscribe(const std::string &_topic, ^ /usr/include/gazebo-5.1/gazebo/transport/Node.hh:175:21: note: template argument deduction/substitution failed: mismatched types void (T::*)(const boost::shared_ptr&) and boost::_bi::bind_t&, long unsigned int>, boost::_bi::list3, boost::arg<1>, boost::_bi::value>> i))); I get 4 similar errors, one for each `Subscribe` overload. Thanks!

Viewing all articles
Browse latest Browse all 7017

Trending Articles