diff --git a/rclcpp/include/rclcpp/node_interfaces/node_parameters_interface.hpp b/rclcpp/include/rclcpp/node_interfaces/node_parameters_interface.hpp index 9d76c6a249..aac3b71b69 100644 --- a/rclcpp/include/rclcpp/node_interfaces/node_parameters_interface.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/node_parameters_interface.hpp @@ -49,16 +49,35 @@ class NodeParametersInterface set_parameters_atomically( const std::vector & parameters) = 0; + /// Get descriptions of parameters given their names. + /* + * \param[in] names a list of parameter names to check. + * \return the list of parameters that were found. + * Any parameter not found is omitted from the returned list. + */ RCLCPP_PUBLIC virtual std::vector get_parameters(const std::vector & names) const = 0; + /// Get the description of one parameter given a name. + /* + * \param[in] name the name of the parameter to look for. + * \return the parameter if it exists on the node. + * \throws std::out_of_range if the parameter does not exist on the node. + */ RCLCPP_PUBLIC virtual rclcpp::Parameter get_parameter(const std::string & name) const = 0; + /// Get the description of one parameter given a name. + /* + * \param[in] name the name of the parameter to look for. + * \param[out] parameter the description if parameter exists on the node. + * \return true if the parameter exists on the node, or + * \return false if the parameter does not exist. + */ RCLCPP_PUBLIC virtual bool diff --git a/rclcpp/src/rclcpp/parameter_service.cpp b/rclcpp/src/rclcpp/parameter_service.cpp index b978524ade..afecee41c6 100644 --- a/rclcpp/src/rclcpp/parameter_service.cpp +++ b/rclcpp/src/rclcpp/parameter_service.cpp @@ -39,9 +39,12 @@ ParameterService::ParameterService( const std::shared_ptr request, std::shared_ptr response) { - auto values = node_params->get_parameters(request->names); - for (auto & pvariant : values) { - response->values.push_back(pvariant.get_value_message()); + for (const auto & name : request->names) { + // Default construct param to NOT_SET + rclcpp::Parameter param; + node_params->get_parameter(name, param); + // push back NOT_SET when get_parameter() call fails + response->values.push_back(param.get_value_message()); } }, qos_profile, nullptr);