Files
dock_planner/CMakeLists.txt
duongtd 07e2fd3b38 feat: per-marker dock_face_offset and pivot margin for dock_anchor mating_edge
The charger goal is the docked base_link pose, and the real charger face lies 0.40 m behind
it (detector offset_x). mating_edge measured the pivot sweep from a face assumed at
mating_extent (0.325 m) behind the goal, and still forced a terminal of at least
rear_extent. So the robot rotated with its centre about 0.725 m from the charger face.

Two optional keys, valid only with dock_anchor: mating_edge (rejected with center or face):
- dock_face_offset [m]: distance from the goal back to the real dock face. Default
  mating_extent.
- dock_pivot_safety_margin [m]: overrides maneuver/pivot_safety_margin for this marker.
A YAML null reads as unset, so move_base2 can clear a previous marker's value.

For mating_edge, the terminal floor becomes
max(mating_extent - face_offset, 0) + padding (floored at path_point_spacing), and the pivot
vertex becomes max(straight_distance, circumscribed - face_offset + margin). The costmap
rotation radius uses the same margin. center and face are unchanged.

KIT charger (face offset 0.40, margin 0.10, straight_length 0.2): vertex 0.2 m, robot centre
0.60 m from the charger face. Tests cover the three robot starts, the defaults, validation
and null handling. The test target now links yaml-cpp itself.
2026-10-29 16:54:16 +07:00

194 lines
5.9 KiB
CMake

cmake_minimum_required(VERSION 3.0.2)
project(dock_planner VERSION 1.0.0 LANGUAGES CXX)
if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL)
set(BUILDING_WITH_CATKIN TRUE)
message(STATUS "Building dock_planner with Catkin")
else()
set(BUILDING_WITH_CATKIN FALSE)
message(STATUS "Building dock_planner with Standalone CMake")
endif()
# C++ Standard - must be set before find_package
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Find dependencies. Boost is header-only here (boost/dll/alias.hpp exports the
# plugin symbol); no Boost component library is linked.
find_package(Boost REQUIRED)
find_package(yaml-cpp REQUIRED)
# librobot_time.so calls pthread_create but does not export the dependency;
# link it explicitly instead of inheriting it from an unrelated Boost component.
find_package(Threads REQUIRED)
if(NOT BUILDING_WITH_CATKIN)
# Enable Position Independent Code
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Cấu hình RPATH để tránh cycle trong runtime search path
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_BUILD_RPATH "${CMAKE_BINARY_DIR}")
# Library targets provided by the standalone parent build.
set(STANDALONE_DEP_TARGETS
robot_geometry_msgs
robot_time
data_convert
robot_costmap_2d
robot_nav_core
robot_cpp
)
else()
# ========================================================
# Catkin specific configuration
# ========================================================
find_package(catkin REQUIRED COMPONENTS
robot_geometry_msgs
robot_time
data_convert
robot_costmap_2d
robot_nav_core
robot_cpp
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS robot_geometry_msgs robot_time data_convert robot_costmap_2d robot_nav_core robot_cpp
DEPENDS Boost
)
endif()
# ========================================================
# Libraries
# ========================================================
add_library(${PROJECT_NAME} SHARED
src/dock_planner.cpp
src/dock_planner_config.cpp
src/dock_calc.cpp
)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${Boost_INCLUDE_DIRS}
)
if(BUILDING_WITH_CATKIN)
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_include_directories(${PROJECT_NAME} PUBLIC ${catkin_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}
PUBLIC ${catkin_LIBRARIES} Threads::Threads
PRIVATE yaml-cpp
)
else()
target_link_libraries(${PROJECT_NAME}
PUBLIC
${STANDALONE_DEP_TARGETS}
Threads::Threads
PRIVATE
yaml-cpp
)
set_target_properties(${PROJECT_NAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
BUILD_RPATH "${CMAKE_BINARY_DIR}"
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
)
endif()
if(COMMAND target_link_options)
target_link_options(${PROJECT_NAME} PRIVATE -Wl,--no-undefined)
endif()
# Focused contract tests use a tiny self-contained runner so both catkin and
# standalone builds exercise the same code without adding a test dependency.
#
# Tests are a development-machine concern: a catkin workspace is where they run,
# while the standalone CMake build is the robot deployment path and must not
# produce test executables. Force with -DBUILD_DOCK_PLANNER_TESTS=ON to build
# them from a standalone build.
#
# include(CTest) used to sit here for the standalone branch. It is deliberately
# gone: it defines BUILD_TESTING=ON for the WHOLE CMake tree, which switched the
# tests of every other package in the aggregate build back on.
option(BUILD_DOCK_PLANNER_TESTS "Build the dock_planner contract tests"
${BUILDING_WITH_CATKIN})
if(BUILD_DOCK_PLANNER_TESTS AND
(NOT BUILDING_WITH_CATKIN OR CATKIN_ENABLE_TESTING))
if(NOT BUILDING_WITH_CATKIN)
enable_testing()
endif()
add_executable(${PROJECT_NAME}_test test/dock_planner_test.cpp)
# The test builds YAML nodes for the config loader directly; the library links
# yaml-cpp PRIVATE and does not pass it on, so the test links it itself.
target_link_libraries(${PROJECT_NAME}_test PRIVATE ${PROJECT_NAME} yaml-cpp)
if(BUILDING_WITH_CATKIN)
add_dependencies(${PROJECT_NAME}_test ${catkin_EXPORTED_TARGETS})
endif()
add_test(NAME ${PROJECT_NAME}_test COMMAND ${PROJECT_NAME}_test)
endif()
# ========================================================
# Install
# ========================================================
if(BUILDING_WITH_CATKIN)
## Mark libraries for installation
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
## Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
else()
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# Export targets
install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}-targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/${PROJECT_NAME}
)
## Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION include
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
# Print configuration info
message(STATUS "=================================")
message(STATUS "Project: ${PROJECT_NAME}")
message(STATUS "Version: ${PROJECT_VERSION}")
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "Dependencies: robot_geometry_msgs, robot_time, data_convert, robot_costmap_2d, robot_nav_core, robot_cpp, Boost (headers), yaml-cpp")
message(STATUS "=================================")
endif()