有多少人工,就有多少智能

Franka Robot cmake demo

cmake_minimum_required(VERSION 3.4) # 指定 CMake 的最低版本要求为 3.4

project(libfranka-examples CXX) # 定义项目名称为 libfranka-examples,并指定语言为 C++

list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR}/../cmake) # 将父目录的 `cmake` 子目录添加到模块路径中

set(CMAKE_CXX_STANDARD 17) # 设置 C++ 标准为 C++17
set(CMAKE_CXX_STANDARD_REQUIRED ON) # 将 C++17 设为必需

if(NOT FRANKA_IS_FOUND) # 检查是否已找到 Franka 库
    find_package(Franka REQUIRED) # 如果没有找到,则尝试查找 Franka 库
endif()
find_package(Eigen3 REQUIRED) # 找到 Eigen3 库,这个库是示例代码所需的
find_package(Poco REQUIRED COMPONENTS Foundation) # 找到 Poco 库,这个库也是示例代码所需的

set(THREADS_PREFER_PTHREAD_FLAG ON) # 指定 Threads 库应该优先使用 pthread 标志
find_package(Threads REQUIRED) # 找到 Threads 库,这个库是一些示例代码所需的

add_library(examples_common STATIC # 创建一个静态库称为 `examples_common`
  examples_common.cpp
)

target_link_libraries(examples_common PRIVATE Franka::Franka Eigen3::Eigen3) # 将 `examples_common` 库链接到 Franka 和 Eigen3 库
target_include_directories(examples_common PUBLIC # 指定 `examples_common` 库的包含目录
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
)
set(EXAMPLES # 定义一个示例程序列表
  cartesian_impedance_control
  communication_test
  echo_robot_state
  force_control
  generate_cartesian_pose_motion
  generate_cartesian_pose_motion_external_control_loop
  generate_cartesian_velocity_motion
  generate_cartesian_velocity_motion_external_control_loop
  generate_consecutive_motions
  generate_elbow_motion
  generate_joint_position_motion
  generate_joint_position_motion_external_control_loop
  generate_joint_velocity_motion
  generate_joint_velocity_motion_external_control_loop
  grasp_object
  joint_impedance_control
  joint_point_to_point_motion
  motion_with_control
  motion_with_control_external_control_loop
  print_joint_poses
  vacuum_object
)

foreach(example ${EXAMPLES}) # 遍历示例程序列表
  add_executable(${example} ${example}.cpp) # 为每个示例程序创建一个可执行文件
  target_include_directories(${example} PUBLIC # 指定每个示例程序的包含目录
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>
  )
  target_link_libraries(${example} Franka::Franka examples_common Eigen3::Eigen3) # 将每个示例程序链接到 Franka、`examples_common` 和 Eigen3 库
endforeach()

target_link_libraries(joint_impedance_control Threads::Threads) # 将 `joint_impedance_control` 示例程序链接到 Threads 库
target_link_libraries(motion_with_control Poco::Foundation) # 将 `motion_with_control` 示例程序链接到 Poco 库
target_link_libraries(motion_with_control_external_control_loop Poco::Foundation) # 将 `motion_with_control_external_control_loop` 示例程序链接到 Poco 库

include(GNUInstallDirs) # 包含 GNUInstallDirs 模块,它提供了标准的安装目录
install(TARGETS ${EXAMPLES} # 配置已构建的示例程序的安装
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

 

posted @ 2024-07-10 11:46  lvdongjie-avatarx  阅读(4)  评论(0编辑  收藏  举报