You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that using mapped parameters with Python nodes doesn't work correctly; the parameter will appear correct from the CLI with ros2 param get but accessing it internally in the Python node it keeps the default value, except for whichever mapped parameter is the last one declared in the YAML definitions.
An example, making minimal changes to the Python generate_parameter_module_example:
Add a loop to the example node init method that logs all the PID parameters of each joint, so in generate_parameter_library/example_python/generate_parameter_module_example/minimal_publisher.py you have:
from generate_parameter_module_example.admittance_parameters import (
admittance_controller,
)
import rclpy
import rclpy.node
from operator import attrgetter
class MinimalParam(rclpy.node.Node):
def __init__(self):
super().__init__('admittance_controller')
self.timer = self.create_timer(1, self.timer_callback)
self.param_listener = admittance_controller.ParamListener(self)
self.params = self.param_listener.get_params()
self.get_logger().info(
"Initial control frame parameter is: '%s'" % self.params.control.frame.id
)
self.get_logger().info("fixed string is: '%s'" % self.params.fixed_string)
self.get_logger().info(
"Original joints parameter is: '%s'" % str(self.params.joints)
)
for d in self.params.fixed_array:
self.get_logger().info("value: '%s'" % str(d))
for j in self.params.joints:
pid = attrgetter(j)(self.params.pid)
self.get_logger().info(f"joint name: {j}")
self.get_logger().info(f"p: {pid.p}")
self.get_logger().info(f"i: {pid.i}")
self.get_logger().info(f"d: {pid.d}")
Then, do: ros2 run generate_parameter_module_example test_node --ros-args --params-file src/generate_parameter_library/example_python/config/implementation.yaml
and you'll get:
Note that the "d" term has gotten the value from implementation.yaml, while the "p" term and "i" term have not.
Finally, if we edit generate_parameter_library/example_python/generate_parameter_module_example/parameters.yaml, so that in the PID / map joints section, we now have:
Hi,
I've noticed that using mapped parameters with Python nodes doesn't work correctly; the parameter will appear correct from the CLI with
ros2 param get
but accessing it internally in the Python node it keeps the default value, except for whichever mapped parameter is the last one declared in the YAML definitions.An example, making minimal changes to the Python
generate_parameter_module_example
:generate_parameter_library/example_python/generate_parameter_module_example/minimal_publisher.py
you have:Then, do:
ros2 run generate_parameter_module_example test_node --ros-args --params-file src/generate_parameter_library/example_python/config/implementation.yaml
and you'll get:
Notice that the PID parameters are all 1.0, the default value, instead of the
as defined in
implementation.yaml
.Then, if you add a P term and D term to the above, so that you have:
then rebuild and run again, you'll get:
Note that the "d" term has gotten the value from implementation.yaml, while the "p" term and "i" term have not.
Finally, if we edit
generate_parameter_library/example_python/generate_parameter_module_example/parameters.yaml
, so that in the PID / map joints section, we now have:and then rebuild and run again, we get:
Note that now the "P" term is from (my modified) implementation.yaml and the "i" and "d" terms are the defaults.
Thank you for a great tool!
The text was updated successfully, but these errors were encountered: