ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
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;
}
2 | No.2 Revision |
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;
}