Ask Your Question

Revision history [back]

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(){;  // blocking here!
       // 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);

When trying to put the service call in another boost thread compilation leads to the error (see below);  // blocking here!

Changed to:

 boost::thread myThread = boost::thread(boost::bind(&ros::ServiceClient::call, &my_srv, request));


 »bind(<unresolved overloaded function type>, ros::ServiceClient*, request&)«

Any hints? Thanks