Files
costmap_2d/CMakeLists.txt
duongtd a5be6f9a1f feat: body_clearance — mot nguon hinh hoc than duy nhat cho ca stack
Do tren sim thang 8-9/2026: bon thanh phan cung tra loi "than co cham khong",
moi cai tu dung hinh hoc rieng —
  local planner (PRIEST): 3 circle r=0.52 (+0.08 +0.05) -> nua rong 0.65 -> khe 1.30 m
  giam sat tuyen         : polygon costmap + 0.05        -> nua rong 0.53 -> khe 1.06 m
  global planner (SBPL)  : polygon vs LETHAL                              -> khe ~1.05 m
  head slowdown          : hop 0.583 x 0.48, nguong 253                   -> khac han
He qua khong tranh duoc: global planner ve duong qua khe 1.1 m, local planner
khong bam noi, residual treo 3.5-4.5, tang an toan dung robot, replan tra ve
CUNG mot duong, lap (do duoc 6 vong o mot goc tru, 250 vong o mot ca khac).
Chinh so o tung cho chi keo hai cot lai gan nhau roi lech o cho thu ba.

Them robot_costmap_2d/body_clearance: khong state, khong quyet dinh gi, chi do.
  BodyModel          footprint that (getRobotFootprint) + MOT padding + nguong LETHAL
  clearance()        [m] ho tu than da dem toi o vat can gan nhat; am = da lan vao
  sweep()            cung (v, omega) dan than toi dau — tra walk/t_contact/turn
  circleApproximation() suy ban kinh + spacing circle TU CHINH BodyModel do, cho
                     optimizer kha vi (ADMM/MPPI) can hinh tron
  obstaclePoints()   diem vat can cho solver — CUNG tap o ma sweep se do

Bat bien trung tam: thu solver nap vao dung bang thu tang an toan se do, va khe
hep nhat chuoi circle lot bang khe hep nhat sweep cho qua (co test khoa lai).

Ba bai hoc do duoc, deu la test:
- Chu vi kin thay vi vai diem roi: tru manh 1 o o goc truoc lot giua duong quet
  mui (ngang 0) va duong quet hong (ngang 0.53) — robot om ca tru moi dung.
- Buoc doc cung <= mot o: tuong mong 1 o lot giua hai mau la dam xuyen.
- Bo qua o DA nam trong than: neu khong, robot dung lan vanh an toan bi cam MOI
  chuyen dong ke ca chuyen dong thoat, va base chi tien thi ket vinh vien.
- t_contact + turn ben canh walk: cung 0.15 m khi di thang 0.36 m/s la "cham sau
  0.4 s"; cung 0.15 m khi bo 0.04 m/s voi omega 0.5 la "quay 107 do, cham sau
  3.7 s" — khong he sap cham.

27 test moi. Chi THEM file, khong sua costmap_2d.h/footprint.h (dung chung cho
moi layer).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011aaTZjPSPV9nfcrRzabEmA
2026-09-04 21:36:37 +07:00

339 lines
9.8 KiB
CMake

