0
$\begingroup$

Rosanswers logo

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?


Originally posted by ahtsan on ROS Answers with karma: 112 on 2019-07-03

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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();

Originally posted by sloretz with karma: 3061 on 2019-07-08

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by ahtsan on 2019-07-09:
Thank you!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.