msg是一个描述ROS中消息的域的简单的文本文件,它用来为消息产生不同语言的源代码。
一个srv文件描述一个服务,它由两部分组成,请求和服务。
msg文件被存储在一个包的msg目录下,srv文件被存储在srv目录下。msg是简单的文本文件,它的每一行由一个与的类型和域的名字组成。你可以使用的域的类型有:
int8, int16, int32, int64 (plus uint*) float32, float64 string time, duration other msg files variable-length array[] and fixed-length array[C]
Header header
Header header string child_frame_id geometry_msgs/PoseWithCovariance pose geometry_msgs/TwistWithCovariance twist
int64 A int64 B --- int64 Sum
打开之前,我们所建立的包:
cd ~/catkin_ws/src/beginner_tutorials
mkdir msg
echo "int64 num" > msg/Num.msg
vim package.xml
<build_depend>message_generation</build_depend> <run_depend>message_runtime</run_depend>
vim CMakeLists.txt
# Do not just add this line to your CMakeLists.txt, modify the existing line find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation)
catkin_package( ... CATKIN_DEPENDS message_runtime ... ...)
# add_message_files( # FILES # Message1.msg # Message2.msg # )
add_message_files( FILES Num.msg )
generate_messages()
rosmsg show [message type]
rosmsg show Num
[beginner_tutorials/Num]: int64 num
roscd beginner_tutorials
mkdir srv
roscp [package_name] [file_to_copy_path] [copy_path]
roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv
vim CMakeLists.txt
# Do not just add this line to your CMakeLists.txt, modify the existing line
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation)
# add_service_files( # FILES # Service1.srv # Service2.srv # )
add_service_files( FILES AddTwoInts.srv )
使用rossrv show可以查看我们刚刚建立的服务类型,它的使用方法和rosmsg show相似,用法如下:
rossrv show <service type>
rossrv show beginner_tutorials/AddTwoInts
int64 a int64 b --- int64 sum
vim CMakeLists.txt
# generate_messages( # DEPENDENCIES # # std_msgs # Or other packages containing msgs # )
generate_messages( DEPENDENCIES std_msgs )
现在重新构建一下这个包:
cd ../..
catkin_make
cd -
~/catkin_ws/devel/include/beginner_tutorials/
~/catkin_ws/devel/lib/python2.7/dist-packages/beginner_tutorials/msg
~/catkin_ws/devel/share/common-lisp/ros/beginner_tutorials/msg/