ros2+rviz2示例代码--cmakelists.txt与package.xml备份

html 复制代码
cmake_minimum_required(VERSION 3.8)
project(gazebo_pkg)
set(CMAKE_PREFIX_PATH /usr;/opt/ros/humble)
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(robot_state_publisher REQUIRED)
find_package(urdf_tutorial REQUIRED)
find_package(xacro REQUIRED)
find_package(rviz2 REQUIRED)
install(
  DIRECTORY  urdf launch etc
  DESTINATION share/${PROJECT_NAME}
)
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()

ament_package()
html 复制代码
<?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>gazebo_pkg</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="actorsun@todo.todo">actorsun</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>robot_state_publisher</depend>
  <depend>urdf_tutorial</depend>
  <depend>xacro</depend>
  <depend>rviz2</depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

其中修改为如下也可以

html 复制代码
<?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>gazebo_pkg</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="actorsun@todo.todo">actorsun</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>robot_state_publisher</depend>
  <exec_depend>joint_state_publisher</exec_depend>
  <depend>xacro</depend>
  <depend>rviz2</depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

find_package 命令用法举例

  • find_package(OpenCV)

    • 查找名为 OpenCV 的包,找不到不报错,事后可以通过 ${OpenCV_FOUND} 查询是否找到。
  • find_package(OpenCV QUIET)

    • 查找名为 OpenCV 的包,找不到不报错,也不打印任何信息。
  • find_package(OpenCV REQUIRED) # 最常见用法

    • 查找名为 OpenCV 的包,找不到就报错(并终止 cmake 进程,不再继续往下执行)。
  • find_package(OpenCV REQUIRED COMPONENTS core videoio)

    • 查找名为 OpenCV 的包,找不到就报错,且必须具有 OpenCV::coreOpenCV::videoio 这两个组件,如果没有这两个组件也会报错。
  • find_package(OpenCV REQUIRED OPTIONAL_COMPONENTS core videoio)

    • 查找名为 OpenCV 的包,找不到就报错,可具有 OpenCV::coreOpenCV::videoio 这两个组件,没有这两组件不会报错,通过 ${OpenCV_core_FOUND} 查询是否找到 core 组件。

find_package 说是找"包(package)",到底是在找什么?

相关推荐
悠哉悠哉愿意2 天前
【ROS2学习笔记】URDF 机器人建模
笔记·学习·机器人·ros2
悠哉悠哉愿意2 天前
【ROS2学习笔记】 TF 坐标系
笔记·学习·ros2
悠哉悠哉愿意3 天前
【ROS2学习笔记】RViz 三维可视化
笔记·学习·机器人·ros2
悠哉悠哉愿意3 天前
【ROS2学习笔记】分布式通信
笔记·学习·ros2
悠哉悠哉愿意4 天前
【ROS2学习笔记】rqt 模块化可视化工具
笔记·学习·机器人·ros2
天若有情6734 天前
Spring配置文件XML验证错误全面解决指南:从cvc-elt.1.a到找不到‘beans‘元素声明
xml·java·spring
悠哉悠哉愿意4 天前
【ROS2学习笔记】Gazebo 仿真与 XACRO 模型
笔记·学习·机器人·ros2
悠哉悠哉愿意4 天前
【ROS2学习笔记】节点篇:ROS 2编程基础
笔记·学习·ros2
悠哉悠哉愿意4 天前
【ROS2学习笔记】话题通信篇:话题通信项目实践——系统状态监测与可视化工具
笔记·学习·ros2
悠哉悠哉愿意5 天前
【ROS2学习笔记】话题通信篇:python话题订阅与发布
笔记·学习·ros2