How to run a ROS service call in another thread with boost
Hi, my node as a class which calls a service. During that service call it needs to get notified by a topic. The callback is set up respectively. The problem is that during the service call no messages are received. I suspect that the node is blocked by the service call and cannot handle any callback calls. They just pop up after the service call has terminated.
Below is a similar example of that node.
class MyClass {
callService(){
my_srv.call(request); // blocking here!
}
callback(){
// do something <-- is never called during service request
}
}
int main.. {
ros::ServiceClient my_srv = n.serviceClient<..>("..");
MyClass my_class(my_srv);
n.subscribe(my_topic, 100, &MyClass::callback, &my_class);
my_class.callService();
}
When trying to put the service call in another boost thread compilation leads to the error (see below)
my_srv.call(request); // blocking here!
Changed to:
boost::thread myThread = boost::thread(boost::bind(&ros::ServiceClient::call, &my_srv, request));
Error:
»bind(<unresolved overloaded function type>, ros::ServiceClient*, request&)«
Any hints? Thanks