Second shape after the V. Same output contract - a pose in the scan frame - so
dock_target and everything downstream of it are untouched.
CircleFit uses Taubin rather than Kasa, and that is the whole reason it is
worth writing rather than reaching for the four-line linear fit. Kasa is biased
on a SHORT arc, and a short arc is the normal case: the dock is partly hidden,
or the robot approaches at an angle. Measured on a true 0.40 m arc, 18 points,
3 mm noise, averaged over 200 seeds:
arc span Taubin Kasa
180 deg +0.0 mm -0.0 mm
90 deg +0.1 mm -1.4 mm
45 deg +1.9 mm -24.3 mm
30 deg +8.6 mm -101.6 mm <- Kasa reads 0.40 m as 0.298 m
20 deg +25.4 mm -256.7 mm
With Kasa a 0.40 m dock seen at an angle is scored as 0.30 m, falls outside
radius_tolerance, and the symptom is "it never detects" - indistinguishable
from the dock not being in range. arc_min_span defaults to 30 degrees off that
same table, because below it even Taubin starts to drift.
The matcher takes line segments as input even though it is looking for a curve.
The extractor breaks a curved surface into short straight pieces - correct
behaviour, and convenient here: those pieces are adjacent by ray number, so
their combined support is the arc's point run. That reuses the gap splitting
and outlier rejection that already ran instead of adding a second segmenter
beside the first. A short shallow arc can come out as one segment, looking
straight under min_split_dist, and still fits: the circle fit reads raw points
and does not care what the extractor called them.
Grouping keys on this_start >= prev_end, not >. On a distance split the
extractor SHARES the corner point between both halves, so two pieces of one
surface meet at the same ray number. Requiring strictly greater grouped
nothing, and every 0.5 rad fragment then failed arc_min_span - a real arc
rejected on a fragment's arithmetic. The shared point is also skipped when
gathering, so it does not get double weight at the joint.
The gates, in order:
- fit residual first, because EVERY set of points fits some circle, a right
angle included. Residual is the only thing separating an arc from a bend,
so radius and span only mean something after it passes.
- span has a floor (numerical: trust the fit) and a ceiling (geometric: a
longer arc is a different object). Not an equality - occlusion only ever
shortens an arc, the same asymmetry as the V's wing lengths.
- concavity: the centre must lie between the sensor and the surface. A convex
cylinder is the same circle curving the other way, and taking one for the
other puts the target pose behind the surface - the robot is told to drive
into the object.
The target is the deepest point, C * (1 + R/|C|), which depends only on centre
and radius and so does not move when part of the arc is hidden. The midpoint of
the observed arc would be easier and would shift the moment one side is
occluded.
tape_enabled is refused on an arc profile rather than ignored. findTape walks
the ray span of a fitted line and an arc produces none, so accepting the flag
would leave someone believing a gate is protecting them.
Measured end to end, 200 runs per cell, 3 mm noise, 690 rays: 100% detection at
1.4-2.0 rad of span out to 3 m, apex within 1-2 mm, radius read as 0.399-0.401
against a true 0.400. It thins out at 0.7 rad (77-80% near, 26% at 5 m), which
is arc_min_span doing its job.
234 lines
6.8 KiB
CMake
234 lines
6.8 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
|
|
)
|
|
|
|
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()
|
|
|
|
endif()
|