Skip to content

Commit

Permalink
Fixed draco subscriber parameter names (#43)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
(cherry picked from commit 48cd0ce)
  • Loading branch information
ahcorde authored and mergify[bot] committed Dec 12, 2023
1 parent 325a879 commit bc8c0b6
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,29 @@ class SimpleSubscriberPlugin : public SubscriberPlugin
}

template<typename T>
bool declareParam(const std::string parameter_name, const T value)
bool declareParam(
const std::string parameter_name, const T value,
const rcl_interfaces::msg::ParameterDescriptor & parameter_descriptor =
rcl_interfaces::msg::ParameterDescriptor())
{
if (impl_) {
impl_->node_->template declare_parameter<T>(parameter_name, value);
uint ns_len = impl_->node_->get_effective_namespace().length();
std::string param_base_name = getTopic().substr(ns_len);
std::replace(param_base_name.begin(), param_base_name.end(), '/', '.');

std::string param_name = param_base_name + "." + parameter_name;

rcl_interfaces::msg::ParameterDescriptor param_descriptor = parameter_descriptor;
param_descriptor.name = param_name;

try {
impl_->node_->template declare_parameter<T>(param_name, value, param_descriptor);
} catch (const rclcpp::exceptions::ParameterAlreadyDeclaredException &) {
RCLCPP_DEBUG(
impl_->node_->get_logger(), "%s was previously declared",
param_descriptor.name.c_str());
}

return true;
}
return false;
Expand Down

0 comments on commit bc8c0b6

Please sign in to comment.