Why is AsyncSpinner needed?

asked 2022-03-22 08:23:30 -0500

alberto gravatar image

updated 2022-03-22 08:36:16 -0500

Hi all,

I'm using this github to recreate the ROS2 code for the Phantom Omni. It's my first experience with ros and maybe it's a stupid question, but I can't understand why in omni.cpp, in the ros_publish function it's used the

ros::AsyncSpinner spinner(2);
spinner.start();

Reading online (for example this), I understand that the AsyncSpinner is useful when I have some callbacks, but in this case I only need to publish, in fact I use the while(ros::ok()), and there are no callbacks.

Moreover, migrating the code in ROS2, I found that the most similar thing to AsyncSpinner is rclcpp::executors::MultiThreadedExecutor. I tried to do as suggested here, but it is confusing since I only have one node:

rclcpp::executors::MultiThreadedExecutor executor;
executor.add_node(omni_ros);

Where omni_ros is an instance of my custom class, which inherits from rclcpp::Node.

Then if I put the executor.spin() before the while(ros::ok()), it never enters the cicle and I guess it's because it waits for the callback, that doesn't exist!

So in the end I removed all the part related to the executor and I left only the while cicle, and everything seems to work fine.

From this reasoning I asked myself why is AsyncSpinner used in the source code? Am I missing something that changed from ros1 / ros2? Is it used to setup for some future potential callbacks?

edit retag flag offensive close merge delete