Callback class member
Hi. Is it possible to use a member class method as a callback? Something like this:
void Node::chatterCallback(const std_msgs::String::ConstPtr& msg){
ROS_INFO("I heard: [%s]", msg->data.c_str());
}
void Node::Subscribe(){
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("alives", 1000, &Node::chatterCallback, this);
}
At the examples (http://www.ros.org/wiki/roscpp_tutorials/Tutorials/UsingClassMethodsAsCallbacks) , I've seen:
Listener listener;
ros::Subscriber sub = n.subscribe("chatter", 1000, &Listener::callback, &listener);
But I don't want to instantiate another object. I've the callback function as a method in my class.
I think it is possible, as I do it with Python. Just try and see. Just found this question : answers.ros.org/question/64446/problem-using-class-function-as-callback/ which might include the answer you're looking for