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

It seems this question is about multithreading in ROS. There are a few ways to do this. You can take a look at: http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning#Multi-threaded_Spinning

int main(int argc, char **argv) {
   ros::init(argc, argv, "your_node");

   //Any init here

   ros::Rate loop_rate(10.0); //Choose the loop rate
   ros::AsyncSpinner spinner(10); //Choose how many threads
   spinner.start();

   while (ros::ok()) {
     //Do any periodical work here
     ros::spinOnce();
     loop_rate.sleep();
   }

   ros::waitForShutdown();

   return 0;
}

It seems this question is about multithreading in ROS. There are a few ways to do this. You can take a look at: http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning#Multi-threaded_Spinning

Below is a minimal example with AsyncSpinner:

int main(int argc, char **argv) {
   ros::init(argc, argv, "your_node");

   //Any init here

   ros::Rate loop_rate(10.0); //Choose the loop rate
   ros::AsyncSpinner spinner(10); //Choose how many threads
   spinner.start();

   while (ros::ok()) {
     //Do any periodical work here
     ros::spinOnce();
     loop_rate.sleep();
   }

   ros::waitForShutdown();

   return 0;
}