ROS2 同一个pkg里定义自定义action、msg报错

参考

主要就是在定义完可执行文件后加入

cpp 复制代码
rosidl_target_interfaces(fibonacci_action_server
  ${PROJECT_NAME} "rosidl_typesupport_cpp")
末尾加
 ament_export_dependencies(rosidl_default_runtime) 
 同时别忘记 packagexml定义 rosidl_default_runtime

完整Cmakelists,txt

cpp 复制代码
cmake_minimum_required(VERSION 3.8)
project(mypkg)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(example_interfaces REQUIRED)


find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "action/Fibonacci.action"
)



if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

add_executable(fibonacci_action_server src/fibonacci_action_server.cpp)
ament_target_dependencies(fibonacci_action_server 
rclcpp rclcpp_action example_interfaces rosidl_default_runtime)
rosidl_target_interfaces(fibonacci_action_server
  ${PROJECT_NAME} "rosidl_typesupport_cpp")



add_executable(fibonacci_action_client src/fibonacci_action_client.cpp)
ament_target_dependencies(fibonacci_action_client 
rclcpp 
rclcpp_action 
example_interfaces 
rosidl_default_runtime)

rosidl_target_interfaces(fibonacci_action_client
  ${PROJECT_NAME} "rosidl_typesupport_cpp")

install(TARGETS
  fibonacci_action_server
  fibonacci_action_client
  DESTINATION lib/${PROJECT_NAME})
  
 ament_export_dependencies(rosidl_default_runtime) 
ament_package()
cpp 复制代码
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>mypkg</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="lzq@todo.todo">lzq</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>rclcpp</depend>
  <depend>rclcpp_action</depend>
  <depend>example_interfaces</depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>
  
  <build_depend>rosidl_default_generators</build_depend>
  <exec_depend>rosidl_default_runtime</exec_depend>
  <member_of_group>rosidl_interface_packages</member_of_group>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>
相关推荐
无人装备硬件开发爱好者1 天前
ROS2:无人机从 “能飞” 到 “会思考” 的全栈技术引擎 —— 深度拆解与落地指南(上)
无人机·ros2·无人机飞控
MIXLLRED2 天前
Ubuntu 22.04/ROS2 Humble下使用Intel RealSense D435i相机
ubuntu·d435i·ros2·深度相机
花花少年4 天前
ROS2常用指令(附 ROS1 & ROS2 对照表)
ros2
习惯就好zz5 天前
在 Ubuntu 18.04 旧系统上部署新版 GitHub Actions Runner 的终极方案
linux·ubuntu·github·cicd·action
阿豪只会阿巴5 天前
【多喝热水系列】从零开始的ROS2之旅——Day5
c++·笔记·python·ubuntu·ros2
维度攻城狮8 天前
ros2参数通信案例
开发语言·windows·python·ros2·参数通信
zylyehuo9 天前
Ubuntu22.04(ROS2 humble)小车仿真环境搭建
ros2·导航
阿豪只会阿巴10 天前
【多喝热水系列】从零开始的ROS2之旅——Day3
linux·笔记·ubuntu·ros2
阿豪只会阿巴10 天前
【多喝热水系列】从零开始的ROS2之旅——Day4
c++·笔记·python·ros2
撬动未来的支点10 天前
【ROS2速通】资料,笔记攻略
ros2