cmake_minimum_required(VERSION 3.0.2)
project(robot_costmap_2d VERSION 1.0.0 LANGUAGES CXX)
if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL)
set(BUILDING_WITH_CATKIN TRUE)
message(STATUS "Building robot_costmap_2d with Catkin")
else()
set(BUILDING_WITH_CATKIN FALSE)
message(STATUS "Building robot_costmap_2d 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
find_package(Eigen3 REQUIRED)
find_package(Boost REQUIRED COMPONENTS system thread filesystem)
# GTest is only needed by the test executables, which the robot deployment build
# does not produce. QUIET, not REQUIRED: a robot without GTest installed must
# still configure. The test block below requires it where it is actually used.
find_package(GTest QUIET)
find_package(yaml-cpp 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}")
set(PACKAGES_DIR
robot_std_msgs
robot_sensor_msgs
geometry_msgs
robot_nav_msgs
robot_map_msgs
robot_laser_geometry
robot_visualization_msgs
robot_voxel_grid
tf3
robot_tf3_geometry_msgs
robot_tf3_sensor_msgs
data_convert
robot_xmlrpcpp
robot_cpp
robot_time
)
find_library(TF3_LIBRARY NAMES tf3 PATHS /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu)
else()
# ========================================================
# Catkin specific configuration
# ========================================================
find_package(catkin REQUIRED COMPONENTS
robot_std_msgs
robot_sensor_msgs
geometry_msgs
robot_nav_msgs
robot_map_msgs
robot_laser_geometry
robot_visualization_msgs
robot_voxel_grid
robot_tf3_geometry_msgs
robot_tf3_sensor_msgs
data_convert
robot_xmlrpcpp
robot_cpp
robot_time
)
find_library(TF3_LIBRARY NAMES tf3)
catkin_package(
INCLUDE_DIRS include
LIBRARIES robot_costmap_2d plugins
CATKIN_DEPENDS robot_std_msgs robot_sensor_msgs geometry_msgs robot_nav_msgs robot_map_msgs robot_laser_geometry robot_visualization_msgs robot_voxel_grid robot_tf3_geometry_msgs robot_tf3_sensor_msgs data_convert robot_xmlrpcpp robot_cpp robot_time
DEPENDS Boost
)
include_directories(
include
${catkin_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${GTEST_INCLUDE_DIRS}
${TF3_INCLUDE_DIR}
)
endif()
# Define macro để dùng trong code
add_definitions(-DROBOT_COSTMAP_2D_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
# Eigen definitions
add_definitions(${EIGEN3_DEFINITIONS})
# ========================================================
# Core library: robot_costmap_2d
# ========================================================
add_library(robot_costmap_2d SHARED
src/costmap_2d_robot.cpp
src/array_parser.cpp
src/costmap_2d.cpp
src/observation_buffer.cpp
src/layer.cpp
src/layered_costmap.cpp
src/costmap_math.cpp
src/footprint.cpp
src/costmap_layer.cpp
src/body_clearance.cpp
)
if(BUILDING_WITH_CATKIN)
add_dependencies(robot_costmap_2d ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_include_directories(robot_costmap_2d
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${EIGEN3_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${TF3_INCLUDE_DIR}
)
target_link_libraries(robot_costmap_2d
PUBLIC ${catkin_LIBRARIES}
PRIVATE Boost::boost Boost::system Boost::thread Boost::filesystem
PRIVATE yaml-cpp
PRIVATE dl
PRIVATE ${TF3_LIBRARY}
)
else()
target_include_directories(robot_costmap_2d
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${EIGEN3_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${TF3_INCLUDE_DIR}
)
target_link_libraries(robot_costmap_2d
PUBLIC
${PACKAGES_DIR}
PRIVATE
Boost::boost Boost::system Boost::thread Boost::filesystem
yaml-cpp
dl
${TF3_LIBRARY}
)
set_target_properties(robot_costmap_2d PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
BUILD_RPATH "${CMAKE_BINARY_DIR}"
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
)
endif()
# ========================================================
# Plugin library: plugins
# ========================================================
add_library(plugins SHARED
plugins/static_layer.cpp
plugins/obstacle_layer.cpp
plugins/inflation_layer.cpp
plugins/voxel_layer.cpp
plugins/critical_layer.cpp
plugins/directional_layer.cpp
plugins/preferred_layer.cpp
plugins/unpreferred_layer.cpp
)
if(BUILDING_WITH_CATKIN)
add_dependencies(plugins ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_include_directories(plugins
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(plugins
PUBLIC robot_costmap_2d
PRIVATE ${catkin_LIBRARIES}
PRIVATE Boost::boost Boost::system Boost::thread Boost::filesystem
PRIVATE yaml-cpp
PRIVATE ${TF3_LIBRARY}
)
else()
target_include_directories(plugins
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(plugins
PUBLIC robot_costmap_2d
PRIVATE Boost::boost Boost::system Boost::thread Boost::filesystem
PRIVATE yaml-cpp
PRIVATE robot_time
PRIVATE robot_cpp
PRIVATE ${TF3_LIBRARY}
)
set_target_properties(plugins PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
BUILD_RPATH "${CMAKE_BINARY_DIR}"
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
)
endif()
# ========================================================
# Install
# ========================================================
if(BUILDING_WITH_CATKIN)
## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
install(TARGETS robot_costmap_2d plugins
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 robot_costmap_2d plugins
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 "Libraries: robot_costmap_2d, plugins")
message(STATUS "Dependencies: robot_std_msgs, robot_sensor_msgs, geometry_msgs, robot_nav_msgs, robot_map_msgs, robot_laser_geometry, robot_visualization_msgs, robot_voxel_grid, tf3, robot_tf3_geometry_msgs, robot_tf3_sensor_msgs, data_convert, robot_xmlrpcpp, robot_cpp, robot_time, Eigen3, Boost, yaml-cpp")
message(STATUS "=================================")
endif()
# ========================================================
# Test executables
# ========================================================
# Default follows the build mode, not a fixed value: a catkin workspace is a
# development machine and gets the tests, while the standalone CMake build is how
# the robot is deployed and must not need GTest installed at all. Force it on with
# -DBUILD_COSTMAP_TESTS=ON to run the tests from a standalone build.
option(BUILD_COSTMAP_TESTS "Build robot_costmap_2d test executables"
${BUILDING_WITH_CATKIN})
if(BUILD_COSTMAP_TESTS)
find_package(GTest REQUIRED)
find_package(Boost REQUIRED COMPONENTS system thread filesystem)
find_library(TF3_LIBRARY NAMES tf3 PATHS /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/body_clearance_test.cpp)
add_executable(test_body_clearance test/body_clearance_test.cpp)
target_link_libraries(test_body_clearance PRIVATE
robot_costmap_2d
GTest::GTest
GTest::Main
Boost::system Boost::thread
${TF3_LIBRARY}
)
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/array_parser_test.cpp)
add_executable(test_array_parser test/array_parser_test.cpp)
target_link_libraries(test_array_parser PRIVATE
robot_costmap_2d
GTest::GTest
GTest::Main
Boost::system Boost::thread
${TF3_LIBRARY}
)
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/coordinates_test.cpp)
add_executable(test_costmap test/coordinates_test.cpp)
target_link_libraries(test_costmap PRIVATE
plugins
robot_costmap_2d
GTest::GTest
GTest::Main
Boost::system Boost::thread
${TF3_LIBRARY}
)
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/static_layer_test.cpp)
add_executable(test_plugin test/static_layer_test.cpp)
target_link_libraries(test_plugin PRIVATE
robot_costmap_2d
Boost::boost Boost::filesystem Boost::system
yaml-cpp
dl
Boost::system Boost::thread
robot_time
GTest::GTest
GTest::Main
${TF3_LIBRARY}
)
endif()
endif()