ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ros2 rclpy list parameters from node

asked 2019-06-28 13:30:24 -0600

updated 2019-06-29 15:46:08 -0600

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()
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-07-04 12:21:07 -0600

jubeira gravatar image

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.....

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!

edit flag offensive delete link more

Comments

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()))

artivis gravatar image artivis  ( 2019-07-04 14:43:06 -0600 )edit

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.

jubeira gravatar image jubeira  ( 2019-07-04 14:47:50 -0600 )edit

Thanks for the precision ! Cheers.

artivis gravatar image artivis  ( 2019-07-04 15:05:50 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-06-28 13:30:24 -0600

Seen: 1,900 times

Last updated: Jul 04 '19