ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

@ahendrix is right, you can just perform initialization in your main function, either before or after initializing the node. You only call ros::spin() if all of your functionality is handled in subscriber callbacks. Often, nodes need to do things periodically, so they use an infinite loop, but don't execute continuously. Instead, they often set up a ros::Rate variable and use a combination of ros::spinOnce() and ros::Rate.sleep(). See callbacks and spinning for more info and other threading models. The other links on that page are also worth a look.