In this article from the official Wiki: http://wiki.ros.org/ROS/Tutorials/UnderstandingServicesParams
- ROS service (service)
service is a communication mechanism in ROS, but different from the publish and subscribe theme, the service adopted a "request (request) - response (response)" mechanism for data exchange.
And service-related functions can be carried out using the rosservice command.
rosservice list lists the active service information rosservice call the given parameter called service rosservice type print out the type of service rosservice find to find a given type of service rosservice uri print services ROSRPC source
- rosservice list
This command lists the services that are currently active, such as in the example of a small turtle, we run rosservice list
returns the following:
$ rosservice list /clear /kill /reset /rosout/get_loggers /rosout/set_logger_level /rostopic_21128_1568429034667/get_loggers /rostopic_21128_1568429034667/set_logger_level /rostopic_25467_1568471203069/get_loggers /rostopic_25467_1568471203069/set_logger_level /rqt_gui_py_node_25560/get_loggers /rqt_gui_py_node_25560/set_logger_level /rqt_gui_py_node_25926/get_loggers /rqt_gui_py_node_25926/set_logger_level /spawn /teleop_turtle/get_loggers /teleop_turtle/set_logger_level /turtle1/set_pen /turtle1/teleport_absolute /turtle1/teleport_relative /turtlesim/get_loggers /turtlesim/set_logger_level
- rosservice type
then use rosservice type can view the type of service:
$ rosservice type /clear std_srvs/Empty
Empty indicates that the service is returned without specifying parameters, a feature that is only that action, without data.
- rosservice call
using rosservice call can invoke the service.
Usage is as follows:rosservice call [service] [args]
For example, want to call / clear, then use the following statement:
rosservice call /clear
It will be removed leaving a small turtle movement track.
We can look at the parameters of service / spwan with parameters:
$ rosservice type /spawn | rossrv show float32 x float32 y float32 theta string name --- string name
It can be seen / spawn service parameters for the type of data represented by three float32 position (x, y) and facing and theta represents the name of a string name.
Call the service with the following command:rosservice call /spawn 2 2 0.2 ""
Another is to produce a small turtle:
- rosservice list
- ROS parameters (rosparam)
rosparam allows ROS parameter server ( the Parameter Server storage) and operating parameters (like personal understanding global variable programming). Server parameters to take YAML markup language to store the following data types:
integers (integer), floats (float), boolean (Boolean), dictionaries (dictionaries (key type)), and lists (list type). Parameters related operations using rosparam command is used as follows:
rosparam set the parameter value rosparam get get parameter values rosparam load Load parameters from file rosparam dump storage parameters to file rosparam delete delete parameters rosparam list parameter names are listed
- rosparam list
This command can list all parameter names, such as:
$ rosparam list /background_b /background_g /background_r /rosdistro /roslaunch/uris/host_localhost__35773 /rosversion /run_id
-
rosparam get rosparam set and
may set the parameter values rosparam set, for example, the following command set the background color in the red channel value of 200:rosparam set /background_r 200
You must then call clear service to refresh the background:
$ rosservice call /clear
The background turns pink
Use the following command to get the background of green:
$ rosparam get /background_g 86
Use rosparam get / all command parameter values available:
$ rosparam get / background_b: 255 background_g: 86 background_r: 200 rosdistro: 'kinetic ' roslaunch: uris: {host_localhost__35773: 'http://localhost:35773/'} rosversion: '1.12.14 ' run_id: d0977b84-d694-11e9-b3cd-502b73e82f34
-
rosparam dump and rosparam load
can rosparam dump storage parameters, rosparam load loading parameters:rosparam dump [file_name] [namespace] rosparam load [file_name] [namespace]
You can specify a file name and namespace parameters
following command to write the file params.yaml all parameters of the current namespace.$ rosparam dump params.yaml
Load all parameters following command to copy the file namespace from params.yaml.
$ rosparam load params.yaml copy
Then read the parameter space:
$ rosparam get /copy/background_b
255
- rosparam list