1. Custom topic message customization, we first create a msg type file named Person.msg under the directory /catkin_ws/src/learning_sun/msg
2. Enter in the file:
string name
uint8 sex
uint8 age
uint8 unknown = 0
uint8 male = 1
uint8 female = 2
uint32 seq
time stamp
string frame_id
3. After the file is created, you need to compile the file and return to the src directory. First modify the package.xml file, add dependencies, and enter in the file:
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
4. After modifying the package.xml file, we then modify the configuration options in the CMakeList file, open the CMakeList file, and add or modify the following options:
Note here that add_message_files() and generate_messages() must be compiled before catkin_package()
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
geometry_msgs
message_generation
)
add_message_files(
FILES
Person.msg
)
generate_messages(
DEPENDENCIES
std_msgs
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES learning_sun
# CATKIN_DEPENDS roscpp rospy std_msgs
# DEPENDS system_lib
CATKIN_DEPENDS geometry_msgs roscpp rospy std_msgs message_runtime
)
5. After modifying the file, exit to the catkin_ws directory and execute the catkin_make command to compile the file. When the progress reaches 100%, the compilation is complete.
6. Enter the command rosmsg show Person
to see if a custom message into force, if in effect, will have the following log:
[learning_sun/Person]:
uint8 unknown=0
uint8 male=1
uint8 female=2
string name
uint8 sex
uint8 age
uint32 seq
time stamp
string frame_id
7. This is the end of the custom message experiment