rosh overview: Roshlets | Basics | Messages | Parameters | Topics | Services | Nodes | Topic Tools | Packages | Bags | Bagys | roslaunch

Parameters

parameters

The parameters object lets you read and write values to the Parameter Server. This object follows the general ROSH convention for converting ROS names, i.e. to access the parameters /foo/bar/gains, you would use:

  • parameters.foo.bar.gains

You can also use mapping-style lookups on parameters, which is useful if you are dealing with string names:

  • parameters['/foo/bar'].gains

Retrieving a parameter value

To retrieve a parameter value, simply do a method call on the parameter you want, e.g.:

In [3]: parameters.run_id()
Out[3]: '7ab647bc-c29f-11df-aef2-003048fb8348'

Setting a parameter value

You can set values on the Parameter Server simply by using normal Python assignment, e.g.:

In [4]: parameters.foo = 1

In [5]: parameters.foo
Out[5]: 1

You can also use Python dictionaries to assign create namespaces, e.g.:

In [6]: parameters.bar = dict(child1=1, child2=2)

In [7]: parameters.bar
Out[7]: Boxed[{'child1': 1, 'child2': 2}]

Loading rosparam data

rosparam(filename)

  • The rosparam() function loads a rosparam YAML file from disk, e.g.

    In [1]: roscd rosparam
    /home/foo/ros/tools/rosparam
    
    In [2]: rosparam('example.yaml')
    Out[2]: 
    {'dict1': {'head': 1, 'knees': 3, 'shoulders': 2, 'toes': 4},
     'float1': 3.1415899999999999,
     'float2': 1234.5,
     'integer1': 1,
     'integer2': 2,
     'list1': ['head', 'shoulders', 'knees', 'toes'],
     'list2': [1, 1, 2, 3, 5, 8],
     'preformattedtext': 'This is the first line\nThis is the second line\nLine breaks are preserved\nIndentation is stripped\n',
     'robots': {'child': {'grandchildparam': 'a grandchild namespace param'},
                'childparam': 'a child namespace parameter'},
     'string1': 'bar',
     'string2': '10'}

rosparam_str(yaml_data)

  • Parse rosparam/YAML string, e.g.:
    In [1]: data = 'string1: bar\nstring2: !!str 10\npreformattedtext: |\n  This is the first line\n  This is the second line\n  Line breaks are preserved\n  Indentation is stripped\nlist1:\n - head\n - shoulders\n - knees\n - toes\nlist2: [1, 1, 2, 3, 5, 8]\ndict1: { head: 1, shoulders: 2, knees: 3, toes: 4}\ninteger1: 1\ninteger2: 2\nfloat1: 3.14159\nfloat2: 1.2345e+3\nrobots:\n  childparam: a child namespace parameter\n  child:\n     grandchildparam: a grandchild namespace param\n'
    
    In [2]: rosparam_str(data)
    Out[2]: 
    [({'dict1': {'head': 1, 'knees': 3, 'shoulders': 2, 'toes': 4},
       'float1': 3.1415899999999999,
       'float2': 1234.5,
       'integer1': 1,
       'integer2': 2,
       'list1': ['head', 'shoulders', 'knees', 'toes'],
       'list2': [1, 1, 2, 3, 5, 8],
       'preformattedtext': 'This is the first line\nThis is the second line\nLine breaks are preserved\nIndentation is stripped\n',
       'robots': {'child': {'grandchildparam': 'a grandchild namespace param'},
                  'childparam': 'a child namespace parameter'},
       'string1': 'bar',
       'string2': '10'},

Wiki: rosh/Overview/Parameters (last edited 2010-10-22 17:35:46 by KenConley)