(六)ROS服务和参数理解

来源:互联网 发布:你呀上瘾了网络剧资源 编辑:程序博客网 时间:2024/06/08 10:34
参考网址:
http://www.ros.org/wiki/ROS/Tutorials/UnderstandingServicesParams

1,ROS服务
服务是节点通信之间的另外一种方式,服务允许节点发送请求和接受响应。采用rosservice命令

(1) $rosservice
得到结果:
Commands:
rosservice args print service arguments
rosservice call call the service with the provided args
rosservice find find services by service type
rosservice info print information about service
rosservice list list active services
rosservice type print service type
rosservice uri print service ROSRPC uri
Type rosservice <command> -h formore detailed usage, e.g. 'rosservice call -h'

之后为各个命令参数的解释:
I, $rosservice list
这个命令显示(比如小海龟例子)turtlesim节点提供的服务:
/clear/kill /reset /rosout/get_loggers /rosout/set_logger_level/spawn新的终端打开鼠标控制终端 $ rosrun turtle /turtle1/set_pen/turtle1/teleport_absolute /turtle1/teleport_relative/turtlesim/get_loggers /turtlesim/set_logger_level

II, $ rosservice type [service]
查看服务类型的详细情况:
比如$rosservice type clear
得到结果:std_srvs/Empty--表示当服务call时,没有任何参数(发送请求是没有数据,接受响应时也没有数据)

III, $ rosservice call [service][args]
比如小海龟运行的例子,运行轨迹如下:
(六)ROS服务和参数理解
调用 $ rosservice call clear
得到结果:
(六)ROS服务和参数理解

IV,当服务有参数的情况, 
$ rosservice type spawn | rossrv show--显示服务描述
得到结果:
float32x float32 y float32 theta string name --- string name
$ rosservice call spawn 2 2 0.2 ""---创建新的小海龟,给定参数x,y,theta,name(这里name为空)他自动返回name:turtle2
(六)ROS服务和参数理解

(2),$ rosparam
该命令允许在ROS服务里存储和修改数据,这些参数包括integers,floats, boolean, dictionaries和lists。此命令用YAML标记,比如 1 isan integer, 1.0 isa float, one isa string, true isa boolean, [1, 2, 3] isa list of integers, and {a: b, c: d} isa dictionary

得到结果:
rosparamis a command-line tool for getting, setting, and deletingparameters from the ROS Parameter Server. Commands: rosparam setset parameter rosparam get get parameter rosparam load loadparameters from file rosparam dump dump parameters to file rosparamdelete delete parameter rosparam list list parameternames

I,$ rosparam list
对于小海龟的例子,turtlesim节点有3个参数表示背景颜色
得到结果:
/background_b/background_g /background_r/roslaunch/uris/host_jason_desktop__54527 /run_id

II,rosparam 设置和获取参数
用法:
$ rosparam set [param_name]
$ rosparam get [param_name]

例如,对于小海龟例子:
$ rosparam set background_r 150
得到如下结果:
(六)ROS服务和参数理解

$ rosparam getbackground_g
得到结果:
86
我们也可以得到所有的参数
$ rosparam get /
得到结果:
background_b:255 background_g: 86 background_r: 150 roslaunch: uris:{host_jason_desktop__54527: 'http://jason-desktop:54527/'} run_id:5421a332-1df1-11e0-ad25-0025116338f1


III,rosparam dump 和 rosparamload
$ rosparam dump [file_name]---将得到的参数进行存储到一个文件中
比如小海龟的例子:
$ rosparam dump params.yaml---将参数存储到params.yaml文件中

$ rosparam load [file_name] [namespace]---重载参数文件,并写入新的命名空间
比如小海龟的例子:
$ rosparam load params.yaml copy---将params.yaml 写入copy文件夹或者命名空间内
$ rosparam get copy/background_b---查看获取background_b参数的值
得到结果:
255





0 0
原创粉丝点击