[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
  executor.add_node(nh);

  // declare some parameters
  nh->declare_parameter("warning1",0.0);

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

  // wait for shutdown and then clean up
  executor.spin();
  RCLCPP_INFO(nh->get_logger(),"Exiting health_status node");
  rclcpp::shutdown();
  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