-
创建消息
1 tommy43@tommy43-GL62M-7RD:~/catkin_ws_2$ roscd beginner_tutorials/ 2 tommy43@tommy43-GL62M-7RD:~/catkin_ws_2/src/beginner_tutorials$ mkdir msg 3 tommy43@tommy43-GL62M-7RD:~/catkin_ws_2/src/beginner_tutorials$ echo "int64 num" > msg/Num.msg
在beginner_tutorial包中创建msg文件夹,并用重定向命令将消息内容写入该文件夹中的Num.msg文件中。(注意该消息内容的格式)。
接下来:
tommy43@tommy43-GL62M-7RD:~/catkin_ws_2/src/beginner_tutorials$ vim package.xml
将该文件中的<build_depend>message_generation</build_depend> <run_depend>message_runtime</run_depend>显示出来(去掉注释符号),因为在编译和运行消息的时候我们将会用到这两行代码。
~/catkin_ws_2/src/beginner_tutorials$ rosed beginner_tutorials CMakeLists.txt
编辑CMakelist.txt,将message_generation加入到相应位置:
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
将message_runtime加入依赖包中:
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES beginner_tutorials
CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
# DEPENDS system_lib
)
添加消息文件:
add_message_files(
FILES
Num.msg
)
将生成消息的函数uncomment出来:
generate_messages(
DEPENDENCIES
std_msgs
)
测试一下是否能够顺利生成消息:
tommy43@tommy43-GL62M-7RD:~/catkin_ws_2/src/beginner_tutorials$ rosmsg show beginner_tutorials/Num
int64 num
-
生成服务
tommy43@tommy43-GL62M-7RD:~/catkin_ws_2/src/beginner_tutorials$ mkdir srv
创建服务所在的文件夹
从rospy_tutorials中将这个服务拷贝过来:
tommy43@tommy43-GL62M-7RD:~/catkin_ws_2/src/beginner_tutorials/srv$ roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv cp: cannot create regular file 'srv/AddTwoInts.srv': No such file or directory tommy43@tommy43-GL62M-7RD:~/catkin_ws_2/src/beginner_tutorials/srv$ roscp rospy_tutorials AddTwoInts.srv AddTwoInts.srv tommy43@tommy43-GL62M-7RD:~/catkin_ws_2/src/beginner_tutorials/srv$ ls AddTwoInts.srv
注意这里第一次拷贝时候的错误——我们是要将第一个参数拷贝第二个参数所表征的位置中去。
在包中的CMakelist中添加我们将要使用的服务文件:
add_service_files(
FILES
AddTwoInts.srv
)
测试一下:
tommy43@tommy43-GL62M-7RD:~/catkin_ws_2/src/beginner_tutorials$ rossrv show beginner_tutorials/AddTwoInts int64 a int64 b --- int64 sum
DONE!
浙公网安备 33010602011771号