Access parameters set from another node
Hi,
I'm using ROS2 Bouncy.
I have two nodes. What I would like to do is to allow the first node to set some parameters on the parameters server and then make the second node to retrieve these parameters.
The problem is that I'm able to see the parameters only from the node that has set them.
NODE 1
rclcpp::init(argc, argv);
rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("node_1");
rclcpp::SyncParametersClient::SharedPtr parameters_client = std::make_shared<rclcpp::SyncParametersClient>(node);
while (!parameters_client->wait_for_service(1s)){
if (!rclcpp::ok()) {
RCLCPP_ERROR(node->get_logger(), "Interrupted while waiting for the service. Exiting.");
return 0;}
RCLCPP_INFO(node->get_logger(), "service not available, waiting again..."); }
std::vector<rcl_interfaces::msg::SetParametersResult> set_parameters_results = parameters_client->set_parameters({rclcpp::Parameter("wheels.radius", 1)});
rclcpp::spin(node);
rclcpp::shutdown();
NODE 2
rclcpp::init(argc, argv);
rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("node_2");
rclcpp::SyncParametersClient::SharedPtr parameters_client = std::make_shared<rclcpp::SyncParametersClient>(node);
while (!parameters_client->wait_for_service(1s)){
if (!rclcpp::ok()) {
RCLCPP_ERROR(node->get_logger(), "Interrupted while waiting for the service. Exiting.");
return 0;}
RCLCPP_INFO(node->get_logger(), "service not available, waiting again..."); }
rclcpp::spin_some(node);
auto parameters_and_prefixes = parameters_client->list_parameters({ }, 0);
std::cout<<"READING PARAMS"<<std::endl;
for (auto & name : parameters_and_prefixes.names) {
std::cout<<"P: "<< name << std::endl;
}
The parameters_and_prefixes
variable in the second node is an empty vector. On the other hand, if I try to list all parameters from node 1 (where they are actually set), everything works fine.
It looks like I'm setting the parameters for node 1 only... What should I change ? Thanks