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

Class send through a CallBack function

asked 2014-03-22 02:40:36 -0500

Maya gravatar image

updated 2016-10-24 09:02:18 -0500

ngrennan gravatar image

I can't figure out how to correctly use boost::bind while sending a class function as a callback Function. I want to callBack function to have on class I made as an argument as well.

Do far my code is like this :

    Scribe(ros::NodeHandle ao_nh, std::string topic, Platform& p) : _verbose(false), _topic_name(topic), _timeStamp(ros::Time::now()), _cmd(), _needChecking(false) {
    //Scribe mode
    _scribe=ao_nh.subscribe<geometry_msgs::Twist>( topic,1000, boost::bind(&Scribe::callBackFunc, _1, &p), this);
    //Timer
    _bomb=ao_nh.createTimer(ros::Duration(2),&Scribe::bombCallBack, this);
};

and the call back function is like this :

void callBackFunc(const geometry_msgs::Twist::ConstPtr& msg, Platform* plat);

Or, I have a error such that no matching function to call and I can't figure out how to correctly declare the subscriber.

Any help is appreciated.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2014-03-22 04:23:06 -0500

paulbovbel gravatar image

Generally:

boost::bind(&ClassName::classMethod, &class_instance, arg1, arg2, ...);

So in this case, since const geometry_msgs::Twist::ConstPtr& msg is passed in as _1:

boost::bind(&Scribe::callBackFunc, this, _1, &p);

edit flag offensive delete link more

Comments

Ok thanks, it worked !

Maya gravatar image Maya  ( 2014-03-22 23:51:30 -0500 )edit
2

answered 2014-03-22 04:03:47 -0500

demmeln gravatar image

updated 2014-03-22 06:16:13 -0500

subscribe has direct support for class members as callbacks. So I suggest making callBackFunc a method of class Platform and following the instructions in the tutorial: http://wiki.ros.org/roscpp_tutorials/...

Edit: Ooops... didn't read properly, your callback is alreay member of class Scribe. Check out the answer by @paulbovbel and make sure to remove the last this paramter in the subscribe call, because you already supply it in via bind.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-03-22 02:40:36 -0500

Seen: 908 times

Last updated: Mar 22 '14