Where should I put MultiThreadedSpinner.spin() in my main function?
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);
Asked by So Young on 2021-03-08 19:51:19 UTC
Comments
I tested the code above and I realised, it handles the callbacks BUT the
update
function is not called once..Asked by So Young on 2021-03-08 20:33:16 UTC
For those who are interested, I used AsyncSpinner instead, since MultiThreadedSpinner blocks.
Asked by So Young on 2021-03-10 03:33:46 UTC