How to Seperate ROS2 init(), Spin(), shutdown() to different function calls without global declaration in C++?

asked 2021-04-10 20:31:32 -0500

Aj088 gravatar image

Is there a way to separate the rclcpp::init(), rclcpp::executors::SingleThreadExecutor to spin node once and the rclcpp::shutdown() into separate function calls? When I tried to move it to different function, the node does not seem functional. What I want is to have separate function that handles the initialisation phase, run phase and the shutdown phase and I want to use ROS2 Executor to perform spin_once() in a loop without getting stuck in a spin callback loop. Since most of the rclcpp contents are classes, I am trying to avoid global declaration of rclcpp::Node or rclcpp::Executors. I fairly new to the concepts and any help in this matter would be helpful.

edit retag flag offensive close merge delete