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

Revision history [back]

click to hide/show revision 1
initial version

As @dornhege stated, this has nothing to do with your class structure. It depends on how the ros callbacks are managed. Typically it is configured such that only one callback can be called at a time. The callbacks can be called while your control loop is in ros::spin() or ros::spinOnce(). This default for you has the advantage that none of your code is executed in parallel, i. e. you do not have to worry about thread-safety, mutexes, race-conditions and so on...

Probably the best solution for your problem would be to switch from services to non-blocking actions in actionlib. http://wiki.ros.org/actionlib This is the preferred approach for long running calculations.

For having your callbacks executed in parallel, you wlll need an AsyncSpinner, see http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning#Multi-threaded_Spinning. This means you have to take care of thread-safety, mutexes, race-conditions and so on. Moreover, you will likely need a separated callback queue (ideally single threaded per queue) for both of your callbacks (http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning#Advanced:_Using_Different_Callback_Queues) because otherwise your not only your callbacks can be executed in parallel but also multiple calls into your callback functions at the same time are possible.