Skip to content

Fix newline issue #176

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

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions example/src/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,35 @@ admittance_controller:
default_value: [3,3,3],
read_only: true,
}
hover_override: {
type: int,
default_value: 1,
description: "Override hover action:\n0: Hover\n1: Push\n2: Pull\n-1: Do not override",
validation: {
one_of<>: [ [ 0, 1, 2, -1 ] ],
},
}
angle_wraparound: {
type: bool,
default_value: false,
description: 'For joints that wrap around (without end stop, ie. are continuous),
where the shortest rotation to the target position is the desired motion.
If true, the position error :math:`e = normalize(s_d - s)` is normalized between :math:`-\pi, \pi`.
Otherwise :math:`e = s_d - s` is used, with the desired position :math:`s_d` and the measured
position :math:`s` from the state interface.'
}
open_loop_control: {
type: bool,
default_value: false,
description: "Use controller in open-loop control mode
\n\n
* The controller ignores the states provided by hardware interface but using last commands as states for starting the trajectory interpolation.\n
* It deactivates the feedback control, see the ``gains`` structure.
\n\n
This is useful if hardware states are not following commands, i.e., an offset between those (typical for hydraulic manipulators).
\n\n
If this flag is set, the controller tries to read the values from the command interfaces on activation.
If they have real numeric values, those will be used instead of state interfaces.
Therefore it is important set command interfaces to NaN (i.e., ``std::numeric_limits<double>::quiet_NaN()``) or state values when the hardware is started.\n",
read_only: true,
}
32 changes: 32 additions & 0 deletions example_python/generate_parameter_module_example/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,35 @@ admittance_controller:
default_value: [3,3,3],
read_only: true,
}
hover_override: {
type: int,
default_value: 1,
description: "Override hover action:\n0: Hover\n1: Push\n2: Pull\n-1: Do not override",
validation: {
one_of<>: [ [ 0, 1, 2, -1 ] ],
},
}
angle_wraparound: {
type: bool,
default_value: false,
description: 'For joints that wrap around (without end stop, ie. are continuous),
where the shortest rotation to the target position is the desired motion.
If true, the position error :math:`e = normalize(s_d - s)` is normalized between :math:`-\pi, \pi`.
Otherwise :math:`e = s_d - s` is used, with the desired position :math:`s_d` and the measured
position :math:`s` from the state interface.'
}
open_loop_control: {
type: bool,
default_value: false,
description: "Use controller in open-loop control mode
\n\n
* The controller ignores the states provided by hardware interface but using last commands as states for starting the trajectory interpolation.\n
* It deactivates the feedback control, see the ``gains`` structure.
\n\n
This is useful if hardware states are not following commands, i.e., an offset between those (typical for hydraulic manipulators).
\n\n
If this flag is set, the controller tries to read the values from the command interfaces on activation.
If they have real numeric values, those will be used instead of state interfaces.
Therefore it is important set command interfaces to NaN (i.e., ``std::numeric_limits<double>::quiet_NaN()``) or state values when the hardware is started.\n",
read_only: true,
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@


def run(output_file, yaml_file, validation_module=''):
print(f'Running {__file__} {output_file} {yaml_file} {validation_module}')
gen_param_struct = GenerateCode('python')
output_dir = os.path.dirname(output_file)
if not os.path.isdir(output_dir):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if not self.node_.has_parameter(self.prefix_ + "{{parameter_name}}"):
{%- filter indent(width=4) %}
descriptor = ParameterDescriptor(description="{{parameter_description}}", read_only = {{parameter_read_only}})
descriptor = ParameterDescriptor(description="{{parameter_description|valid_string_python}}", read_only = {{parameter_read_only}})
{%- for validation in parameter_validations if ("bounds" in validation.function_name or "lt" in validation.function_name or "gt" in validation.function_name) %}
{%- if "DOUBLE" in parameter_type %}
{%- if validation.arguments|length == 2 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ entry = {{param_struct_instance}}.{{struct_name}}.get_entry(value)
param_name = f"{self.prefix_}{{struct_name}}.{value}.{{parameter_field}}"
if not self.node_.has_parameter(self.prefix_ + param_name):
{%- filter indent(width=4) %}
descriptor = ParameterDescriptor(description="{{parameter_description}}", read_only = {{parameter_read_only}})
descriptor = ParameterDescriptor(description="{{parameter_description|valid_string_python}}", read_only = {{parameter_read_only}})
{%- for validation in parameter_validations if ("bounds" in validation.function_name or "lt" in validation.function_name or "gt" in validation.function_name) %}
{%- if "DOUBLE" in parameter_type %}
{%- if validation.arguments|length == 2 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@

from generate_parameter_library_py.cpp_convertions import CPPConverstions
from generate_parameter_library_py.python_convertions import PythonConvertions
from generate_parameter_library_py.string_filters_cpp import valid_string_cpp
from generate_parameter_library_py.string_filters_cpp import (
valid_string_cpp,
valid_string_python,
)


# YAMLSyntaxError standardizes compiler error messages
Expand Down Expand Up @@ -513,6 +516,7 @@ def __str__(self):
# Create a Jinja2 environment to register the custom filter
env = Environment()
env.filters['valid_string_cpp'] = valid_string_cpp
env.filters['valid_string_python'] = valid_string_python
j2_template = env.from_string(GenerateCode.templates['declare_parameter'])
code = j2_template.render(data, trim_blocks=True)
return code
Expand Down Expand Up @@ -575,6 +579,7 @@ def __str__(self):
# Create a Jinja2 environment to register the custom filter
env = Environment()
env.filters['valid_string_cpp'] = valid_string_cpp
env.filters['valid_string_python'] = valid_string_python
j2_template = env.from_string(
GenerateCode.templates['declare_runtime_parameter']
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,26 @@ def valid_string_cpp(description):
str: The filtered string that is a valid C++ string.
"""
if description:
# remove possible markdown/rst syntax, but add proper indent for cpp-header files.
filtered_description = (
description.replace('\\', '\\\\').replace('"', '\\"').replace('`', '')
description.replace('\\', '\\\\').replace('`', '').replace('\n', '\\n ')
)
# create a quote delimited string for every line
filtered_description = '\n'.join(
f'"{line}"' for line in filtered_description.splitlines()
)
return filtered_description
return f'"{filtered_description}"'
else:
return '""'


def valid_string_python(description):
"""
Filter a string to make it a valid Python string literal.

Args:
description (str): The input string to be filtered.

Returns:
str: The filtered string that is a valid Python string.
"""
if description:
return description.replace('\n', '\\n ')
else:
return ''