创建
Step 1: 转到catkin_ws/src下
cd catkin_ws/src
Step 2: 创建package,添加依赖项
catkin_create_pkg customized_msgs roscpp rospy std_msgs message_generation message_runtime
Step 3: 打开IDE,在customized_msgs下创建msg文件夹,再在msg文件下创建后缀为.msg的文件
Step 4: 更改CMakeList文件中的以下内容:
add_message_files(
FILES
carry.msg
)
generate_messages(
DEPENDENCIES
std_msgs
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES qq_msgs
CATKIN_DEPENDS message_generation message_runtime roscpp rospy std_msgs
# DEPENDS system_lib
)
Step 5: 确保package.xml文件包含以下四项
<build_depend>message_generation</build_depend>
<build_depend>message_runtime</build_depend>
<exec_depend>message_generation</exec_depend>
<exec_depend>message_runtime</exec_depend>
Step 6: ctrl+shift+b编译
Step 7: 检查
rosmsg show qq_msgs/carry
使用
Step 1: 在需要使用的地方,include头文件
#include <qq_msgs/carry.h>
Step 2: 在CMakeList文件中修改以下内容
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
qq_msgs
)
添加依赖项
add_dependencies(chao_node qq_msgs_generate_messages_cpp)
在加载chao_node前,先加载qq_msgs
Step 3: 在package.xml文件中,确保拥有以下项
<build_depend>qq_msgs</build_depend>
<exec_depend>qq_msgs</exec_depend>