Files
dock_pattern_action/CMakeLists.txt
duongtd 8269e20576 Run the dock detector as an action, from raw scan to goal frame
This is the layer that turns the geometry into something the robot actually
runs. It pulls a raw scan from the shared store, extracts lines, matches the
dock pattern, transforms into the global frame and writes the result as a
static transform - the same output contract FrameSampler has, so the charge
sequence keeps working and nothing in move_base2, dock_planner or
mission_adapters changes. Swapping detectors is one word in the YAML.

It is also the only place in the chain allowed to know about TF, actions and
the sensor store. The three packages beneath it stay free of all that, which
is what lets their tests build a world, cast rays and finish in a millisecond
with no runtime around them.

Three things only break once the pieces are joined, and no core test can see
them:

The scan cursor. A 30 Hz control loop reading a 29 Hz lidar ticks more often
than scans arrive. Without the cursor the same scan counts as several samples,
min_samples stops meaning anything, and the handler commits on one measurement.

TF arriving after the scan. The two come from different sources, so TF running
a few milliseconds behind is routine. The store's cursor has already moved past
that scan, so dropping the sample loses a detection outright every time TF is
late. The detection is now held and transformed on a later tick, without
re-running the match - the shape was already found, only the transform was
missing. The regression test fails without that, which is how it earned its
place.

Transforming at the scan's own stamp rather than at the latest. The pose just
computed belongs to the moment the scan was taken; looking up at another moment
mixes two instants into one measurement. The error from "latest" is small but
nobody knows how small, and a stamp on the wrong clock shows up exactly here.

Rejections happen at boot, not at detection time: no sensor store, a scan_topic
the store does not carry (listing the ones it does - a mistyped topic looks
exactly like a dead sensor), no profiles, a pattern that is not implemented,
a default_profile that does not exist. Every profile is validated, not just the
default one, because a typo in the fifth profile that only surfaces at four in
the afternoon is the worst kind.

An order asking for a profile that does not exist fails and says which ones do.
It does not quietly fall back to the default: using the wrong geometry means
docking in the wrong place, not being slightly slower.

The timeout message says which gate failed. Nothing matched, matched too
rarely, or matched but never settled need opposite responses, and one failure
line cannot carry that.
2026-08-26 13:03:22 +07:00

112 lines
3.4 KiB
CMake

cmake_minimum_required(VERSION 3.0.2)
project(dock_pattern_action VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(Boost REQUIRED)
find_package(Threads REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(catkin REQUIRED COMPONENTS
action_core
dock_pattern_detector
robot_line_extraction
robot_sensor_ports
robot_cpp
robot_sensor_msgs
)
# tf3 không được build bởi workspace này (cài sẵn ở /usr/local/lib/libtf3.so).
find_library(TF3_LIBRARY
NAMES tf3
PATHS /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu
)
if(NOT TF3_LIBRARY)
message(FATAL_ERROR "tf3 not found — install tf3 (/usr/local/lib/libtf3.so) before building")
endif()
catkin_package(
CATKIN_DEPENDS
action_core
dock_pattern_detector
robot_line_extraction
robot_sensor_ports
robot_cpp
robot_sensor_msgs
)
# Header của dependency vào dạng SYSTEM: gói này build với -Wall -Wextra, mà robot_cpp sinh hàng
# trăm warning riêng của nó — để lẫn vào thì warning của chính gói này vô hình.
include_directories(SYSTEM
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
)
# Handler là plugin Boost.DLL, nạp theo khoá `library_path` trong YAML — KHÔNG link thẳng vào ai.
add_library(dock_pattern_action_handler SHARED
plugins/dock_pattern_action_handler.cpp
)
target_compile_options(dock_pattern_action_handler PRIVATE -Wall -Wextra)
add_dependencies(dock_pattern_action_handler ${catkin_EXPORTED_TARGETS})
target_link_libraries(dock_pattern_action_handler
PUBLIC
${catkin_LIBRARIES}
PRIVATE
Boost::boost
yaml-cpp
Threads::Threads
${CMAKE_DL_LIBS}
${TF3_LIBRARY}
)
install(TARGETS dock_pattern_action_handler
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
if(CATKIN_ENABLE_TESTING)
if(NOT COMMAND catkin_add_gtest)
message(FATAL_ERROR "catkin_add_gtest NOT FOUND")
endif()
catkin_add_gtest(dock_pattern_action_test test/dock_pattern_action_test.cpp)
if(TARGET dock_pattern_action_test)
# catkin_add_gtest đặt target EXCLUDE_FROM_ALL; mở ra để binary có mặt sau `catkin_make` thường.
set_target_properties(dock_pattern_action_test PROPERTIES EXCLUDE_FROM_ALL FALSE)
target_compile_options(dock_pattern_action_test PRIVATE -Wall -Wextra)
target_include_directories(dock_pattern_action_test SYSTEM
PRIVATE ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIRS}
)
# Plugin KHÔNG được link thẳng: nó chỉ export alias Boost.DLL và được nạp qua ActionRegistry,
# đúng đường mà runtime đi.
target_link_libraries(dock_pattern_action_test
${catkin_LIBRARIES}
${Boost_LIBRARIES}
yaml-cpp
pthread
${CMAKE_DL_LIBS}
${TF3_LIBRARY}
)
add_dependencies(dock_pattern_action_test dock_pattern_action_handler)
# ctest không mang theo PNKX_NAV_CORE_CONFIG_DIR hay LD_LIBRARY_PATH của shell.
target_compile_definitions(dock_pattern_action_test PRIVATE
DOCK_PATTERN_ACTION_TEST_CONFIG_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test/config"
DOCK_PATTERN_ACTION_TEST_LIBRARY_DIR="${CATKIN_DEVEL_PREFIX}/lib"
)
endif()
endif()