Get single parameter (#245)
* added function to get parameter by exact name * added ros1 style get_parameter for parameter variant * added ros1 style get_param for non-variant types * Make the get_parameter functions call a private base function * Parameter Variant requires name in constructor * Cleaned up to no longer need private function * Made exception message more clear
This commit is contained in:
parent
1402715d76
commit
902d558e64
3 changed files with 47 additions and 0 deletions
|
@ -253,6 +253,18 @@ public:
|
||||||
std::vector<rclcpp::parameter::ParameterVariant>
|
std::vector<rclcpp::parameter::ParameterVariant>
|
||||||
get_parameters(const std::vector<std::string> & names) const;
|
get_parameters(const std::vector<std::string> & 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<typename ParameterT>
|
||||||
|
bool get_parameter(const std::string & name, ParameterT & parameter) const;
|
||||||
|
|
||||||
RCLCPP_PUBLIC
|
RCLCPP_PUBLIC
|
||||||
std::vector<rcl_interfaces::msg::ParameterDescriptor>
|
std::vector<rcl_interfaces::msg::ParameterDescriptor>
|
||||||
describe_parameters(const std::vector<std::string> & names) const;
|
describe_parameters(const std::vector<std::string> & names) const;
|
||||||
|
|
|
@ -368,6 +368,16 @@ void Node::register_param_change_callback(CallbackT && callback)
|
||||||
this->parameters_callback_ = callback;
|
this->parameters_callback_ = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename ParameterT>
|
||||||
|
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<ParameterT>();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace node
|
} // namespace node
|
||||||
} // namespace rclcpp
|
} // namespace rclcpp
|
||||||
|
|
||||||
|
|
|
@ -242,6 +242,31 @@ Node::get_parameters(
|
||||||
return results;
|
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<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
|
if (parameters_.count(name)) {
|
||||||
|
parameter = parameters_.at(name);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<rcl_interfaces::msg::ParameterDescriptor>
|
std::vector<rcl_interfaces::msg::ParameterDescriptor>
|
||||||
Node::describe_parameters(
|
Node::describe_parameters(
|
||||||
const std::vector<std::string> & names) const
|
const std::vector<std::string> & names) const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue