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

Problem with message_filter inizialization

asked 2014-06-08 10:55:37 -0600

schizzz8 gravatar image

updated 2014-06-08 10:56:46 -0600


I need to write a C++ class containing message_filters as members.

In the ROS Wiki they are declared in this way:

message_filters::Subscriber<std_msgs::UInt32> sub(nh, "my_topic", 1);

while for using them in a class I found that this could be a way:

class DBCreator
    ros::NodeHandle nh_;
    message_filters::Subscriber<capygroovy::Ticks> ticks_sub_;

        ticks_sub_ = nh_.subscribe("/ticks",1,&DBCreator::ticksCallback,this);

but I get this error:

/opt/ros/groovy/include/message_filters/subscriber.h:96: note: no known conversion for argument 1 from ‘ros::Subscriber’ to 'const message_filters::Subscriber< capygroovy::Ticks_< std::allocator < void > > >&'

that is, ticks_sub_ should be a ros::Subscriber object.

I'm not very familiar with this topic so I'd be glad if someone could help me understand how to initialize this object inside the class!!!


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2014-06-08 19:28:23 -0600

ahendrix gravatar image

Instead of using the default subscriber created from a ros NodeHandle, you should be creating message_filters::Subscriber instances as described in the C++ example on the wiki.

In your case, this could look like:

DBCreator() {
    ticks_sub_ = message_filters::Subscriber<capygroovy::Ticks>(nh_, "/ticks", 1);

Or you can use the C++ member initializer syntax:

DBCreator() : ticks_sub_(nh_, "/ticks", 1) {
edit flag offensive delete link more


The first example doesn't work, but the second does and I also prefer it. Thanks a lot for your help!!!

schizzz8 gravatar image schizzz8  ( 2014-06-09 03:41:08 -0600 )edit

Question Tools

1 follower


Asked: 2014-06-08 10:55:37 -0600

Seen: 587 times

Last updated: Jun 08 '14