0
$\begingroup$

Rosanswers logo

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!


Originally posted by schizzz8 on ROS Answers with karma: 183 on 2014-06-08

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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);
}

Originally posted by ahendrix with karma: 47576 on 2014-06-08

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by schizzz8 on 2014-06-09:
The first example doesn't work, but the second does and I also prefer it. Thanks a lot for your help!!!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.