ROS Custom Message Type Method

Process

1, the new package in the folder named msg

2, create a message (here to my_msg.msg) in the msg folder, for example, it is to pay attention to the msg name suffix

SUMMARY example as follows:

int32 data1
float64 date2

On message content, it should be noted that if the wrong type, it will not generate a header file. For example float64 wrote the float, then a compile-time error will occur: xxx.h: No SUCH File or Directory; and will not tell you what went wrong, I have encountered such a problem had the pit, so that needs attention .

3, modify CmakeList.txt and package.xml

3.1, add compiled package.xml, run dependencies

<build_depend>message_generation</build_depend>
<build_export_depend>message_generation</build_export_depend>
<exec_depend>message_runtime</exec_depend>

 

3.2、CmakeList.txt 

find_package added message_generation () in

find_package(catkin REQUIRED COMPONENTS
  message_generation
  roscpp
  rospy
  std_msgs
)

add_message_files added my_msg.msg () in

add_message_files(FILES
  my_msg.msg
)

generate_messages()添加std_msgs

generate_messages(DEPENDENCIES
  std_msgs
)

catkin_package()添加message_runtime

catkin_package(
  CATKIN_DEPENDS
  message_runtime)

Finally, add a row add_executable (xxx src / xxx.cpp) behind

add_dependencies(xxx ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

Otherwise, still may not generate my_msg.h header file

how to use?

1, include the header file

#include<package_name/my_msg.h>

2, the definition of variables

package_name::my_msg msg
 

Guess you like

Origin www.cnblogs.com/long5683/p/11450472.html