http://blog.sina.com.cn/s/blog_661159d50100od32.html
参考网址:http://www.ros.org/wiki/ROS/Tutorials/CreatingMsgAndSrv
1,msg和srv介绍:
msg文件包括以上几种类型:
- int8, int16, int32, int64 (plus uint*)
- float32, float64
- string
- time, duration
- other msg files
- variable-length array[] and fixed-length array[C]
srv文件就像msg文件,另外还包括请求和响应两部分,由“----”分开,例如:
int 64 A
int 64 B
---
int64 Sum
其中,A,B是请求者,Sum是响应者。
2,创建一个msg
例子:
(1) 我们在已经创建好的beginner_tutorialspackage上创建msg
$ roscd beginner_tutorials
$ mkdir msg
$ echo "int64 num" >msg/Num.msg
然后,
$ gedit CMakeLists.txt--打开该package的CMakeList.txt,取消“# rosbuild_genmsg()”前的“#”号。
(2)查看msg文件
用法:
$ rosmsg show [messagetype]
例子:
$ rosmsg showbeginner_tutorials/Num
得到结果:
int64 num
另外,也可以直接:
$ rosmsg show Num
得到结果:
[beginner_tutorials/Num]:
int64 num
注:在这个例子,消息类型包括:
-
beginner_tutorials
-- the package wherethe message is defined -
Num
-- The name of themsg Num.
(3) rosmsg帮助
用法:
$ rosmsg-h
得到结果:
Commands:
rosmsg show Show message description
rosmsg users Find files that use message
rosmsg md5 Display message md5sum
rosmsg package List messages in a package
rosmsg packages List packages that contain messages
Type rosmsg <command> -h formore detailed usage
或者:
$ rosmsg show -h
得到结果:
Usage: rosmsg show [options] <messagetype>
Options:
3,创建一个srv
(1) 在我们已经创建好的package上创建srv文件
$ roscd beginner_tutorials
$ mkdir srv
$
roscprospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv--将
AddTwoInts.srv复制到srv/AddTwoInts.srv
$ gedit CMakeLists.txt--打开该package下的CMakeLists.txt,将“#rosbuild_gensrv()”前的“#”去掉。
(2) 查看srv文件
rossrv命令
用法:
$ rossrv show<servicetype>
例子:
$ rossrvshow beginner_tutorials/AddTwoInts
得到结果:int64 a
int64 b
---
int64 sum
$ rosmakebeginner_tutorials --编译更新过的beginner_tutorials package
得到结果:
[ rosmake ] Packages requested are: ['beginner_tutorials']
[ rosmake ] Logging todirectory/home/jason/.ros/rosmake/rosmake_output-20110110-102351
[ rosmake ] Expanded args ['beginner_tutorials'] to:
['beginner_tutorials']
[ rosmake ] Checking rosdeps compliance for packagesbeginner_tutorials.
This may take a fewseconds.
[ rosmake ] rosdep check passed all system dependencies inpackages
[rosmake-0] Starting>>> roslib [ make ]
[rosmake-0] Finished<<< roslib ROS_NOBUILDin package roslib
[rosmake-1] Starting>>> roslang [ make ]
[rosmake-1] Finished<<< roslangROS_NOBUILD in package roslang
[rosmake-1] Starting>>> xmlrpcpp [ make ]
[rosmake-1] Finished<<< xmlrpcppROS_NOBUILD in package xmlrpcpp
[rosmake-0] Starting>>> rosconsole [ make]
[rosmake-0] Finished<<< rosconsoleROS_NOBUILD in package rosconsole
[rosmake-0] Starting>>> std_msgs [ make ]
[rosmake-0] Finished<<< std_msgsROS_NOBUILD in package std_msgs
[rosmake-0] Starting>>> rospy [ make ]
[rosmake-0] Finished<<< rospy ROS_NOBUILDin package rospy
[rosmake-0] Starting>>> roscpp [ make ]
[rosmake-0] Finished<<< roscpp ROS_NOBUILDin package roscpp
[rosmake-0] Starting>>> beginner_tutorials[ make ]
[rosmake-1] Starting>>> rosout [ make ]
[rosmake-1] Finished<<< rosout ROS_NOBUILDin package rosout
[rosmake-0] Finished<<< beginner_tutorials[PASS] [ 7.58 seconds ]
[ rosmake ] Results:
[ rosmake ] Built 11 packages with 0 failures.
[ rosmake ] Summary output to directory
[ rosmake ]/home/jason/.ros/rosmake/rosmake_output-20110110-102351
(3) rossrv帮助
用法:
$ rossrv -h
得到结果:
Commands:
rossrv show Show message description
rossrv users Find files that use message
rossrv md5 Display message md5sum
rossrv package List messages in a package
rossrv packages List packages that contain messages
Type rossrv <command> -h formore detailed usage
或者:
$ rossrv show -h
得到结果:
Usage: rossrv show [options] <servicetype>
Options: