[Documentation] [TitleIndex] [WordIndex

一个参数服务器是一个多变量的、共享的、能够通过网络API进入的词典。节点使用这个服务器在运行时来存储或者检索参数。因为它不是为了高性能的应用而设计的,所以最好用它来存储一些静态的、非二进制的数据,例如初始化时的配置参数。它被设计为全局可见的,因此你的机器能够轻而易举地检索系统的配置状态,并且在必要时进行更改。

参数服务器是基于XMLRPC来实施,然后再ROS Master中运行,这意味着它的API可以在普通的XMLRPC库中访问。

参数

参数使用常规的ROS命名规则(参见ROS naming convention)。这意味着ROS参数有一个层级来匹配在 topicsnodes中使用的命名空间。 这个层级是用来防止参数命名发生冲突。同时,采用层及方案也可以允许参数被单独或者作为一树来访问。例如,在下面的参数中:

/camera/left/name: leftcamera
/camera/left/exposure: 1
/camera/right/name: rightcamera
/camera/right/exposure: 1.1

参数 /camera/left/name 的值为 leftcamera。你同样可以从/camera/left,中得到这个值,/camera/left是一个字典。

name: leftcamera
exposure: 1

And you can also get the value for /camera, which has a dictionary of dictionaries representation of the parameter tree:

left: { name: leftcamera, exposure: 1 }
right: { name: rightcamera, exposure: 1.1 }

NOTE: The current implementation does not enforce the naming conventions of parameter names. However in the future they may be so you should follow them.

Parameter Types

The Parameter Server uses XMLRPC data types for parameter values, which include:

You can also store dictionaries (i.e. structs) on the Parameter Server, though they have special meaning. The Parameter Server represents ROS namespaces as dictionaries. For example, imagine you set the following three parameters:

/gains/P = 10.0
/gains/I = 1.0
/gains/D = 0.1

You can either read them back separately, i.e. retrieving /gains/P would return 10.0, or you can retrieving /gains, which would return a dictionary:

{ 'P': 10.0, 'I': 1.0, 'D' : 0.1 }

Just like the ROS naming hierarchy, you can nest dictionaries within dictionaries to represent child namespaces.

私有参数

The ROS naming convention refers to ~name as a private name. These private names primarily are for parameters specific to a single Node. The ~ prefix prepends the Node's name to use it as a semi-private namespace -- they are still accessible from other parts of the system, but they are generally protected from accidental name collisions.

You can use remapping arguments to specify node parameters on the command line by changing the tilde ~ to an underscore _, e.g.:

rosrun rospy_tutorials talker _param:=1.0

参数工具

rosparam命令工具允许你在参数服务器中使用YAML语法对参数进行查询和设置。

客户端库支持

Python

参见 rospy overview.

C++

can roscpp overview.


2024-12-07 14:41