Topic name or index in Subscriber callback [closed]

asked 2016-03-14 11:43:30 -0600

updated 2016-03-14 11:57:59 -0600

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 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<gazebo::transport::SubscriberPtr> _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<char>::__string_type, boost::_bi::bind_t<void, boost::_mfi::mf2<void, MyClass, const boost::shared_ptr<const gazebo::msgs::LaserScanStamped>&, long unsigned int>, boost::_bi::list3<boost::_bi::value<MyClass*>, boost::arg<1>, boost::_bi::value<long unsigned int> > >)
      i)));
        ^
note: candidates are:
template<class M, class T> gazebo::transport::SubscriberPtr gazebo::transport::Node::Subscribe(const string&, void           (T::*)(const boost::shared_ptr<const T>&), 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<const T>&) and boost::_bi::bind_t<void, boost::_mfi::mf2<void, MyClass, const boost::shared_ptr<const gazebo::msgs::LaserScanStamped>&, long unsigned int>, boost::_bi::list3<boost::_bi::value<MyClass*>, boost::arg<1>, boost::_bi::value<long unsigned int> > >
      i)));

I get 4 similar errors, one for each Subscribe overload.

Thanks!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Javi V
close date 2016-03-14 15:37:06.530176

Comments

Can you post code that you have tried?

nkoenig gravatar imagenkoenig ( 2016-03-14 11:46:20 -0600 )edit

@nkoenig I've updated the post.

Javi V gravatar imageJavi V ( 2016-03-14 11:59:07 -0600 )edit
1

Thanks. I also checked out the code, and it's definitely not possible. You can file an issue for this feature, or try to implement a fix yourself.

nkoenig gravatar imagenkoenig ( 2016-03-14 12:11:35 -0600 )edit