Files
dock_pattern_detector/CMakeLists.txt
duongtd a694d5abe2 Find a dock plate in a laser scan and say where the robot must stop
The detection chain had a gap between line segments and a navigation goal.
This is that step: segments plus the geometry of one charger, out comes the
pose base_link has to reach, in the scan's own frame.

Pure geometry, no TF and no action, so it is testable the same way the line
extractor is - build the world, cast the rays, and the answer is known before
the code runs. The tests exercise the real chain end to end, from synthetic
world through robot_line_extraction into the matcher.

The output is the goal pose, not the charger's pose. dock_planner deliberately
carries no standoff key: it derives which edge of the robot meets the dock from
which side of the goal the robot stands on, and that only works because the
goal already is where base_link must end up. The standoff is also a property of
the charger - how deep its contacts sit - so it belongs to the profile.
apex_x/apex_y keep the pre-offset vertex, because a wrong offset and a wrong
detection look identical from the final pose alone.

Matching a V:

The vertex is the intersection of the two fitted lines, not the midpoint of
their endpoints. A line is a least-squares fit over tens of rays; an endpoint
is one ray and much noisier.

Both segments must END near that intersection. Any two non-parallel walls cross
somewhere, and without this gate a corridor corner reads as a dock.

The vertex angle is measured between the two wing vectors from the apex, not
between the two normals. The two agree at exactly 90 degrees and diverge
everywhere else, so confusing them is a silent error at every other opening.

Wing length is what rejects a pallet corner: a pallet has a perfect right
angle, it just has metre-long sides.

Yaw is the bisector pointing back at the sensor, and its sign is chosen by
comparing against the sensor position rather than by the order of the two
wings. That order flips with which side the robot approaches from, and being
180 degrees out here means reversing into the plate instead of driving in.

Confidence is the worst of the three criteria, not their mean. A mean lets a
shape with a badly wrong angle through on the strength of the other two.

The search gate is not optional in a warehouse: any two perpendicular pallets
are a V. candidate_count reports how many survived every gate, so an ambiguous
scene is visible to the layer above rather than silently resolved.

A failed detection reports which gate it failed. "Nothing there" and "something
there but the wrong length" need opposite responses, and one failure line
cannot carry that.

Declaring a pattern that is not implemented is refused at configure time.
Accepting it would produce a detector that never finds anything, which looks
exactly like a charger out of range.
2026-08-26 12:38:29 +07:00

180 lines
5.1 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/v_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()
endif()