Skip to content

Commit

Permalink
Fix nested maps with no struct name
Browse files Browse the repository at this point in the history
  • Loading branch information
sea-bass committed Mar 20, 2024
1 parent 4c5f526 commit 61692da
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 21 deletions.
3 changes: 2 additions & 1 deletion example/config/implementation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ admittance_controller:
"happy"

elbow_joint:
weight: 2.0
x:
weight: 2.0

pid:
shoulder_pan_joint:
Expand Down
15 changes: 8 additions & 7 deletions example/src/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ admittance_controller:
}

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

nested_dynamic:
__map_joints:
Expand Down
3 changes: 2 additions & 1 deletion example_python/config/implementation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ admittance_controller:
"happy"

elbow_joint:
weight: 2.0
x:
weight: 2.0

pid:
shoulder_pan_joint:
Expand Down
15 changes: 8 additions & 7 deletions example_python/generate_parameter_module_example/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ admittance_controller:
}

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

nested_dynamic:
__map_joints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ for (const auto & value_{{loop.index}} : updated_params.{{mapped_param}}) {
{% 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 %};
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 %});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (param.get_name() == param_name) {
{% 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}};
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 @@ -7,11 +7,11 @@ for value_{{loop.index}} in updated_params.{{mapped_param}}:
{% 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}}"
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) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ 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 -%}
Expand Down

0 comments on commit 61692da

Please sign in to comment.