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

[ROS2] hangs forever when getting parameter for node defined in another node

asked 2019-07-03 19:15:14 -0500

ahtsan gravatar image

I have this script

#include "rclcpp/rclcpp.hpp"

using namespace std::chrono_literals;

class MinimalTimer : public rclcpp::Node
{
public:
  MinimalTimer()
  : Node("MinimalTimer")
  {
    node_ = std::make_shared<rclcpp::Node>("test_node");
    node_->declare_parameter("parameter_A");

    auto timer_callback = [this]() -> void {
      RCLCPP_INFO(this->get_logger(), "Callback!");
    };

    timer_ = this->create_wall_timer(500ms, timer_callback);
    this->declare_parameter("parameter_B");
  }

private:
  rclcpp::TimerBase::SharedPtr timer_;
  std::shared_ptr<rclcpp::Node> node_;
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  auto minimal_timer = std::make_shared<MinimalTimer>();

  rclcpp::spin(minimal_timer);
  rclcpp::shutdown();

  return 0;
}

and I ran ros2 run ....

ros2 node list gives

/MinimalTimer
/test_node

ros2 param list MinimalTimer gives

  parameter_B
  use_sim_time

but ros param list test_node hangs forever.

Any idea?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-07-08 12:26:30 -0500

sloretz gravatar image

The example creates two nodes:MinimalTimer and test_node, but spins only one of them rclcpp::spin(minimal_timer);. rclcpp::spin() adds a node to an executor. The executor calls callbacks, like the parameter service callbacks. test_node must be added to an executor so the parameter service callbacks can send a response.

See the manual composition demo for an example.

rclcpp::executors::SingleThreadedExecutor exec;
exec.add_node(minimal_timer);
exec.add_node(minimal_timer->node_);
exec.spin();
edit flag offensive delete link more

Comments

Thank you!

ahtsan gravatar image ahtsan  ( 2019-07-09 12:37:37 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2019-07-03 19:15:14 -0500

Seen: 1,066 times

Last updated: Jul 08 '19