0
$\begingroup$

Rosanswers logo

How should I do that? I've looked up along the roslaunch and dynamic reconfigure code but I don't find it. Do you know any standard function to do it?

By the momment I've done this (but I understand that should exist another way):

config = yaml.load(open(custom_configuration_file))
rospy.loginfo(config)
self.recursive_set_param(config)
...

def recursive_set_param(self, config, key_path=""):
        for k in config.keys():
            data = config[k]
            
            full_qualified_key = key_path + "/" + k
            if data.__class__ == dict:
                self.recursive_set_param(data, full_qualified_key)
            else:
                rospy.set_param(full_qualified_key, config[k])
                rospy.loginfo("SETTING PARAM %s -> %s", full_qualified_key, data)

Originally posted by Pablo Iñigo Blasco on ROS Answers with karma: 2982 on 2013-03-21

Post score: 3


Original comments

Comment by dornhege on 2013-03-21:
Any reason why you want to do that? There might be simpler ways to achieve your goal.

Comment by Pablo Iñigo Blasco on 2013-03-27:
For sure! and that is what I was looking for!

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

If you are doing python, you could just use rosparam and reuse its load functionality.

Just check out the basic script in your distro. You should be able to import the function in your script and thus do exactly the same as rosparam load does.


Originally posted by dornhege with karma: 31395 on 2013-03-21

This answer was NOT ACCEPTED on the original site

Post score: 3


Original comments

Comment by Pablo Iñigo Blasco on 2013-03-27:
I've followed your guidelines and I found how to do it with the rosparam API. I've added another response to this answer with the code. I expected to find a simple method to import the yaml file, but at the end a few lines of code where needed. Thanks! +1

Comment by Pablo Iñigo Blasco on 2013-03-27:
By the way. One of the problems of using this dynamic loading approach is that the nodes which uses the dynamic reconfigure server don't notice the change. This is related with this question: http://answers.ros.org/question/58820/dynamic-reconfigure-server-how-explicity-fetch-parameters/

$\endgroup$
0
$\begingroup$

Rosanswers logo

You can load the yaml file in a launchfile and then, in the node, get the needed params. No parsing needed.

Add to your launchfile a

<rosparam file="path/to/your/file.yaml" />

and in that yamlfile, structure it like this:

node_name1:
  param_name1: value
  param_name2: value

node_name2:
  param_name1: value
  param_name2: value

Originally posted by Miquel Massot with karma: 1471 on 2013-03-21

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by Pablo Iñigo Blasco on 2013-03-27:
yeah but that forces you to load the configuration file through a launch file. In my case, my node wants to load at runtime and proactively a configuration file (without the human intervention).

Comment by neil on 2017-08-02:
but how can we get the param_name1's value in cpp files?

Comment by knxa on 2017-09-04:
NodeHandle::getParam

$\endgroup$
0
$\begingroup$

Rosanswers logo

Following the guidelines of dornhege, this looks the code that it is needed to load a yaml file dynamically (tested in Fuerte).

I firstly expected to be able to use the rosparam.yamlmain method. But it is not possible because it is programed using as argument sys.args.

The below for loop looks like it could be avoided using some method, but if such method exist I haven't found it.

import roslib
roslib.load_manifest("rosparam")
import rosparam

paramlist=rosparam.load_file("/path/to/myfile",default_namespace="my_namespace")
for params, ns in paramlist:
    rosparam.upload_params(ns,params)

Originally posted by Pablo Iñigo Blasco with karma: 2982 on 2013-03-27

This answer was ACCEPTED on the original site

Post score: 4

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.