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

Problem with message_filter inizialization

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

schizzz8 gravatar image

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

Hi,

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);
sub.registerCallback(myCallback);

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_;

public:
    DBCreator()
    {
        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!!!

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

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

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);
    ticks_sub_.registerCallback(&DBCreator::ticksCallback,this);
}

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

DBCreator() : ticks_sub_(nh_, "/ticks", 1) {
        ticks_sub_.registerCallback(&DBCreator::ticksCallback,this);
}
edit flag offensive delete link more

Comments

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 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 588 times

Last updated: Jun 08 '14