Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filter chain configuration parameter loading #69

Open
wants to merge 3 commits into
base: ros2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions include/filters/filter_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,22 @@ load_chain_config(
const std::string norm_param_prefix = impl::normalize_param_prefix(param_prefix);

// Read parameters for filter1..filterN
for (size_t filter_num = 1; filter_num > found_filters.size(); ++filter_num) {
for (size_t filter_num = 1; ; ++filter_num) {
// Parameters in chain are prefixed with 'filterN.'
const std::string filter_n = "filter" + std::to_string(filter_num);

// Declare filterN.name and filterN.type
// Declare filterN.name
rcl_interfaces::msg::ParameterDescriptor name_desc;
name_desc.name = norm_param_prefix + filter_n + ".name";
name_desc.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING;
name_desc.read_only = false;
// Must be dynamically typed because later we undeclare it and redeclare
// it read-only, but statically typed params cannot be undeclared.
name_desc.dynamic_typing = true;
node_params->declare_parameter(name_desc.name, rclcpp::PARAMETER_STRING);
rcl_interfaces::msg::ParameterDescriptor type_desc;
Copy link

@meyerj meyerj Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type_desc and name_desc are declared and populated, but then unused besides the name. I suggest to use the declare_parameter() overloads that accept a rcl_interfaces::msg::ParameterDescriptor, same as before.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or directly pass the name only without the extra descriptor declarations, if the default descriptors will do.

// Declare filterN.type
type_desc.name = norm_param_prefix + filter_n + ".type";
type_desc.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING;
type_desc.read_only = false;
// Must be dynamically typed because later we undeclare it and redeclare
// it read-only, but statically typed params cannot be undeclared.
type_desc.dynamic_typing = true;

node_params->declare_parameter(
name_desc.name, rclcpp::ParameterValue(), name_desc);
node_params->declare_parameter(
type_desc.name, rclcpp::ParameterValue(), type_desc);
jonbinney marked this conversation as resolved.
Show resolved Hide resolved
node_params->declare_parameter(type_desc.name, rclcpp::PARAMETER_STRING);

rclcpp::Parameter param_name;
rclcpp::Parameter param_type;
Expand Down Expand Up @@ -139,6 +131,7 @@ load_chain_config(
}
}


// Make sure 'type' is formated as 'package_name/filtername'
if (1 != std::count(found_filter.type.cbegin(), found_filter.type.cend(), '/')) {
RCLCPP_FATAL(
Expand All @@ -150,16 +143,6 @@ load_chain_config(
// Seems ok; store it for now; it will be loaded further down.
found_filter.param_prefix = norm_param_prefix + filter_n + ".params";
found_filters.push_back(found_filter);

// Redeclare 'name' and 'type' as read_only
node_params->undeclare_parameter(name_desc.name);
node_params->undeclare_parameter(type_desc.name);
name_desc.read_only = true;
type_desc.read_only = true;
node_params->declare_parameter(
name_desc.name, rclcpp::ParameterValue(found_filter.name), name_desc);
node_params->declare_parameter(
type_desc.name, rclcpp::ParameterValue(found_filter.type), type_desc);
}
return true;
}
Expand Down