[Documentation] [TitleIndex] [WordIndex

The ROS Parameter Server can store strings, integers, floats, booleans, lists, dictionaries, iso8601 dates, and base64-encoded data. Dictionaries must have string keys.

rospy's API is a thin wrapper around Python's builtin xmlrpclib library, so you should consult that documentation on how to properly encode values. In most cases (booleans, ints, floats, strings, arrays, dictionaries), you can use values as-is.

NOTE: parameter server methods are not threadsafe, so if you are using them from multiple threads, you must lock appropriate.

Getting parameters

rospy.get_param(param_name)

Setting parameters

As described earlier, you can set parameters to store strings, integers, floats, booleans, lists, and dictionaries. You can also use iso8601 dates and base64-encoded data, though those types are discouraged as they are not commonly used in other ROS client libraries. Dictionaries must have string keys as they are considered to be namespaces (see example below).

rospy.set_param(param_name, param_value)

Parameter existence

Testing for parameter existence is useful if you wish to save network bandwidth transferring the parameter value or if you don't wish to use try/except blocks with get_param and delete_param.

rospy.has_param(param_name)

Deleting parameters

rospy.delete_param(param_name)

Retrieve list of parameter names

New in ROS indigo

rospy.get_param_names()

Searching for parameter keys

There are times where you want to get a parameter from the closest namespace. For example, if you have a "robot_name" parameter, you just want to search upwards from your private namespace until you find a matching parameter. Similarly, if you have a group of camera nodes, you may wish to set some parameters commonly in a shared namespace but override others by setting them in private (~name) namespace.

NOTE: in order to use search_param effectively, you should use it with relative names instead of /global and ~private names.

rospy.search_param(param_name)

If this code appears in the node /foo/bar, rospy.search_param will try to find the parameters

  1. /foo/bar/global_example

  2. /foo/global_example

  3. /global_example

in this order.

Getting parameter names

rospy.get_param_names()


2024-11-23 17:51