creat the publisher and use self-defined message

Step 1
creat the work space and catkin_init_workspace(in src folder) &catkin_make(in workspace folder)

Step 2
creat the package (in src),catkin_create_pkg

Step 3
copy and edit the code in the jan_7_duckietown
main change: the location of the message 'TW..' class

Step 4
add such code in the CMakeLists.txt in package

add_executable(car_publisher src/car_publisher.cpp)
target_link_libraries(car_publisher ${catkin_LIBRARIES})
add_dependencies(car_publisher ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

Step 5

add msg-'TW..'into car_controller'

Step 6

edit the CMakelists.txt in package

1.find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
  message_generation ##added
)

2.
 add_message_files(
   FILES
   Twist2DStamped.msg
#   Message2.msg
 )
3.
 generate_messages(
   DEPENDENCIES
   std_msgs
 )
4.
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES car_controller
  CATKIN_DEPENDS message_runtime
#  DEPENDS system_lib
)

Step 7  edit the package.xml

  message_runtime
  message_generation


你可能感兴趣的:(ROS学习,ros)