0
$\begingroup$

Rosanswers logo

Is there an easy way to list parameters from an rclpy Node ?? I can 'manually' set up a service client and do the list_parameters call but it feels like this should be abstracted,

Current solution,

class Dummy(Node):
  def __init__(self):
      super().__init__('dummy', allow_undeclared_parameters=True,
                       automatically_declare_parameters_from_overrides=True)
  
      service_name = self.get_name() + '/list_parameters'
      client = self.create_client(ListParameters, service_name)

      while not client.service_is_ready():
          time.sleep(0.1)
          
      request = ListParameters.Request()
      future = client.call_async(request)
  
      # wait for response
      rclpy.spin_until_future_complete(self, future)
  
      if future.result is not None:
          response = future.result()
          for name in sorted(response.result.names):
              print('  {name}'.format_map(locals()))

Desired,

class Dummy(Node):
      def __init__(self):
          super().__init__('dummy', allow_undeclared_parameters=True,
                           automatically_declare_parameters_from_overrides=True)
          param_list = self.list_parameters()

Originally posted by artivis on ROS Answers with karma: 65 on 2019-06-28

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Hi @Artivis,

The service call is the solution if you need to list the parameters of another node.

If you want to do something with the parameters within the node (Dummy in your case), just use the "private" member self._parameters, which is a map with the parameter names as keys and Parameter objects as values: https://github.com/ros2/rclpy/blob/0.7.4/rclpy/rclpy/node.py#L133.

If you just want a list:

class Dummy(Node):
      def __init__(self):
          super().__init__('dummy', allow_undeclared_parameters=True,
                           automatically_declare_parameters_from_overrides=True)
          param_list = [parameter for parameter in self._parameters.values()]

Hope it helps!


Originally posted by jubeira with karma: 1054 on 2019-07-04

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by artivis on 2019-07-04:
Hi, thanks for the tip !

Is this self._parameters member the place were the parameters live ? The actual concern being to know whether this member is up-to-date at launch time given that allow_undeclared_parameters=True and automatically_declare_parameters_from_overrides=True ? A quick test suggests that yes.

Notice that in my particular example the actual code would be sorted(list(self._parameters.keys()))

Comment by jubeira on 2019-07-04:
Yw! Yes, that's where parameters actually live. Getting them after calling super().__init__ should give you the up-to-date dictionary. And yes, if you just want a sorted list of names that line should be just fine.

Comment by artivis on 2019-07-04:
Thanks for the precision ! Cheers.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.