Skip to content

Commit

Permalink
Restore functionality for mapped params with no struct name (#185)
Browse files Browse the repository at this point in the history
* Restore functionality for mapped params with no struct name

* Fix nested maps with no struct name
  • Loading branch information
sea-bass authored Mar 23, 2024
1 parent 8733d7a commit edfeb82
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/__pycache__
4 changes: 4 additions & 0 deletions example/config/implementation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ admittance_controller:
fixed_string_no_default:
"happy"

elbow_joint:
x:
weight: 2.0

pid:
shoulder_pan_joint:
i: 0.7
Expand Down
11 changes: 11 additions & 0 deletions example/src/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ admittance_controller:
description: "specifies which joints will be used by the controller",
}

__map_joints:
__map_dof_names:
weight: {
type: double,
default_value: 1.0,
description: "map parameter without struct name",
validation: {
gt<>: [0.0],
}
}

nested_dynamic:
__map_joints:
__map_dof_names:
Expand Down
4 changes: 4 additions & 0 deletions example_python/config/implementation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ admittance_controller:
fixed_string_no_default:
"happy"

elbow_joint:
x:
weight: 2.0

pid:
shoulder_pan_joint:
i: 0.7
Expand Down
11 changes: 11 additions & 0 deletions example_python/generate_parameter_module_example/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ admittance_controller:
description: "specifies which joints will be used by the controller",
}

__map_joints:
__map_dof_names:
weight: {
type: double,
default_value: 1.0,
description: "map parameter without struct name",
validation: {
gt<>: [0.0],
}
}

