Skip to content

Commit fc2a9af

Browse files
authored
Merge branch 'main' into pr-support-nested-mapped-parameters
2 parents d398973 + 42c8f8a commit fc2a9af

32 files changed

+1043
-40
lines changed

example/CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog for package generate_parameter_library_example
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
0.3.7 (2024-01-12)
6+
------------------
7+
* Split example/README.md into C++ and Python version; updated content (`#138 <https://github.com/PickNikRobotics/generate_parameter_library/issues/138>`_)
8+
* Contributors: chriseichmann
9+
510
0.3.6 (2023-07-31)
611
------------------
712

example/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
33
<package format="3">
44
<name>generate_parameter_library_example</name>
5-
<version>0.3.6</version>
5+
<version>0.3.7</version>
66
<description>Example usage of generate_parameter_library.</description>
77
<maintainer email="paul.gesel@picknik.ai">Paul Gesel</maintainer>
88
<license>BSD-3-Clause</license>

example_cmake_python/CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2+
Changelog for package cmake_generate_parameter_module_example
3+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
5+
0.3.7 (2024-01-12)
6+
------------------
7+
* Enable generate_parameter_module through ament_cmake_python (`#161 <https://github.com/PickNikRobotics/generate_parameter_library/issues/161>`_)
8+
* Contributors: Paul Gesel

example_cmake_python/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(cmake_generate_parameter_module_example)
3+
4+
find_package(ament_cmake REQUIRED)
5+
find_package(ament_cmake_python REQUIRED)
6+
find_package(generate_parameter_library REQUIRED)
7+
8+
generate_parameter_module(admittance_parameters
9+
cmake_generate_parameter_module_example/parameters.yaml
10+
cmake_generate_parameter_module_example.custom_validation
11+
)
12+
13+
ament_python_install_package(${PROJECT_NAME})
14+
15+
ament_package()

example_cmake_python/README.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Example:
2+
3+
## Build the node
4+
5+
```
6+
mkdir -p colcon_ws/src
7+
cd colcon_ws/src
8+
git clone https://github.com/picknikrobotics/generate_parameter_library.git
9+
cd ..
10+
colcon build
11+
```
12+
13+
## Run the Python node
14+
15+
```
16+
source install/setup.bash
17+
python3 src/generate_parameter_library/example_cmake_python/cmake_generate_parameter_module_example/minimal_publisher.py --ros-args --params-file src/generate_parameter_library/example_python/config/implementation.yaml
18+
```
19+
20+
You should see an output like this:
21+
`[INFO] [1656018676.015816509] [admittance_controller]: Initial control frame parameter is: 'ee_link'`
22+
23+
24+
## ROS 2 CLI
25+
26+
Run the following:
27+
28+
`ros2 param list`
29+
30+
You should see:
31+
32+
```
33+
/admittance_controller:
34+
admittance.damping_ratio
35+
admittance.mass
36+
admittance.selected_axes
37+
admittance.stiffness
38+
chainable_command_interfaces
39+
command_interfaces
40+
control.frame.external
41+
control.frame.id
42+
enable_parameter_update_without_reactivation
43+
fixed_array
44+
fixed_string
45+
fixed_string_no_default
46+
fixed_world_frame.frame.external
47+
fixed_world_frame.frame.id
48+
ft_sensor.filter_coefficient
49+
ft_sensor.frame.external
50+
ft_sensor.frame.id
51+
ft_sensor.name
52+
gravity_compensation.CoG.force
53+
gravity_compensation.CoG.pos
54+
gravity_compensation.frame.external
55+
gravity_compensation.frame.id
56+
interpolation_mode
57+
joints
58+
kinematics.alpha
59+
kinematics.base
60+
kinematics.group_name
61+
kinematics.plugin_name
62+
kinematics.plugin_package
63+
kinematics.tip
64+
one_number
65+
pid.elbow_joint.d
66+
pid.elbow_joint.i
67+
pid.elbow_joint.p
68+
pid.rate
69+
pid.shoulder_lift_joint.d
70+
pid.shoulder_lift_joint.i
71+
pid.shoulder_lift_joint.p
72+
pid.shoulder_pan_joint.d
73+
pid.shoulder_pan_joint.i
74+
pid.shoulder_pan_joint.p
75+
pid.wrist_1_joint.d
76+
pid.wrist_1_joint.i
77+
pid.wrist_1_joint.p
78+
pid.wrist_2_joint.d
79+
pid.wrist_2_joint.i
80+
pid.wrist_2_joint.p
81+
pid.wrist_3_joint.d
82+
pid.wrist_3_joint.i
83+
pid.wrist_3_joint.p
84+
qos_overrides./parameter_events.publisher.depth
85+
qos_overrides./parameter_events.publisher.durability
86+
qos_overrides./parameter_events.publisher.history
87+
qos_overrides./parameter_events.publisher.reliability
88+
scientific_notation_num
89+
state_interfaces
90+
three_numbers
91+
three_numbers_of_five
92+
use_feedforward_commanded_input
93+
use_sim_time
94+
```
95+
96+
All parameter are automatically declared and callbacks are setup by default. You can set a parameter by typing:
97+
98+
`ros2 param set /admittance_controller control.frame.id new_frame`
99+
100+
You should see:
101+
102+
`[INFO] [1656019001.515820371] [admittance_controller]: New control frame parameter is: 'new_frame'`
103+
104+
Congratulations, you updated the parameter!
105+
106+
If you try to set a parameter that is read only, you will get an error. Running the following
107+
108+
`ros2 param set /admittance_controller command_interfaces ["velocity"]`
109+
110+
will result in the error
111+
112+
`Setting parameter failed: Trying to set a read-only parameter: command_interfaces.`
113+
114+
Running the following
115+
116+
`ros2 param describe /admittance_controller admittance.damping_ratio`
117+
118+
will show a parameter's description
119+
120+
```
121+
Parameter name: admittance.damping_ratio
122+
Type: double array
123+
Description: specifies damping ratio values for x, y, z, rx, ry, and rz used in the admittance calculation. The values are calculated as damping can be used instead: zeta = D / (2 * sqrt( M * S ))
124+
Constraints:
125+
Min value: 0.1
126+
Max value: 10.0
127+
```
128+
129+
If you try to set a value out of the specified bounds,
130+
131+
`ros2 param set /admittance_controller admittance.damping_ratio [-10.0,-10.0,-10.0,-10.0,-10.0,-10.0]`
132+
133+
you will get the error
134+
135+
`Setting parameter failed: Value array('d', [-10.0, -10.0, -10.0, -10.0, -10.0, -10.0]) in parameter 'admittance.damping_ratio' must be within bounds [0.1, 10.0]`
136+
137+
If you try to set a vector parameter with the wrong length,
138+
139+
`ros2 param set /admittance_controller admittance.damping_ratio [1.0,1.0,1.0]`
140+
141+
you will get the error
142+
143+
`Setting parameter failed: Length of parameter 'admittance.damping_ratio' is '3' but must be equal to 6`
144+
145+
If you try to load a yaml file with missing required parameters
146+
147+
`python3 src/generate_parameter_library/example_cmake_python/cmake_generate_parameter_module_example/minimal_publisher.py --ros-args --params-file src/generate_parameter_library/example_python/config/missing_required.yaml`
148+
149+
you will get the error
150+
151+
```
152+
Traceback (most recent call last):
153+
[...]
154+
rclpy.exceptions.ParameterUninitializedException: The parameter 'fixed_string_no_default' is not initialized
155+
[ros2run]: Process exited with failure 1
156+
```

