Calling spinOnce inside a service callback that publishes a message
I have a roscpp service callback that, upon request, does a few things and then publishes a message on a topic. Here is an oversimplified example:
void someServiceCb(std_srvs::Trigger::Request& req,
std_srvs::Trigger::Response& resp) {
if (something)
{
std_msgs::Empty msg;
pub.publish(msg);
resp.success = true;
ros::spinOnce(); // Do I need this? Can it cause problems?
doSomeOtherStuff();
}
else
{
resp.success = false;
}
}
The intent is to get the message out as soon as possible.
- Do I need that
ros::spinOnce()
in order to get the message out as quickly as possible? - Can calling
ros::spinOnce()
inside a service callback cause problems?
Reading http://wiki.ros.org/roscpp/Overview more carefully, I think the answer is that
ros::spinOnce()
does not help with "getting the message out more quickly". I would still like to know if it can cause problems though :-)