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="[email protected]">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>
相关推荐
Mr.Winter`12 小时前
无人船 | 图解基于PID控制的路径跟踪算法(以全驱动无人艇WAMV为例)
人工智能·机器人·ros·ros2·路径规划·无人船
hillstream313 天前
ROS2学习笔记1-起步的程序
ros·ros2
Mr.Winter`13 天前
运动规划实战案例 | 基于四叉树分解的路径规划(附ROS C++/Python仿真)
人工智能·机器人·自动驾驶·ros·计算机图形学·ros2·路径规划
维度攻城狮20 天前
实现在Unity3D中仿真汽车,而且还能使用ros2控制
python·unity·docker·汽车·ros2·rviz2
伊织code23 天前
GPT Actions
gpt·openai·api·action
Mr.Winter`1 个月前
轨迹优化 | 基于梯度下降的路径规划算法(附ROS C++/Python仿真)
c++·人工智能·算法·机器人·自动驾驶·ros·ros2
猫头鹰数据分析1 个月前
机器人ROS学习:Ubuntu22.04安装ROS2和Moveit2实现运动规划
ubuntu·ros2·moveit·机器人运动
爱凤的小光3 个月前
图漾相机-ROS2-SDK-Ubuntu版本编译(新版本)
ubuntu·ros2
Mr.Winter`3 个月前
轨迹优化 | 基于ESDF的非线性最小二乘法路径平滑(附ROS C++仿真)
人工智能·科技·机器人·自动驾驶·ros·最小二乘法·ros2