Ask Your Question
1

How are YAML files used in ROS?

asked 2020-07-07 06:26:10 -0500

Kansai gravatar image

I searched and couldn't find. I would like to know what are YAML files for in ROS and how to use them? Examples or tutorials would be great. I have read about the YAML format used in command lines and that is not what I am asking. Specifically I have a system developed in ROS and it has YAML files and I want to understand its use.

Oh and also, are they still used in ROS2?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
9

answered 2020-07-07 06:56:47 -0500

Weasfas gravatar image

Hi @Kansai,

YAML files are usually used in ROS to load Node configuration parameters in the ROS Parameter server. There are several ways lo load a YAMLfile in the parameter server:

You can load the file with the command line:

rosparam load my_cfg.yaml

Note: If you want to know more about rosparam take a look here.

You can also use this YAML file from a launch file with the rosparam tag:

<rosparam command="load" file="$(find my_pkg)/my_cfg.yaml" />

Note: If tou want to know more about this feaure check this, and if you do not know what roslaunch you can check this.

Then, after loading the file in the parameter server you will be able to get any parameter from there.

With command line:

rosparam list # List all ROS parameters
rosparam get /my_parameter # Get my_parameter value

But the most interesting part is that you can do this programatically generating a specific configuration for your node. Both roscpp and rospy have functions to deal with parameters, with get, set, search... instructions.

For instance if you have a C++ node and you want this node to have a configurable rate, you can load your rate in the parameter server:

rosparam set /node_rate "20.0" # or with yaml a file.

and retrieve this parameter in the node with:

ros::NodeHandle nh;
double rate;
nh.getParam("node_rate" , rate);

even you can set default params if the parameter is not found in the server with:

nh.param<double>("node_rate ", rate, 10.0);

The python API is very similar so If you want to know more about roscpp you can check this, for python this.

As for your last question, of course it is used in ROS2 since it is a very powerful tool to generate any kind of configurable enviroment.

The main difference is that in ROS2 there is no "global parameter server" since all parameters are "owned" by individual nodes. Apart from that, the idea is very similar, although function usage are a bit different.

You can learn more about command line tool for ROS2 parameters here and how to use it programatically here: C++ and Python.

Hope this helped you solving your doubts about this topic.

Cheers!

edit flag offensive delete link more

Comments

1

This is a beautiful answer, with complete explanation and all helpful links. Thanks for going out of your way to be so helpful and make this community better!

parzival gravatar image parzival  ( 2020-07-07 09:15:48 -0500 )edit

This was wonderfully put.

karry3775 gravatar image karry3775  ( 2020-11-15 12:33:36 -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

2 followers

Stats

Asked: 2020-07-07 06:26:10 -0500

Seen: 2,426 times

Last updated: Jul 07 '20