1.在工作空间下创建一个关于消息的包;
mkdir -p ~/catkin_ws/src cd src catkin_create_pkg msg_topic roscpp rospy std_msgs message_generation message_runtime cd msg_topic mkdir msg//这里要创建一个msg的文件夹,将消息文件保存到这里,否则会找不到文件
2.修改消息包下的CMakeLists.txt文件:
cmake_minimum_required(VERSION 2.8.3) project(zx_msg_topic) find_package(catkin REQUIRED COMPONENTS message_generation message_runtime roscpp rospy std_msgs ) add_message_files( FILES 消息文件名.msg ) generate_messages( DEPENDENCIES std_msgs ) catkin_package( # INCLUDE_DIRS include LIBRARIES msg_topic //创建的消息包名 CATKIN_DEPENDS message_generation message_runtime roscpp rospy std_msgs # DEPENDS system_lib ) include_directories( # include ${catkin_INCLUDE_DIRS} )
3.修改package.xml文件:
<exec_depend>message_generation</exec_depend> <build_depend>message_runtime</build_depend>
4,运行以下指令判断消息类型是否创建成功
rosmsg show msg_topic/消息文件名.msg