ros::spinOnce within library function - dangerous?
Hi
I would like your opinion on an implementation I made. In order to facilitate use of our robots, I implemented some common helper functions that interact with specific nodes. These helper functions can check if a node is alive or get its most recent status, just to give examples. Most of the functions have a ros::spinOnce
call inside to deliver the newest data or to function at all.
Now the problem. It happened a few times now that I or someone else was utterly confused about the sequence of a ROS node. It would do unexpected things, simply because of the hidden spinOnce
calls in my library function. And without expecting it, the normal user might not take into account, that any of his own node's callbacks could trigger at the moment when he calls one of my library functions.
How do you see that? Is it, for the reason I described, evil to have spin
and spinOnce
calls hidden in library functions or should the user be expecting it to happen? Should I rewrite my library to start a separate thread for its own callbacks such that it does not interfere with the node's main thread? The latter might be overkill for simple helper functions.
Asked by potaahto on 2017-04-26 10:37:31 UTC
Comments
I'm currently contemplating a similar rewrite for a library of mine; switching the library's subscriber to use a separate AsyncSpinner so that it doesn't have to call spinOnce to process callbacks.
Asked by ahendrix on 2017-04-26 11:32:05 UTC