cbandera / rosparam_handler

An easy wrapper for using parameters in ROS
Other
47 stars 26 forks source link

[Feature Request] Generate .yaml file from .params #30

Closed artivis closed 7 years ago

artivis commented 7 years ago

I was looking for a way to generate a yaml file from a params file at any time (not only at compile time).

Expected workflow :

given the following dummy.params

#!/usr/bin/env python
from rosparam_handler.parameter_generator_catkin import *
gen = ParameterGenerator()

# Parameters with different types
gen.add("int_param", paramtype="int", description="An Integer parameter")
gen.add("str_param", paramtype="std::string", description="A string parameter",  default="Hello World")

gen.add("dummy", paramtype="double", description="My Dummy parameter", level=0,
edit_method="", default=5.2, min=0, max=10, configurable=True,
global_scope=False, constant=False)

#Syntax : Package, Node, Config Name(The final name will be MyDummyConfig)
exit(gen.generate("rosparam_tutorials", "example_node", "Tutorial"))

A command such as :

rosrun rosparam_handler generate_yaml path/to/dummy.params

Would generate : dummy.yaml

## An Integer parameter
#int_param

## An string parameter
str_param = Hello Wold

## My Dummy parameter
## [min,max] : [0,10]
## live in relative namespace
## is configurable from dynamic_reconfigure
## is not constant
dummy = 5.2

with all defined parameters with description and as much info as available.
Only parameters with default value would be un-commented.

The problem is that dummy.params is somewhat self-contained and I couldn't really find what would be the entry point for the generate_yaml.
Does that feature make sense to anyone else ? Any idea on how to approach the issue ?

cbandera commented 7 years ago

Hello @artivis, thanks for the idea. I have played around a little and come up with a possible solution in commit 718d617. Please have a look at it and see whether it works for you. After building the package and sourcing, you should be able to use the syntax you suggested:

rosrun rosparam_handler generate_yaml path/to/dummy.params

It will generate the yaml file in your current directory.

cbandera commented 7 years ago

Things that I am not sure about yet:

Is there a better way to solve this?

artivis commented 7 years ago

Hi @cbandera ! This is great, thanks a lot for your work.
I will give it a shot asap and give you feedback.

As for your questions, I do not think that the yaml file should be generated at compilation for two simple reasons. First I believe that the user should pro-actively generate it, thus calling the command. The second point is actually the one you already raised, where would you put such file during compilation ? Will the user have to dig into the devel folder to find it ? That wouldn't be very handy...

artivis commented 7 years ago

Just try this with a couple of .params files I'm using and it works smoothly.
I'm not using all available features in these files so I couldn't assert that everything works but it definitely looks good.
To its current state, the scripts prints in the terminal the whole content of the dictionary. I suppose this is for debugging purpose.

artivis commented 7 years ago

Examples here and there.