Skip to content
Open
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,34 @@ validation:
"my_project::integer_equal_value": [3]
```

For Python modules, pass the validation module to `generate_parameter_module` in `setup.py`.
The functions receive the generated `rclpy.Parameter` as the first argument and return an
empty string when the parameter is valid. Any non-empty string is treated as the validation
error message.

```python
generate_parameter_module(
module_name,
yaml_file,
validation_module='generate_parameter_module_example.custom_validation',
)
```

The Python example includes custom validators such as:

```python
import math


def validate_damping_ratio(param, lower_bound, upper_bound):
for value in param.value:
if not math.isfinite(value) or value <= 0.0:
return f"Parameter '{param.name}' must contain finite positive damping ratios"
if value < lower_bound or value > upper_bound:
return f"Value {value} in parameter '{param.name}' must be within bounds"
return ''
```

### Nested structures
After the top-level key, every subsequent non-leaf key will generate a nested C++ struct. The struct instance will have
the same name as the key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,26 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import math


def no_args_validator(param):
return ''


def validate_double_array_custom_func(param, arg1, arg2):
def validate_damping_ratio(param, lower_bound, upper_bound):
if len(param.value) != 6:
return f"Parameter '{param.name}' must contain six damping ratio values"

for value in param.value:
if not math.isfinite(value) or value <= 0.0:
return (
f"Parameter '{param.name}' must contain finite positive damping ratios"
)
if value < lower_bound or value > upper_bound:
return (
f"Value {value} in parameter '{param.name}' must be within "
f"[{lower_bound}, {upper_bound}]"
)

return ''
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ admittance_controller:
The values are calculated as damping can be used instead: zeta = D / (2 * sqrt( M * S ))"
validation:
fixed_size<>: 6
"custom_validators::validate_double_array_custom_func": [ 20.3, 5.0 ]
element_bounds<>: [ 0.1, 10.0 ]
"custom_validators::validate_damping_ratio": [ 0.1, 10.0 ]

stiffness:
type: double_array
Expand Down