Where should I put MultiThreadedSpinner.spin() in my main function?

asked 2021-03-08 18:51:19 -0500

So Young gravatar image

updated 2021-03-08 18:59:13 -0500

HI I have a question about ros::MultiThreadedSpinner. I have several callback functions that should be handled at the same time so I am using Multi threads. The problem is that I need to call update function from my docking class continuously, like I did in the code below. In this case, is putting spinner.spin() above the while loop correct? I am not sure where I should place spinner.spin(), can someone tell me if I've done this in a right way and if the usage of multi thread like this is a common practice? Thank you in advance!

ros::init (argc, argv, "docking_node");
docking GGG;    
ros::MultiThreadedSpinner spinner(4);
ros::Rate spin_rate(10);


spinner.spin();
while(ros::ok){
    GGG.update();
    spin_rate.sleep();
}

return (0);
edit retag flag offensive close merge delete

Comments

I tested the code above and I realised, it handles the callbacks BUT the update function is not called once..

So Young gravatar image So Young  ( 2021-03-08 19:33:16 -0500 )edit

For those who are interested, I used AsyncSpinner instead, since MultiThreadedSpinner blocks.

So Young gravatar image So Young  ( 2021-03-10 02:33:46 -0500 )edit