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

Revision history [back]

click to hide/show revision 1
initial version

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!