ROS Parameters
ROS parameters are parameters in a node which can be modified from their default values. By this definition, the ROS parameters are very useful to be used when we want to be able to modify them quickly, in real-time. ROS parameters can be, for example, USB port numbers, camera calibration parameters, or minimum and maximum motor speeds. The parameters can be of integers, floats, boolean, string, dictionaries, list, and so on.
In C++, a parameter in a node is set and read by using setParam and getParam functions, respectively. These functions can be used with a node handler as the following:
1 2 3 |
ros::NodeHandle nh; nh.setParam("parameter_name", parameter_value); // Reset the parameter value nh.getParam("parameter_name", variable); // Read the parameter value and pass it to variable |
The parameter_value can be directly a value or a variable representing a value. Notice that the data types of the variables “parameter_value” and “variable” above should be declared earlier as any variable needs declaration in C++.
The setParam and getParam can also be used as the following:
1 2 |
ros::param::set("parameter_name", parameter_value); ros::param::get("parameter_name", variable); |
The official documentation can be found here: http://wiki.ros.org/roscpp/Overview/Parameter%20Server
In Python, setting and reading the parameters can be done as follows:
1 2 3 |
rospy.set_param('parameter_name', parameter_value) rospy.get_param('parameter_name') variable = rospy.get_param('parameter_name') |
The official documentation can be found here:
- http://wiki.ros.org/rospy/Overview/Parameter%20Server
- http://wiki.ros.org/rospy_tutorials/Tutorials/Parameters
CLI Commands for ROS Parameters
The following are the CLI commands regarding ROS parameters:
1 2 3 4 5 6 |
rosparam set : used to set parameter rosparam get : used to get parameter rosparam load : used to load parameters from file rosparam dump : used to dump parameters to file rosparam delete : used to delete parameter rosparam list : used to list parameter names |