example_cmake_python/cmake_generate_parameter_module_example/__init__.py

Whitespace-only changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2023 PickNik Inc.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# * Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
#
10+
# * Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
#
14+
# * Neither the name of the PickNik Inc. nor the names of its
15+
# contributors may be used to endorse or promote products derived from
16+
# this software without specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
# POSSIBILITY OF SUCH DAMAGE.
29+
30+
31+
def no_args_validator(param):
32+
return ''
33+
34+
35+
def validate_double_array_custom_func(param, arg1, arg2):
36+
return ''
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2023 PickNik Inc.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# * Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
#
10+
# * Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
#
14+
# * Neither the name of the PickNik Inc. nor the names of its
15+
# contributors may be used to endorse or promote products derived from
16+
# this software without specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
# POSSIBILITY OF SUCH DAMAGE.
29+
30+
import rclpy
31+
import rclpy.node
32+
33+
from cmake_generate_parameter_module_example.admittance_parameters import (
34+
admittance_controller,
35+
)
36+
37+
38+
class MinimalParam(rclpy.node.Node):
39+
def __init__(self):
40+
super().__init__('admittance_controller')
41+
self.timer = self.create_timer(1, self.timer_callback)
42+
43+
self.param_listener = admittance_controller.ParamListener(self)
44+
self.params = self.param_listener.get_params()
45+
self.get_logger().info(
46+
"Initial control frame parameter is: '%s'" % self.params.control.frame.id
47+
)
48+
self.get_logger().info("fixed string is: '%s'" % self.params.fixed_string)
49+
50+
self.get_logger().info(
51+
"Original joints parameter is: '%s'" % str(self.params.joints)
52+
)
53+
for d in self.params.fixed_array:
54+
self.get_logger().info("value: '%s'" % str(d))
55+
56+
def timer_callback(self):
57+
if self.param_listener.is_old(self.params):
58+
self.param_listener.refresh_dynamic_parameters()
59+
self.params = self.param_listener.get_params()
60+
self.get_logger().info(
61+
"New control frame parameter is: '%s'" % self.params.control.frame.id
62+
)
63+
self.get_logger().info("fixed string is: '%s'" % self.params.fixed_string)
64+
for d in self.params.fixed_array:
65+
self.get_logger().info("value: '%s'" % str(d))
66+
67+
68+
def main(args=None):
69+
rclpy.init(args=args)
70+
node = MinimalParam()
71+
rclpy.spin(node)
72+
73+
74+
if __name__ == '__main__':
75+
main()

0 commit comments

Comments
 (0)