ROS Commands – ROS Parameter
Parameter is also an important concept of ROS. We have shortly described ROS Parameter in ROS Terminologies blogs, now we will go through ROS Parameter commands.
ROS Parameter Command “rosparam”
First we will check the options which can be used with the command “rosparam”.
Run following command in the terminal
rosparam -h
We can see the options that can be used with “rosparam” command in figure below. Now we will go through these commands one by one.
Note: The order of the commands in above list may be different from the order of the commands in our description. This is because, we will follow the order which is convenient to execute the commands.
Close all terminals, and open three new terminals to run the following three commands in each terminal separately
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
“rosparam list” command
The “rosparam list” command displays the running parameters in the same network.
Open a new terminal and run the command
rosparam list
You can see a list of running parameters as shown in the figure below
“rosparam get” command
In above figure, we can see the number of parameters. Using the command “rosparam get”, we can get value of a specific parameter.
The structure of the command is as follows
rosparam get [Parameter_Name]
Choose the parameter from the list and run the command to get its value.
For example we get the values of the parameters “background_b” and “background_r” one by one.
Run in the terminal
rosparam get background_b
Also run
rosparam get background_r
We can see in the figure below the parameter values. The values (where background_b is 255, and background_r is 69) show that background_b has maximum value, which is also clear from the simulation environment of Turtlesim that the background is of blue color.
In order to get all parameter values, we can use “/” instead of parameter name.
Run the following command in terminals
rosparam get /
We can see the values of all parameters in figure below
“rosparam dump” command
The command “rosparam dump” is used to save the running parameters into the file (the extension of parameter file is .yaml). This command is very useful because it helps saving the current values of parameters which can be used next time (and multiple times).
Run the following command to save current parameter values in the “parameters.yaml” file
rosparam dump ~/parameters.yaml
Here “~/” represents the home directory (/home/userName). Hence the file is saved at home directory. We can go to the directory (/home/kashif), and open the file “parameters.yaml” to see if the parameter values are saved.
Great! The file contained the values of the parameters.
“rosparam set” command
Using the command “rosparam set”, we can assign new value to the specific parameter.
The structure of the command is
rosparam set [Parameter_Name] [Parameter_Value]
As we have already seen the current parameter values in previous example. Where RGB background color values are “255 86 69”. We changed background_g value from 86 to 255. So the new RGB value will be “255 255 69”, and the background color will be changed accordingly.
Run the command
rosparam set background_g 255
Since, turtlesim node is already running, and it will not automatically read and apply the new parameter value. Hence in order to refresh the screen we will run following command
rosservice call clear
After setting new parameter value and refreshing the screen using the above mentioned commands, the background of the Turtlesim simulation screen will be changed as shown in figure below
“rosparam load” command
The command “rosparam load” has opposite function to the previously discussed command “rosparam dump”. The command “rosparam load” loads the file (of extension .yaml) and set current parameters with the values as given in the loaded parameter file.
The structure of the command is
rosparam load [File_Name]
Run the command to load the file “parameters.yaml” that we have previously saved.
rosparam load ~/parameters.yaml
Also run the command to refresh the screen
rosservice call clear
You will see the background color of the Turtlesim simulation will again changed to blue. This is because, when we saved the parameters into the “parameters.yaml” file, the color of the background was blue. So again those parameter values are set which are loaded from the file.
“rosparam delete” command
The parameter can also be deleted using the “rosparam delete” command.
The structure of the command is
rosparam delete [Parameter_Name]
Run the following command to delete the parameter “background_r”
rosparam delete background_r
Now again run the following command to verify if the parameter “background_r” is deleeted.
rosparam list
From above figure it is evident that the “background_r” parameter is not displayed in the list, hence deleted.