ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

[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

1 Answer

Sort by ยป oldest newest most voted
0

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

Comments

that link is dead now. Is this what you were referring to: https://github.com/ros2/rclcpp/blob/m... ?

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

this link is actual implementation of MultiThreadedExecutor. I think it should be https://github.com/ros2/examples/blob...

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

With OP not making it clear what's in "Health" object (we don't know e.g. if there are multiple callback hooks in it), I'm not sure if making multiple CallbackGroups can be a solution to OP's case?

130s gravatar image 130s  ( 2023-05-25 16:11:22 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 5,477 times

Last updated: Aug 04 '20