On the KIT robot (28/10), hiding one trolley leg with a post always made detection fail with "too few legs". The far-right leg stood less than leg_min_depth_gap in front of another object, so its cluster was rejected as "attached". Hiding one more leg left only two free-standing legs. - LegProfile::accept_attached_legs (default false): an attached cluster that passes the width and point gates becomes a weak leg. A weak leg can be assigned to a corner, counts toward min_legs and enters the fit, but it cannot start a hypothesis. So every cart still needs one pair of free-standing legs at the right spacing. - ScanLimits::zero_range_is_no_echo (default false): the KIT driver reports no echo as range 0. The matcher read 0 as "blocked closer than min_range", so every leg edge was marked partial, and a 0 ray at a missing corner always read as occluded. With the flag set, an edge next to a 0 ray is free. A corner that sees only 0 rays carries no evidence. A ray that passes the corner and returns from a surface behind it still rejects the cart. - Confidence ties: fit_term saturates at 1, so two 4-leg hypotheses can both score 1.00. The nearer one used to win, even when it had taken a post standing 9 cm from a leg (3.4 cm off). Ties now go to the lower normalized RMS first. - LegDetection::legs_attached; the reason text says when only attached legs were found at the cart spacing. Tests: leg_pattern_matcher_kit_test replays 6 real KIT scans (test/data/kit_f_scan_trolley_occlusion.txt). leg_pattern_matcher_test adds 4 synthetic cases. With both keys off, behaviour is unchanged except for the tie rule. All 111 tests of this package and the trolley handler pass.
273 lines
8.3 KiB
CMake
273 lines
8.3 KiB
CMake
cmake_minimum_required(VERSION 3.0.2)
|
|
project(dock_pattern_detector VERSION 0.1.0 LANGUAGES CXX)
|
|
|
|
# ========================================================
|
|
# Build mode detection
|
|
# ========================================================
|
|
if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL)
|
|
set(BUILDING_WITH_CATKIN TRUE)
|
|
message(STATUS "Building dock_pattern_detector with Catkin")
|
|
else()
|
|
set(BUILDING_WITH_CATKIN FALSE)
|
|
message(STATUS "Building dock_pattern_detector with Standalone CMake")
|
|
endif()
|
|
|
|
|
|
# ========================================================
|
|
# C++ Standard
|
|
# ========================================================
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
|
# ========================================================
|
|
# Dependencies
|
|
# ========================================================
|
|
# Eigen là phụ thuộc DUY NHẤT, và chỉ dùng ở bước gộp hai đoạn. Gói này cố ý không kéo robot_cpp,
|
|
# costmap hay message nào — đó là thứ khiến nó test được bằng scan tổng hợp, không cần runtime.
|
|
find_package(Eigen3 REQUIRED)
|
|
|
|
|
|
# ========================================================
|
|
# Catkin configuration
|
|
# ========================================================
|
|
if(BUILDING_WITH_CATKIN)
|
|
|
|
find_package(catkin REQUIRED COMPONENTS
|
|
robot_line_extraction
|
|
)
|
|
|
|
catkin_package(
|
|
INCLUDE_DIRS
|
|
include
|
|
|
|
LIBRARIES
|
|
dock_pattern_detector
|
|
|
|
CATKIN_DEPENDS
|
|
robot_line_extraction
|
|
|
|
DEPENDS
|
|
EIGEN3
|
|
)
|
|
|
|
include_directories(SYSTEM ${catkin_INCLUDE_DIRS})
|
|
|
|
endif()
|
|
|
|
|
|
# ========================================================
|
|
# Library
|
|
# ========================================================
|
|
add_library(dock_pattern_detector SHARED
|
|
src/dock_profile.cpp
|
|
src/arc_pattern_matcher.cpp
|
|
src/circle_fit.cpp
|
|
src/v_pattern_matcher.cpp
|
|
# Dò xe hàng 4 chân: đọc scan thô, không qua đoạn thẳng. Dùng bởi trolley_detection_action.
|
|
src/leg_profile.cpp
|
|
src/leg_pose_fit.cpp
|
|
src/leg_pattern_matcher.cpp
|
|
)
|
|
|
|
target_compile_options(dock_pattern_detector PRIVATE -Wall -Wextra)
|
|
|
|
target_include_directories(dock_pattern_detector
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE:include>
|
|
)
|
|
|
|
# Header của Eigen vào dạng SYSTEM: gói này build với -Wall -Wextra, mà Eigen sinh warning riêng
|
|
# của nó — để lẫn vào thì warning của chính gói này vô hình.
|
|
target_include_directories(dock_pattern_detector SYSTEM
|
|
PUBLIC
|
|
${EIGEN3_INCLUDE_DIRS}
|
|
)
|
|
|
|
if(BUILDING_WITH_CATKIN)
|
|
target_link_libraries(dock_pattern_detector PUBLIC ${catkin_LIBRARIES})
|
|
else()
|
|
target_include_directories(dock_pattern_detector SYSTEM
|
|
PUBLIC
|
|
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../robot_line_extraction/include>"
|
|
)
|
|
target_link_libraries(dock_pattern_detector PUBLIC robot_line_extraction)
|
|
endif()
|
|
|
|
if(NOT BUILDING_WITH_CATKIN)
|
|
set_target_properties(dock_pattern_detector PROPERTIES
|
|
POSITION_INDEPENDENT_CODE ON
|
|
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
BUILD_RPATH "${CMAKE_BINARY_DIR}"
|
|
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
|
|
)
|
|
endif()
|
|
|
|
|
|
# ========================================================
|
|
# Install
|
|
# ========================================================
|
|
if(BUILDING_WITH_CATKIN)
|
|
|
|
install(TARGETS dock_pattern_detector
|
|
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
|
|
)
|
|
|
|
install(DIRECTORY include/${PROJECT_NAME}/
|
|
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
|
|
FILES_MATCHING PATTERN "*.h"
|
|
)
|
|
|
|
else()
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
install(TARGETS dock_pattern_detector
|
|
EXPORT ${PROJECT_NAME}-targets
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
)
|
|
|
|
install(EXPORT ${PROJECT_NAME}-targets
|
|
FILE ${PROJECT_NAME}-targets.cmake
|
|
NAMESPACE ${PROJECT_NAME}::
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
|
)
|
|
|
|
install(DIRECTORY include/${PROJECT_NAME}/
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
|
|
FILES_MATCHING PATTERN "*.h"
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
# ========================================================
|
|
# Tests
|
|
# ========================================================
|
|
if(CATKIN_ENABLE_TESTING AND BUILDING_WITH_CATKIN)
|
|
|
|
if(NOT COMMAND catkin_add_gtest)
|
|
message(FATAL_ERROR "catkin_add_gtest NOT FOUND")
|
|
endif()
|
|
|
|
catkin_add_gtest(v_pattern_matcher_test test/v_pattern_matcher_test.cpp)
|
|
|
|
if(TARGET v_pattern_matcher_test)
|
|
# catkin_add_gtest đặt target EXCLUDE_FROM_ALL; mở ra để binary có mặt sau `catkin_make`
|
|
# thường, đúng quy trình verify của repo.
|
|
set_target_properties(v_pattern_matcher_test PROPERTIES EXCLUDE_FROM_ALL FALSE)
|
|
|
|
target_compile_options(v_pattern_matcher_test PRIVATE -Wall -Wextra)
|
|
|
|
target_include_directories(v_pattern_matcher_test
|
|
PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
)
|
|
|
|
target_include_directories(v_pattern_matcher_test SYSTEM
|
|
PRIVATE
|
|
${EIGEN3_INCLUDE_DIRS}
|
|
)
|
|
|
|
# catkin_add_gtest dùng target_link_libraries dạng plain, nên phần bổ sung cũng phải plain.
|
|
target_link_libraries(v_pattern_matcher_test
|
|
dock_pattern_detector
|
|
pthread
|
|
)
|
|
endif()
|
|
|
|
catkin_add_gtest(circle_fit_test test/circle_fit_test.cpp)
|
|
|
|
if(TARGET circle_fit_test)
|
|
# catkin_add_gtest đặt target EXCLUDE_FROM_ALL; mở ra để binary có mặt sau `catkin_make`
|
|
# thường, đúng quy trình verify của repo.
|
|
set_target_properties(circle_fit_test PROPERTIES EXCLUDE_FROM_ALL FALSE)
|
|
|
|
target_compile_options(circle_fit_test PRIVATE -Wall -Wextra)
|
|
|
|
target_include_directories(circle_fit_test
|
|
PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
)
|
|
|
|
target_include_directories(circle_fit_test SYSTEM
|
|
PRIVATE
|
|
${EIGEN3_INCLUDE_DIRS}
|
|
)
|
|
|
|
# catkin_add_gtest dùng target_link_libraries dạng plain, nên phần bổ sung cũng phải plain.
|
|
target_link_libraries(circle_fit_test
|
|
dock_pattern_detector
|
|
pthread
|
|
)
|
|
endif()
|
|
|
|
catkin_add_gtest(arc_pattern_matcher_test test/arc_pattern_matcher_test.cpp)
|
|
|
|
if(TARGET arc_pattern_matcher_test)
|
|
# catkin_add_gtest đặt target EXCLUDE_FROM_ALL; mở ra để binary có mặt sau `catkin_make`
|
|
# thường, đúng quy trình verify của repo.
|
|
set_target_properties(arc_pattern_matcher_test PROPERTIES EXCLUDE_FROM_ALL FALSE)
|
|
|
|
target_compile_options(arc_pattern_matcher_test PRIVATE -Wall -Wextra)
|
|
|
|
target_include_directories(arc_pattern_matcher_test
|
|
PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
)
|
|
|
|
target_include_directories(arc_pattern_matcher_test SYSTEM
|
|
PRIVATE
|
|
${EIGEN3_INCLUDE_DIRS}
|
|
)
|
|
|
|
# catkin_add_gtest dùng target_link_libraries dạng plain, nên phần bổ sung cũng phải plain.
|
|
target_link_libraries(arc_pattern_matcher_test
|
|
dock_pattern_detector
|
|
pthread
|
|
)
|
|
endif()
|
|
|
|
# Test của bộ dò xe hàng: hai test đầu dùng bộ dựng scan tổng hợp `test/leg_scan_sim.h`, test
|
|
# `_kit` đọc scan thật của lidar KIT trong `test/data/`.
|
|
foreach(leg_test leg_pose_fit_test leg_pattern_matcher_test leg_pattern_matcher_kit_test)
|
|
catkin_add_gtest(${leg_test} test/${leg_test}.cpp)
|
|
|
|
if(TARGET ${leg_test})
|
|
# catkin_add_gtest đặt target EXCLUDE_FROM_ALL; mở ra để binary có mặt sau `catkin_make`
|
|
# thường, đúng quy trình verify của repo.
|
|
set_target_properties(${leg_test} PROPERTIES EXCLUDE_FROM_ALL FALSE)
|
|
|
|
target_compile_options(${leg_test} PRIVATE -Wall -Wextra)
|
|
target_compile_definitions(${leg_test}
|
|
PRIVATE
|
|
DOCK_PATTERN_DETECTOR_TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test/data"
|
|
)
|
|
|
|
target_include_directories(${leg_test}
|
|
PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
${CMAKE_CURRENT_SOURCE_DIR}/test
|
|
)
|
|
|
|
target_include_directories(${leg_test} SYSTEM
|
|
PRIVATE
|
|
${EIGEN3_INCLUDE_DIRS}
|
|
)
|
|
|
|
# catkin_add_gtest dùng target_link_libraries dạng plain, nên phần bổ sung cũng phải plain.
|
|
target_link_libraries(${leg_test}
|
|
dock_pattern_detector
|
|
pthread
|
|
)
|
|
endif()
|
|
endforeach()
|
|
|
|
endif()
|