Ask Your Question

[ros2] Multithreaded Executors and parameters

asked 2019-09-23 16:55:15 -0500

fatadama gravatar image

I'm running into an issue in attaching a node to a MultiThreadedExecutor. The basic code is structured as follows:

#include <rclcpp/rclcpp.hpp>
#include <health/health.h>

int main(int argc, char* argv[])
  rclcpp::init(argc, argv);
  // make multithreaded executor
  rclcpp::executors::MultiThreadedExecutor executor;
  // make nodehandle
  auto nh = std::make_shared<rclcpp::Node>("health_status");
  // add to the executor

  // declare some parameters

  // create an object that sets up some callbacks
  Health h(nh);

  // wait for shutdown and then clean up
  RCLCPP_INFO(nh->get_logger(),"Exiting health_status node");
  return 0;

The code compiles and appears to set up the correct publishers and subscribers (which are all abstracted into the "Health" object). However, if I call "ros2 param list" while the node is running, the call appears to hang forever. If I change my executor to a SingleThreadedExecutor or use rclcpp::spin() instead, "ros2 param list" works as it's supposed to. The code (as currently structured) does not actually use the MultiThreadedExecutor's functionality to run multiple callback threads; however, we would like to eventually support that functionality.

I have come across this thread, which appears to address a related problem. However, I'm not sure how to modify my code. Any help would be appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-10-17 21:54:25 -0500

ignacio gravatar image

updated 2020-08-04 02:37:58 -0500

You may need to add two CallbackGroups and pass then as arguments while calling create_subscription() or create_publisher(). This multithread_executor.cpp will help you.

edit flag offensive delete link more


that link is dead now. Is this what you were referring to: ?

mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2020-06-03 12:53:25 -0500 )edit

this link is actual implementation of MultiThreadedExecutor. I think it should be

ipa-hsd gravatar image ipa-hsd  ( 2020-06-14 13:48:35 -0500 )edit

just updated. Thanks guys!

ignacio gravatar image ignacio  ( 2020-08-04 02:38:13 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-09-23 16:55:15 -0500

Seen: 3,676 times

Last updated: Aug 04 '20