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

Getting all parameter names using C++

asked 2011-03-28 20:32:28 -0600

Aslund gravatar image

updated 2011-03-29 16:12:28 -0600

mjcarroll gravatar image

I am developing an application where I need to get all the parameter names from the parameter server (without specifically knowing the names of each parameter). I have only seen it possible on python using "getParamNames(caller_id)", but is something similar possible using C++?

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
0

answered 2011-04-03 13:47:04 -0600

tfoote gravatar image

You can get arbitrarily complex data structures off the parameter server using the XMLRPC data structure.

See bool ros::NodeHandle::getParam(const std::string & key, XmlRpc::XmlRpcValue & ) const in the API docs.

The only downside is that you have to use XMLRPC data types manipulation.

edit flag offensive delete link more

Comments

Thanks, might be an option. I late also found out that it is not totally easy to figure out data types in C++ from a random variable, so I think Python does things pretty smooth and easy. Due to the simplicity of the program, then I do not expect the big overhead in using it over C++.
Aslund gravatar image Aslund  ( 2011-04-05 01:50:55 -0600 )edit
1

answered 2011-04-03 00:40:42 -0600

I don't think there is direct support for this by roscpp, so you probably have to query the parameter server directly. You can have a look at the Parameter Server API and at the file roscpp/src/libros/param.cpp for an idea how to do that.

edit flag offensive delete link more
0

answered 2011-03-29 12:23:19 -0600

Aslund gravatar image

I kinda gave up on finding a solution using C++, so I sticked with python, but if someone knows how to do it using C++ then I would be happy to hear. For people interested in the same topic, then I have applied the code below for reading the parameter server and publish the values, so far only for simple data types. I am using my own message types to publish the data, which contain the name and a value, which is either int, float, bool or a string.

#!/usr/bin/env python

import roslib
roslib.load_manifest('ros_rws_plugin')
import sys
import rospy
from ros_rws_plugin.msg import *


def main(args):
    rospy.init_node('read_param')

    pub_int = rospy.Publisher('parameter/int', propertyInt )
    pub_float = rospy.Publisher('parameter/float', propertyFloat )
    pub_bool = rospy.Publisher('parameter/bool', propertyBool )
    pub_str = rospy.Publisher('parameter/string', propertyString )

    rospy.set_param("int", 2)
    rospy.set_param("float", 2.2)

    r = rospy.Rate(5)

    while not rospy.is_shutdown(): 
        names = rospy.get_param_names()

        for name in names:
            if type( rospy.get_param(name) ) is int : 
                pub_int.publish( propertyName=name, propertyValue=rospy.get_param(name) )
            elif type( rospy.get_param(name) ) is float : 
                pub_float.publish( propertyName=name, propertyValue=rospy.get_param(name) )
            elif type( rospy.get_param(name) ) is bool : 
                pub_bool.publish( propertyName=name, propertyValue=rospy.get_param(name) )
            elif type( rospy.get_param(name) ) is str : 
                pub_str.publish( propertyName=name, propertyValue=rospy.get_param(name) )



        r.sleep()

if __name__ == '__main__':
    main(sys.argv)
edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-03-28 20:32:28 -0600

Seen: 3,397 times

Last updated: Apr 03 '11