Multithreaded nested service calls

asked 2016-08-18 03:56:45 -0500

RunOrVeith gravatar image

Hello,

I am relativelynew to ROS and have the following problem: There is a Node running that was written in C++. At one point in its execution, I need to call a python script and return the result to the c++ node. This sounds like a perfect use for a ros service. The problem is: The python script needs to call a service that the same c++ node provides. I hope this illustrates the situation better:

C++ Node                                  Python Node
Call python service 
                                    Receive service request
                                    Call C++ Node service
                                    that needs to operate on the same object
                                    that made the first service call
Service never provided,
as still waiting for
response of first service
call
                                    Never gets a result from the C++ service,
                                    and thus never returns

What would be the best way to fix this? I thought of 2 things, but I don't know if they will work:

  1. Make the the call from c++ to python asynchronous (how? Can I just start a new thread to make the call?) and then ros::spinOnce() until the result is there. I think that would work, but is not very pretty.
  2. Use a ros::MultiThreadedSpinner with 2 threads for the whole c++ node. If it works how I think it works, than the request back from the python node will be processed by the seconds thread that is not still waiting for the response. Is this correct?

Thanks for your help!

edit retag flag offensive close merge delete