- Implements Preemptable::preempt() (atomic store), checked between the up
to 3 internal ARA* runs a single makePlan() can do (free_start_heading
retry, realign) — the runs now share one time budget instead of each
getting the full allocated_time, and a preempt between runs stops the
next one from starting (kMinReplanBudget floor so a preempt right at the
edge still gets a minimal attempt).
- Probes for the vendored sbpl's abort flag at runtime via
dlsym(RTLD_DEFAULT, "sbpl_abort_flag_abi_version") before touching
set_abort_flag() — logs an error if the header advertises the flag but
the loaded .so doesn't (header/lib version mismatch), a warning if built
against an sbpl without the flag at all (falls back to the old
run-to-allocated_time behaviour, no crash).
- primitive_filename now resolves relative to PNKX_NAV_CORE_CONFIG_DIR
instead of only working from one dev machine's absolute path.
- CMakeLists.txt: target_include_directories(... BEFORE PRIVATE
${SBPL_INCLUDE_DIRS}) so this package's own sbpl header wins over a
same-named one pulled in transitively (apt ros-noetic-sbpl in
/opt/ros/noetic/include has no abort flag and was winning silently);
configure-time check for SBPL_HAS_ABORT_FLAG in the resolved header with
a loud warning if missing.
Depends on Test/sbpl commit bd89924 (the abort flag itself) and
pnkx_nav_core commit 2b0993b (robot_nav_core::Preemptable header).
Measured on the dev machine (2026-09-12, apt ros-noetic-sbpl removed,
rebuilt): "preempted after N ms" with N in the tens of ms instead of
running to allocated_time (was up to 9 s). Full numbers:
Test/move_base2/docs/PLAN_LIFECYCLE_CANCEL_PAUSE_RESUME.md section 6.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
216 lines
7.4 KiB
CMake
216 lines
7.4 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
|
|
)
|
|
|
|
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
|
|
)
|
|
|
|
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
|
|
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
|
|
)
|
|
|
|
# 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()
|
|
|
|
# ========================================================
|
|
# 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()
|