diff --git a/rclcpp/include/rclcpp/node.hpp b/rclcpp/include/rclcpp/node.hpp index 5448cef..a9d9aa1 100644 --- a/rclcpp/include/rclcpp/node.hpp +++ b/rclcpp/include/rclcpp/node.hpp @@ -253,6 +253,18 @@ public: std::vector get_parameters(const std::vector & names) const; + RCLCPP_PUBLIC + const rclcpp::parameter::ParameterVariant + get_parameter(const std::string & name) const; + + RCLCPP_PUBLIC + bool get_parameter( + const std::string & name, + rclcpp::parameter::ParameterVariant & parameter) const; + + template + bool get_parameter(const std::string & name, ParameterT & parameter) const; + RCLCPP_PUBLIC std::vector describe_parameters(const std::vector & names) const; diff --git a/rclcpp/include/rclcpp/node_impl.hpp b/rclcpp/include/rclcpp/node_impl.hpp index 7c018ad..654359e 100644 --- a/rclcpp/include/rclcpp/node_impl.hpp +++ b/rclcpp/include/rclcpp/node_impl.hpp @@ -368,6 +368,16 @@ void Node::register_param_change_callback(CallbackT && callback) this->parameters_callback_ = callback; } +template +bool Node::get_parameter(const std::string & name, ParameterT & parameter) const +{ + rclcpp::parameter::ParameterVariant parameter_variant(name, parameter); + bool result = get_parameter(name, parameter_variant); + parameter = parameter_variant.get_value(); + + return result; +} + } // namespace node } // namespace rclcpp diff --git a/rclcpp/src/rclcpp/node.cpp b/rclcpp/src/rclcpp/node.cpp index 84fbf3e..bfba5ed 100644 --- a/rclcpp/src/rclcpp/node.cpp +++ b/rclcpp/src/rclcpp/node.cpp @@ -242,6 +242,31 @@ Node::get_parameters( return results; } +const rclcpp::parameter::ParameterVariant +Node::get_parameter(const std::string & name) const +{ + rclcpp::parameter::ParameterVariant parameter; + + if (get_parameter(name, parameter)) { + return parameter; + } else { + throw std::out_of_range("Parameter '" + name + "' not set"); + } +} + +bool Node::get_parameter(const std::string & name, + rclcpp::parameter::ParameterVariant & parameter) const +{ + std::lock_guard lock(mutex_); + + if (parameters_.count(name)) { + parameter = parameters_.at(name); + return true; + } else { + return false; + } +} + std::vector Node::describe_parameters( const std::vector & names) const