ros2自己创建message

0.前言

  • ros2查看message信息的命令是ros2 interface show yourmessage,查看服务也类似

1.流程

  • ros2 pkg create --build-type ament_cmake tutorial_interfaces
  • cd tutorial_interfaces
  • mkdir msg
  • cd msg
  • vim xx.msg,内容
geometry_msgs/Point point
  • 在CMakeLists.txt添加
find_package(geometry_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(xx
  "msg/xx.msg"
  DEPENDENCIES builtin_interfaces geometry_msgs
)
  • 在package.xml添加
geometry_msgs
rosidl_default_generators
  rosidl_default_runtime
  rosidl_interface_packages
  • cd …/…/…
  • colcon build --packages-select tutorial_interfaces
  • source install/setup.bash
  • ros2 interface show tutorial_interfaces/msg/xx

9.注意事项

  • 1.CMakeLists.txt中rosidl_generate_interfaces缺少DEPENDENCIES会报错:fatal error: geometry_msgs/msg/detail/point__struct.hpp: No such file or directory

你可能感兴趣的:(ROS2,ros2)