ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
In ROS 2 parameters are available via service interfaces:
root@d0a03d7984eb:/# ros2 run demo_nodes_cpp listener &
root@d0a03d7984eb:/# ros2 service list
/listener/describe_parameters
/listener/get_parameter_types
/listener/get_parameters
/listener/list_parameters
/listener/set_parameters
/listener/set_parameters_atomically
In rclpy
I believe there is no helper and you need to create a service client yourself and call it, similar to what is done in ros2 service
In rclcpp
there is are ParameterClient classes
on which you can call functions like get_parameters
and it will handle the service calls
the use looks like:
auto parameters_client = std::make_shared<rclcpp::SyncParametersClient>(my_node, "remote_node_name");
while (!parameters_client->wait_for_service(1s)) {
if (!rclcpp::ok()) {
RCLCPP_ERROR(this->get_logger(), "Interrupted while waiting for the service. Exiting.");
rclcpp::shutdown();
}
RCLCPP_INFO(this->get_logger(), "service not available, waiting again...");
}
auto parameters = parameters_client->get_parameters({"remote_param1", "remote_param2"});
you can then access them:
std::stringstream ss;
// Get a few of the parameters just set.
for (auto & parameter : parameters)
{
ss << "\nParameter name: " << parameter.get_name();
ss << "\nParameter value (" << parameter.get_type_name() << "): " <<
parameter.value_to_string();
}
There is also a non-blocking / asynchronous version rclcpp::AsyncParametersClient