Ask Your Question
3

load yaml with code

asked 2014-05-26 06:50:01 -0500

crpizarr gravatar image

updated 2014-05-26 06:51:20 -0500

Is there a way to load a .yaml file in python directly to the parameter server? I want to do something like "rosparam load", but programmatically, as a callback for an event in a GUI.

Thanks in advance

edit retag flag offensive close merge delete

Comments

This is duplicate of http://answers.ros.org/question/58819... , there is an answer there.

lucasw gravatar imagelucasw ( 2015-05-26 18:40:47 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2014-05-26 08:22:37 -0500

ahendrix gravatar image

You should be able to load a YAML file into a python data structure using the pyyaml module.

You can then use rospy.set_param('/prefix', data) to push the entire contents of your data structure to a prefix on the parameter server.

edit flag offensive delete link more

Comments

It's not the same as doing "rosparam load" . I've tried what you propose, but it does not make the namespace structure as "rosparam load" does. I mean, with "rosparam load file.yaml" I load all the namespaces in the file, that is, the data I can access is just the leaves of the structure. and all the internal nodes in the file are loaded as namespaces. With rospy.set_param, I just set the "/prefix" with a dictionary, so I can't access the data with rospy.get_param("/prefix/namespace1/namespace2").

crpizarr gravatar imagecrpizarr ( 2014-05-26 09:29:48 -0500 )edit

That's a bit surprising. What sort of structure/namespaces do you get on the parameter server after uploading a dict with set_param? It might be worth adding what you've tried to your question, particularly a small piece of python and the resulting `rosparam list /prefix` and `rosparam get /prefix`

ahendrix gravatar imageahendrix ( 2014-05-26 10:32:40 -0500 )edit
0

answered 2014-05-27 04:50:22 -0500

crpizarr gravatar image

updated 2014-05-27 05:03:38 -0500

In response to @ahendrix, this an use-case

the data: "asdf.yaml"

    namespace1: {data1: 1, data2: 2}
    namespace2: {data3: 3, data4: 4.5}

the use-case:

> rosparam load asdf.yaml main
> rosparam list
  /main/namespace1/data1
  /main/namespace1/data2
  /main/namespace2/data3
  /main/namespace2/data4
 ...and other ros stuff

> rosparam get main/namespace1/data1
  1

In an IPython console

> data = rosparam.load_file("asdf.yaml")
[({'main': {'namespace1': {'data1': 1, 'data2': 2}, 'namespace2': {'data3': 3, 'data4': 4.5}}},'/')]
# The parameter server is not touched, it just returns a list
> rospy.set_param("main", data)
> rospy.get_param("main")
   [[{'namespace1': {'data1': 1, 'data2': 2}, 'namespace2': {'data3': 3, 'data4': 4.5}}, '/']]

Outside, in another terminal:

> rosparam list
   /main
> rosparam get main/namespace1/data1
   ERROR: Parameter [/main/namespace1/data1] is not set

So it doesn't load the namespace structure I think.

edit flag offensive delete link more

Comments

Does this work if you load your yaml file using the python yaml module, as I suggested?

ahendrix gravatar imageahendrix ( 2014-05-27 06:54:10 -0500 )edit
1

Oh, sorry, i overlooked that. With the yaml module it does work. Thanks. By the way, what is the utility of the rosparam.load_file method, if it is not to load a file into the parameter server.?

crpizarr gravatar imagecrpizarr ( 2014-05-27 10:30:29 -0500 )edit
1

This function does what I expected it to do:

def load_params_from_yaml(complete_file_path):
    from rosparam import upload_params
    from yaml import load
    f = open(full_path, 'r')
    yamlfile = load(f)
    f.close()
    upload_params('/', yamlfile)
awesomebytes gravatar imageawesomebytes ( 2014-10-21 05:02:01 -0500 )edit
-1

answered 2014-05-26 07:10:32 -0500

130s gravatar image

Have you tried rosparam set with -t option? http://wiki.ros.org/rosparam#rosparam...

It's possible from .launch file as well (example).

edit flag offensive delete link more

Comments

That is not what I'm looking for. What I want to do is something like this: rosparam.load_something("filename.yaml") and then I want to see the parameters of filename.yaml in the parameter server. Currently the rosparam.load_file method just prints the content of the file in stdout, without touching the parameter server.

crpizarr gravatar imagecrpizarr ( 2014-05-26 08:12:09 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-05-26 06:50:01 -0500

Seen: 6,249 times

Last updated: May 27 '14