nested_dynamic:
__map_joints:
__map_dof_names:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
for (const auto & value_{{loop.index}} : updated_params.{{mapped_param}}) {
{% endfor -%}
{%- filter indent(width=4) -%}
{% if struct_name != "" %}
auto& entry = {{param_struct_instance}}.{{struct_name}}{% for map in parameter_map%}.{{map}}[value_{{loop.index}}]{% endfor %};
{% else %}
auto& entry = {{param_struct_instance}}{% for map in parameter_map%}.{{map}}[value_{{loop.index}}]{% endfor %};
{% endif -%}
std::string value = fmt::format("{%- for mapped_param in mapped_params -%}{% if loop.index == 1 %}{}{% else %}.{}{% endif -%} {%- endfor -%}",
{%- for mapped_param in mapped_params -%}{% if loop.index == 1 %} value_{{loop.index}}{% else %}, value_{{loop.index}}{% endif -%} {%- endfor %});
{% if struct_name != "" %}
auto param_name = fmt::format("{}{}.{}.{}", prefix_, "{{struct_name}}", value, "{{parameter_field}}");
{% else %}
auto param_name = fmt::format("{}{}.{}", prefix_, value, "{{parameter_field}}");
{% endif -%}
if (!parameters_interface_->has_parameter(param_name)) {
{%- filter indent(width=4) %}
rcl_interfaces::msg::ParameterDescriptor descriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
std::set<std::string> {{mapped_param}}_set(updated_params.{{mapped_param}}.begin(), updated_params.{{mapped_param}}.end());
for (const auto &it: updated_params.{{parameter_map}}) {
if ({{mapped_param}}_set.find(it.first) == {{mapped_param}}_set.end()) {
{% if struct_name != "" %}
auto param_name = fmt::format("{}{}.{}.{}", prefix_, "{{struct_name}}", it.first, "{{parameter_field}}");
{% else %}
auto param_name = fmt::format("{}{}.{}", prefix_, it.first, "{{parameter_field}}");
{% endif -%}
parameters_interface_->undeclare_parameter(param_name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ for (const auto & value_{{loop.index}} : updated_params.{{mapped_param}}) {
{%- filter indent(width=4) -%}
std::string value = fmt::format("{%- for mapped_param in mapped_params -%}{% if loop.index == 1 %}{}{% else %}.{}{% endif -%} {%- endfor -%}",
{%- for mapped_param in mapped_params -%}{% if loop.index == 1 %} value_{{loop.index}}{% else %}, value_{{loop.index}}{% endif -%} {%- endfor %});
{% if struct_name != "" %}
auto param_name = fmt::format("{}{}.{}.{}", prefix_, "{{struct_name}}", value, "{{parameter_field}}");
{% else %}
auto param_name = fmt::format("{}{}.{}", prefix_, value, "{{parameter_field}}");
{% endif -%}
if (param.get_name() == param_name) {
{%- filter indent(width=4) %}
{% if parameter_validations|length -%}
{{parameter_validations-}}
{% endif -%}
{% if struct_name != "" %}
updated_params.{{struct_name}}{% for map in parameter_map%}.{{map}}[value_{{loop.index}}]{% endfor %}.{{parameter_field}} = param.{{parameter_as_function}};
{% else %}
updated_params{% for map in parameter_map%}.{{map}}[value_{{loop.index}}]{% endfor %}.{{parameter_field}} = param.{{parameter_as_function}};
{% endif -%}
RCLCPP_DEBUG_STREAM(logger_, param.get_name() << ": " << param.get_type_name() << " = " << param.value_to_string());
{% endfilter -%}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ for value_{{loop.index}} in updated_params.{{mapped_param}}:
{%- endfilter -%}
{% endfor -%}
{%- filter indent(width=4*(mapped_params|length)) %}
{% if struct_name != "" %}
{{param_struct_instance}}.{{struct_name}}{% for map in parameter_map%}.add_entry(value_{{loop.index}}){% endfor %}
entry = {{param_struct_instance}}.{{struct_name}}{% for map in parameter_map%}.get_entry(value_{{loop.index}}){% endfor %}
param_name = f"{self.prefix_}{{struct_name}}{% for map in parameter_map%}.{value_{{loop.index}}}{% endfor %}.{{parameter_field}}"
param_name = f"{self.prefix_}{{struct_name}}.{% for map in parameter_map%}{value_{{loop.index}}}.{% endfor %}{{parameter_field}}"
{% else %}
{{param_struct_instance}}{% for map in parameter_map%}.add_entry(value_{{loop.index}}){% endfor %}
entry = {{param_struct_instance}}{% for map in parameter_map%}.get_entry(value_{{loop.index}}){% endfor %}
param_name = f"{self.prefix_}{% for map in parameter_map%}{value_{{loop.index}}}.{% endfor %}{{parameter_field}}"
{% endif -%}
if not self.node_.has_parameter(self.prefix_ + param_name):
{%- filter indent(width=4) %}
descriptor = ParameterDescriptor(description="{{parameter_description|valid_string_python}}", read_only = {{parameter_read_only}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ for value_{{loop.index}} in updated_params.{{mapped_param}}:
{%- endfilter -%}
{% endfor -%}
{%- filter indent(width=4*(1+mapped_params|length)) %}
param_name = f"{self.prefix_}{{struct_name}}{% for map in parameter_map%}.{value_{{loop.index}}}{% endfor %}.{{parameter_field}}"
{% if struct_name != "" %}
param_name = f"{self.prefix_}{{struct_name}}{% for map in parameter_map%}{value_{{loop.index}}}.{% endfor %}{{parameter_field}}"
{% else %}
param_name = f"{self.prefix_}{% for map in parameter_map%}{value_{{loop.index}}}.{% endfor %}{{parameter_field}}"
{% endif -%}
if param.name == param_name:
{%- filter indent(width=4) %}
{% if parameter_validations|length -%}
{{parameter_validations-}}
{% endif -%}
{% if struct_name != "" %}
updated_params.{{struct_name}}{% for map in parameter_map%}.get_entry(value_{{loop.index}}){% endfor %}.{{parameter_field}} = param.{{parameter_as_function}}
{% else %}
updated_params{% for map in parameter_map%}.get_entry(value_{{loop.index}}){% endfor %}.{{parameter_field}} = param.{{parameter_as_function}}
{% endif -%}
self.logger_.debug(param.name + ": " + param.type_.name + " = " + str(param.value))
{% endfilter -%}
{% endfilter -%}

0 comments on commit edfeb82

Please sign in to comment.