- Anytime dung nghia (pha 0): replan() qua ReplanParams thay vi replan(double) - nghiem dau o initial_epsilon, ha dan eps_step toi final_epsilon trong repair_time; return_first_solution de bench. eps=1.0 (A* thuan) tren map rong gan chac chan het gio. - Route graph corridor: nhan robot_sensor_ports::SensorConsumer, doc RouteGraph tu kho (host bien dich Voronoi tu map, day qua addRouteGraph), doi chieu map_hash voi static layer song. Goal >= min_range_m + co graph -> gan start/goal (BFS), Dijkstra ra tuyen, dong dau mask quanh tuyen; o NGOAI mask nhan cost inscribed (hard) hoac bi phat (soft) - search + heuristic 2D chi no trong dai (~3% map thay 100% tren sehc). Khong graph/lech/gan that bai = chay full nhu cu, log [debug/corridor] noi ly do; "route graph REJECTED" la LOI khong tat duoc. Nguong nghen -> noi rong (widen_factor, toi da max_widen) -> bo dai chay full voi thoi gian con lai. - Path smoother (distance_map.h/.cpp, path_smoother.h/.cpp): keo day doan lattice di thang duoc tren costmap SONG (distance-transform giu khoang cach voi LETHAL, khong chi nhin cost), bo goc bang cung ban kinh co dinh khop bo mprim - giu nguyen doan lui (cusp). Do tren sehc: path lattice dai hon toi uu 2D 12%, 11 lan doi chieu re; smoother giam duoc phan lon. - Log "metrics: ... detour= turn_deg= arcs= wiggles= plan_ms= corridor= corridor_ms= smooth= raw_m= smooth_ms= anchors= fillets=" moi lan plan thanh cong - so dai on/off, hard/soft, eps qua script tools/eval_plan_bag.py. - Test moi: test/path_smoother_test.cpp (path_smoother la hinh hoc thuan, khong SBPL/costmap, chay duoc moi noi co gtest). CMakeLists them target catkin_add_gtest + nhanh standalone. - Phu thuoc build moi: robot_sensor_ports, route_graph (repo rieng, da co remote). - YAML: schema initial_epsilon/final_epsilon/eps_step/repair_time/return_first_solution, khoi voronoi_corridor (12 khoa) va smooth_path (7 khoa) trong cfg/sbpl_global_params.yaml (dong bo tu pnkx_nav_core c52cbe5 / move_base2 f4f9965).
251 lines
9.1 KiB
CMake
251 lines
9.1 KiB
CMake
cmake_minimum_required(VERSION 3.0.2)
|
|
project(sbpl_lattice_planner VERSION 1.0.0 LANGUAGES CXX)
|
|
|
|
if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL)
|
|
set(BUILDING_WITH_CATKIN TRUE)
|
|
message(STATUS "Building sbpl_lattice_planner with Catkin")
|
|
|
|
else()
|
|
set(BUILDING_WITH_CATKIN FALSE)
|
|
message(STATUS "Building sbpl_lattice_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
|
|
#
|
|
# Hai bản sbpl có thể cùng tồn tại trên máy: ros-noetic-sbpl (apt, 2020, /opt/ros/noetic) và bản
|
|
# vendored Test/sbpl (cài /usr/local, hoặc in-tree src/Libraries/sbpl trên robot). Chỉ bản vendored
|
|
# từ 2026-09-11 có abort flag (cancel cắt được lượt search). SBPL_DIR trong cache quyết định bản
|
|
# nào — ưu tiên /usr/local nếu chưa ai ép; sai bản thì cảnh báo to ở configure, và
|
|
# sbpl_lattice_planner còn tự probe symbol lúc chạy trước khi đụng cờ (mismatch header/.so là
|
|
# ghi đè bộ nhớ).
|
|
if(NOT DEFINED SBPL_DIR AND EXISTS "/usr/local/share/sbpl/sbpl-config.cmake")
|
|
set(SBPL_DIR "/usr/local/share/sbpl" CACHE PATH "sbpl config dir (vendored build preferred)")
|
|
endif()
|
|
find_package(SBPL REQUIRED)
|
|
message(STATUS "sbpl_lattice_planner: SBPL from '${SBPL_DIR}' (include: ${SBPL_INCLUDE_DIRS})")
|
|
set(_sbpl_planner_h "")
|
|
foreach(_dir ${SBPL_INCLUDE_DIRS})
|
|
if(EXISTS "${_dir}/sbpl/planners/planner.h")
|
|
set(_sbpl_planner_h "${_dir}/sbpl/planners/planner.h")
|
|
endif()
|
|
endforeach()
|
|
if(_sbpl_planner_h)
|
|
file(READ "${_sbpl_planner_h}" _sbpl_planner_h_text)
|
|
string(FIND "${_sbpl_planner_h_text}" "SBPL_HAS_ABORT_FLAG" _sbpl_abort_pos)
|
|
if(_sbpl_abort_pos EQUAL -1)
|
|
message(WARNING
|
|
"sbpl_lattice_planner: '${_sbpl_planner_h}' has no SBPL_HAS_ABORT_FLAG — this sbpl cannot be "
|
|
"preempted; cancel/pause will wait for allocated_time. Build+install Test/sbpl and point "
|
|
"-DSBPL_DIR=/usr/local/share/sbpl (or drop ros-noetic-sbpl) to get preempt.")
|
|
else()
|
|
message(STATUS "sbpl_lattice_planner: sbpl abort flag available (preempt on)")
|
|
endif()
|
|
endif()
|
|
find_package(Eigen3 REQUIRED)
|
|
find_package(Boost REQUIRED COMPONENTS system thread filesystem)
|
|
|
|
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_visualization_msgs
|
|
robot_nav_msgs
|
|
robot_std_msgs
|
|
robot_geometry_msgs
|
|
tf3
|
|
robot_tf3_geometry_msgs
|
|
robot_time
|
|
data_convert
|
|
robot_costmap_2d
|
|
robot_nav_core
|
|
robot_protocol_msgs
|
|
robot_cpp
|
|
robot_sensor_ports
|
|
route_graph
|
|
)
|
|
|
|
else()
|
|
|
|
# ========================================================
|
|
# Catkin specific configuration
|
|
# ========================================================
|
|
find_package(catkin REQUIRED COMPONENTS
|
|
robot_visualization_msgs
|
|
robot_nav_msgs
|
|
robot_std_msgs
|
|
robot_geometry_msgs
|
|
robot_tf3_geometry_msgs
|
|
robot_time
|
|
data_convert
|
|
robot_costmap_2d
|
|
robot_nav_core
|
|
robot_protocol_msgs
|
|
robot_cpp
|
|
robot_sensor_ports
|
|
route_graph
|
|
)
|
|
|
|
find_library(TF3_LIBRARY NAMES tf3)
|
|
|
|
catkin_package(
|
|
INCLUDE_DIRS include
|
|
LIBRARIES ${PROJECT_NAME}
|
|
CATKIN_DEPENDS robot_visualization_msgs robot_nav_msgs robot_std_msgs robot_geometry_msgs robot_tf3_geometry_msgs robot_time data_convert robot_costmap_2d robot_nav_core robot_protocol_msgs robot_cpp robot_sensor_ports route_graph
|
|
DEPENDS Eigen3 Boost SBPL
|
|
)
|
|
|
|
include_directories(
|
|
include
|
|
${catkin_INCLUDE_DIRS}
|
|
${EIGEN3_INCLUDE_DIRS}
|
|
${Boost_INCLUDE_DIRS}
|
|
)
|
|
endif()
|
|
|
|
# ========================================================
|
|
# Libraries
|
|
# ========================================================
|
|
add_library(${PROJECT_NAME} SHARED
|
|
src/sbpl_lattice_planner.cpp
|
|
src/path_smoother.cpp
|
|
src/distance_map.cpp
|
|
)
|
|
|
|
# Header sbpl phải là bản mà SBPL_DIR chọn, ĐỨNG TRƯỚC mọi include của catkin: /opt/ros/noetic/include
|
|
# (ros-noetic-sbpl, apt) cũng có sbpl/planners/planner.h và nếu đứng trước sẽ thắng — khi đó plugin
|
|
# build với header CŨ (không abort flag, preempt bị compile out) dù link libsbpl mới. Đã xảy ra
|
|
# 2026-09-11 trên máy dev: log "built against an sbpl without abort flag" trong khi cmake báo
|
|
# "preempt on". Lưu ý runtime: soname `libsbpl.so` trùng nhau, LD_LIBRARY_PATH của ROS đặt
|
|
# /opt/ros/noetic/lib trước /usr/local/lib nên bản apt vẫn được nạp — phải gỡ ros-noetic-sbpl
|
|
# (và ros-noetic-sbpl-lattice-planner) trên máy build/chạy, hoặc đổi soname bản vendored.
|
|
target_include_directories(${PROJECT_NAME} BEFORE PRIVATE ${SBPL_INCLUDE_DIRS})
|
|
|
|
if(BUILDING_WITH_CATKIN)
|
|
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
|
|
|
|
target_include_directories(${PROJECT_NAME}
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE:include>
|
|
)
|
|
|
|
target_link_libraries(${PROJECT_NAME}
|
|
PUBLIC ${catkin_LIBRARIES} ${SBPL_LIBRARIES}
|
|
PRIVATE Eigen3::Eigen Boost::system Boost::thread Boost::filesystem
|
|
)
|
|
|
|
else()
|
|
|
|
target_include_directories(${PROJECT_NAME}
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE:include>
|
|
)
|
|
|
|
target_link_libraries(${PROJECT_NAME}
|
|
PUBLIC
|
|
${PACKAGES_DIR}
|
|
PRIVATE
|
|
Eigen3::Eigen Boost::system Boost::thread Boost::filesystem
|
|
)
|
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
BUILD_RPATH "${CMAKE_BINARY_DIR}"
|
|
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
|
|
)
|
|
|
|
endif()
|
|
|
|
# ========================================================
|
|
# Tests — path_smoother is pure geometry (no SBPL/costmap), runs anywhere gtest exists.
|
|
# catkin_add_gtest KHÔNG link gtest_main nên test tự có main(). Chạy tay:
|
|
# ./devel/lib/sbpl_lattice_planner/path_smoother_test (catkin)
|
|
# ========================================================
|
|
if(BUILDING_WITH_CATKIN)
|
|
if(CATKIN_ENABLE_TESTING)
|
|
catkin_add_gtest(path_smoother_test test/path_smoother_test.cpp src/path_smoother.cpp src/distance_map.cpp)
|
|
if(TARGET path_smoother_test)
|
|
# catkin_add_gtest đánh dấu EXCLUDE_FROM_ALL (chỉ ra khi chạy target `tests`); bỏ dấu để
|
|
# `catkin_make --pkg sbpl_lattice_planner` ra luôn ./devel/lib/sbpl_lattice_planner/path_smoother_test.
|
|
set_target_properties(path_smoother_test PROPERTIES EXCLUDE_FROM_ALL FALSE)
|
|
target_compile_options(path_smoother_test PRIVATE -Wall -Wextra)
|
|
target_include_directories(path_smoother_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
target_link_libraries(path_smoother_test pthread)
|
|
endif()
|
|
endif()
|
|
else()
|
|
option(BUILD_TESTS "Build sbpl_lattice_planner unit tests" OFF)
|
|
if(BUILD_TESTS)
|
|
find_package(GTest REQUIRED)
|
|
add_executable(path_smoother_test test/path_smoother_test.cpp src/path_smoother.cpp src/distance_map.cpp)
|
|
target_include_directories(path_smoother_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
target_link_libraries(path_smoother_test PRIVATE GTest::GTest pthread)
|
|
enable_testing()
|
|
add_test(NAME path_smoother_test COMMAND path_smoother_test)
|
|
endif()
|
|
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 ${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_visualization_msgs, robot_nav_msgs, robot_std_msgs, robot_geometry_msgs, tf3, robot_tf3_geometry_msgs, robot_time, data_convert, robot_costmap_2d, robot_nav_core, robot_protocol_msgs, robot_cpp, Eigen3, Boost")
|
|
message(STATUS "=================================")
|
|
endif()
|