Understanding ROS Services and Parameters
Understanding ROS Services and Parameters
If continuing from earlier, please close down all currently running terminals.
- Services: allow nodes to send a request and receive a response.
1) In a terminal, run roscore:
roscore
2) In a new terminal (terminal 2) run the turtle simulation:
rosrun turtlesim turtlesim_node
3) In a new terminal (terminal 3) run a controller to be able to control the turtle with keystrokes:
rosrun turtlesim turtle_teleop_key
You should be able to move the turtle. If not, make sure you have this terminal 3 selected, then try pressing the arrow keys again. (If on a vm, there might be a slight lag to start)
4)In a new terminal (terminal 4) list the services the turtle sim can provide:
rosservice list
You will see a list reset, clear, spawn, kill, turtle1/set_pen, /turtle1/teleport_absolute, /turtle1/teleport_relative, turtlesim/get_loggers, and turtlesim/set_logger_level.
5) In terminal 4, use rosservice type [service] to display information on a service that was found earlier with rosservice list:
rosservice type clear
6) In terminal 4, use rosservice call [service] [args] to use a service found earlier with rosservice list:
rosservice call clear
7) In terminal 4, view the information on the service spawn:
rosservice type spawn| rossrv show
The information tells us that we can spawn a turtle in the same window at a specified location and orientation.
8) In terminal 4, spawn the new turtle with:
rosservice call spawn 2 2 0.2 ""
9) In terminal 4, list the parameters the node (our simulation) has on the param server:
rosparam list
10) In terminal 4, use rosparam set [param_name] to set parameters:
rosparam set background_r 150
The background color parameter has been changed.
11) In terminal 4, to see the change made to the parameters:
rosservice call clear
12) In terminal 4, use rosparam get [param_name] to retrieve parameters:
rosparam get background_g
or
rosparam get /
To see all parameters.
13) In terminal 4, use rosparam dump [file_name] [namespace] to dump parameters to a file:
rosparam dump params.yaml
14) In terminal 4, use rosparam load [file_name] [namespace] to retrieve the newly created file contents in the same or different workspaces:
rosparam load params.yaml copy