From 4c5f526a9f5598aa48e3b0791d99191ff9edcb6b Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Tue, 19 Mar 2024 23:55:28 -0400 Subject: [PATCH 1/2] Restore functionality for mapped params with no struct name --- .gitignore | 1 + example/config/implementation.yaml | 3 +++ example/src/parameters.yaml | 10 ++++++++++ example_python/config/implementation.yaml | 3 +++ .../generate_parameter_module_example/parameters.yaml | 10 ++++++++++ .../jinja_templates/cpp/declare_runtime_parameter | 8 ++++++++ .../jinja_templates/cpp/remove_runtime_parameter | 4 ++++ .../jinja_templates/cpp/update_runtime_parameter | 8 ++++++++ .../jinja_templates/python/declare_runtime_parameter | 6 ++++++ .../jinja_templates/python/update_runtime_parameter | 4 ++++ 10 files changed, 57 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eeb8a6e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/__pycache__ diff --git a/example/config/implementation.yaml b/example/config/implementation.yaml index 324356c..11a3f38 100644 --- a/example/config/implementation.yaml +++ b/example/config/implementation.yaml @@ -11,6 +11,9 @@ admittance_controller: fixed_string_no_default: "happy" + elbow_joint: + weight: 2.0 + pid: shoulder_pan_joint: i: 0.7 diff --git a/example/src/parameters.yaml b/example/src/parameters.yaml index 7520d0d..e0f51fa 100644 --- a/example/src/parameters.yaml +++ b/example/src/parameters.yaml @@ -24,6 +24,16 @@ admittance_controller: description: "specifies which joints will be used by the controller", } + __map_joints: + weight: { + type: double, + default_value: 1.0, + description: "map parameter without struct name", + validation: { + gt<>: [0.0], + } + } + nested_dynamic: __map_joints: __map_dof_names: diff --git a/example_python/config/implementation.yaml b/example_python/config/implementation.yaml index 324356c..11a3f38 100644 --- a/example_python/config/implementation.yaml +++ b/example_python/config/implementation.yaml @@ -11,6 +11,9 @@ admittance_controller: fixed_string_no_default: "happy" + elbow_joint: + weight: 2.0 + pid: shoulder_pan_joint: i: 0.7 diff --git a/example_python/generate_parameter_module_example/parameters.yaml b/example_python/generate_parameter_module_example/parameters.yaml index 9c856f4..3cff6d5 100644 --- a/example_python/generate_parameter_module_example/parameters.yaml +++ b/example_python/generate_parameter_module_example/parameters.yaml @@ -32,6 +32,16 @@ admittance_controller: description: "specifies which joints will be used by the controller", } + __map_joints: + weight: { + type: double, + default_value: 1.0, + description: "map parameter without struct name", + validation: { + gt<>: [0.0], + } + } + nested_dynamic: __map_joints: __map_dof_names: diff --git a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/declare_runtime_parameter b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/declare_runtime_parameter index f960b64..11f1d01 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/declare_runtime_parameter +++ b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/declare_runtime_parameter @@ -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; diff --git a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/remove_runtime_parameter b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/remove_runtime_parameter index abaa2c2..9617e45 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/remove_runtime_parameter +++ b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/remove_runtime_parameter @@ -2,7 +2,11 @@ std::set {{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); } } diff --git a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/update_runtime_parameter b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/update_runtime_parameter index 3fb84fb..bdd59ad 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/update_runtime_parameter +++ b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/update_runtime_parameter @@ -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 -%} } diff --git a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/declare_runtime_parameter b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/declare_runtime_parameter index 117fa1b..0f7b4c8 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/declare_runtime_parameter +++ b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/declare_runtime_parameter @@ -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}}" +{% 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}}) diff --git a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/update_runtime_parameter b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/update_runtime_parameter index 231a3c4..30f34e7 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/update_runtime_parameter +++ b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/update_runtime_parameter @@ -10,7 +10,11 @@ if param.name == param_name: {% 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 -%} From 61692da61b81d80e3da95dc12ed631bd0b307aff Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Wed, 20 Mar 2024 00:22:38 -0400 Subject: [PATCH 2/2] Fix nested maps with no struct name --- example/config/implementation.yaml | 3 ++- example/src/parameters.yaml | 15 ++++++++------- example_python/config/implementation.yaml | 3 ++- .../parameters.yaml | 15 ++++++++------- .../jinja_templates/cpp/declare_runtime_parameter | 2 +- .../jinja_templates/cpp/update_runtime_parameter | 2 +- .../python/declare_runtime_parameter | 4 ++-- .../python/update_runtime_parameter | 6 +++++- 8 files changed, 29 insertions(+), 21 deletions(-) diff --git a/example/config/implementation.yaml b/example/config/implementation.yaml index 11a3f38..4cd1ba9 100644 --- a/example/config/implementation.yaml +++ b/example/config/implementation.yaml @@ -12,7 +12,8 @@ admittance_controller: "happy" elbow_joint: - weight: 2.0 + x: + weight: 2.0 pid: shoulder_pan_joint: diff --git a/example/src/parameters.yaml b/example/src/parameters.yaml index e0f51fa..31e7e61 100644 --- a/example/src/parameters.yaml +++ b/example/src/parameters.yaml @@ -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: diff --git a/example_python/config/implementation.yaml b/example_python/config/implementation.yaml index 11a3f38..4cd1ba9 100644 --- a/example_python/config/implementation.yaml +++ b/example_python/config/implementation.yaml @@ -12,7 +12,8 @@ admittance_controller: "happy" elbow_joint: - weight: 2.0 + x: + weight: 2.0 pid: shoulder_pan_joint: diff --git a/example_python/generate_parameter_module_example/parameters.yaml b/example_python/generate_parameter_module_example/parameters.yaml index 3cff6d5..1440e58 100644 --- a/example_python/generate_parameter_module_example/parameters.yaml +++ b/example_python/generate_parameter_module_example/parameters.yaml @@ -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: diff --git a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/declare_runtime_parameter b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/declare_runtime_parameter index 11f1d01..244e595 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/declare_runtime_parameter +++ b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/declare_runtime_parameter @@ -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 %}); diff --git a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/update_runtime_parameter b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/update_runtime_parameter index bdd59ad..b4cd4e3 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/update_runtime_parameter +++ b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/cpp/update_runtime_parameter @@ -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 -%} diff --git a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/declare_runtime_parameter b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/declare_runtime_parameter index 0f7b4c8..96c48f7 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/declare_runtime_parameter +++ b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/declare_runtime_parameter @@ -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) %} diff --git a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/update_runtime_parameter b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/update_runtime_parameter index 30f34e7..195fb78 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/update_runtime_parameter +++ b/generate_parameter_library_py/generate_parameter_library_py/jinja_templates/python/update_runtime_parameter @@ -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 -%}