Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There's no API for creating threads in ROS 2. The Executor class calls callbacks (if that's what you mean), and if you want a different threading model form SingleThreadedExecutor and MultiThreadedExecutor then you should make you're own executor, using one of those two as an example. They are fairly simple:

https://github.com/ros2/rclcpp/blob/33a755c535d654c97401eb6d199580368c19eb40/rclcpp/include/rclcpp/executors/single_threaded_executor.hpp#L38-L63

https://github.com/ros2/rclcpp/blob/33a755c535d654c97401eb6d199580368c19eb40/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp#L21-L39

Then you can create an instance of your custom executor, add nodes to it, and then call spin on it.

There's no API for creating threads in ROS 2. The Executor class calls callbacks (if that's what you mean), and if you want a different threading model form from SingleThreadedExecutor and MultiThreadedExecutor then you should make you're own executor, using one of those two as an example. They are fairly simple:

https://github.com/ros2/rclcpp/blob/33a755c535d654c97401eb6d199580368c19eb40/rclcpp/include/rclcpp/executors/single_threaded_executor.hpp#L38-L63

https://github.com/ros2/rclcpp/blob/33a755c535d654c97401eb6d199580368c19eb40/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp#L21-L39

Then you can create an instance of your custom executor, add nodes to it, and then call spin on it.