From 83d40ffdc05df5520d3d519af205406c693920cb Mon Sep 17 00:00:00 2001 From: duongtd Date: Thu, 12 Nov 2026 13:47:43 +0700 Subject: [PATCH] feat: add wall_reflector_detection_action, bump dock_pattern_detector, add its config - New submodule wall_reflector_detection_action b5da961 (branch main) and its add_subdirectory after trolley_detection_action. - dock_pattern_detector 5c1688a -> 95c7df9: ReflectorPairMatcher for two flat reflective strips on a wall (narrow 3/9 cm strips supported). - config/runtime: - action_handlers: detect_wall_reflector handler ENABLED for a robot trial; profile wall_pair (strip 0.03 / spacing 0.09, provisional nanoScan3 intensity 245, other numbers from sim, not measured yet); WallReflectorDetectionActionHandler library_path. - compound_actions: GOTOWALLSTATION = DetectWallReflectors, then move_to wall_reflector_target with marker wall_station. - maker_sources: wall_station profile, deliberately NOT in the maker_sources allow-list, so the move_to leg of GOTOWALLSTATION is rejected until detection is proven on the robot and the docking tail limit-cycle bug is fixed. --- .gitmodules | 4 + CMakeLists.txt | 9 ++ config/runtime/action_handlers_params.yaml | 140 ++++++++++++++++++ config/runtime/compound_actions_params.yaml | 17 +++ config/runtime/maker_sources.yaml | 20 +++ .../actions/wall_reflector_detection_action | 1 + src/Libraries/dock_pattern_detector | 2 +- 7 files changed, 192 insertions(+), 1 deletion(-) create mode 160000 src/Algorithms/Packages/actions/wall_reflector_detection_action diff --git a/.gitmodules b/.gitmodules index 2adb7dd..f87eed1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -104,3 +104,7 @@ path = src/Algorithms/Packages/global_planners/lane_route_planner url = https://git.pnkr.asia/DuongTD/lane_route_planner.git branch = main +[submodule "src/Algorithms/Packages/actions/wall_reflector_detection_action"] + path = src/Algorithms/Packages/actions/wall_reflector_detection_action + url = https://git.pnkr.asia/DuongTD/wall_reflector_detection_action.git + branch = main diff --git a/CMakeLists.txt b/CMakeLists.txt index 4afad0e..73b21af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,6 +289,15 @@ if (NOT TARGET trolley_detection_action_handler) add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Packages/actions/trolley_detection_action) endif() +# Bộ dò trạm dừng trước tường có hai dải phản quang, từ scan LiDAR thô, nạp như một action handler. +# Cần dock_pattern_detector (ReflectorPairMatcher), action_core và robot_sensor_ports — đều đã add ở +# trên. +# +# ⚠ Guard kiểm target thư viện `wall_reflector_detection_action_handler`, như hai gói action trên. +if (NOT TARGET wall_reflector_detection_action_handler) + add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Packages/actions/wall_reflector_detection_action) +endif() + # C API for .NET/C# integration. Target is `nav_c_api` — the guard must name the same target, # otherwise it never matches and the subdirectory is added twice on a re-entrant configure. if (NOT TARGET nav_c_api) diff --git a/config/runtime/action_handlers_params.yaml b/config/runtime/action_handlers_params.yaml index 80aeda1..ce88a79 100644 --- a/config/runtime/action_handlers_params.yaml +++ b/config/runtime/action_handlers_params.yaml @@ -40,6 +40,142 @@ actions: # Dò xe hàng 4 chân (gói trolley_detection_action). TẮT: bỏ comment dòng dưới để bật, SAU KHI # đã đo xe thật và sửa số trong khối `detect_trolley` bên dưới. - {name: detect_trolley, type: TrolleyDetectionActionHandler} + # Dò trạm dừng trước tường có hai dải phản quang (gói wall_reflector_detection_action). BẬT từ + # 12/11/2026 để chạy thử trên robot; profile `wall_pair` trong khối `detect_wall_reflector` bên + # dưới CHƯA đo (intensity còn tạm). Chỉ dò, robot đứng yên. Tắt: comment dòng dưới. + - {name: detect_wall_reflector, type: WallReflectorDetectionActionHandler} + + # --- detect_wall_reflector: dò trạm dừng trước tường có hai dải phản quang ---------------------- + # + # ⚠ ĐANG BẬT để chạy thử (dòng `detect_wall_reflector` trong `handlers:`), số CHƯA đo trên robot: + # kích thước dải theo dải đang thử (rộng 0.03, tâm cách 0.09), intensity tạm theo nanoScan3, mọi + # số còn lại theo sim. Chạy thử: robot đứng yên trước tường, ghi bag `/b_scan`, đo intensity dải + # và tường, rồi sửa profile `wall_pair`. + # + # Robot đứng yên, lidar sau nhìn tường. Handler tìm hai dải trong scan, fit mặt tường, lọc nhiều + # scan, rồi ghi TF tĩnh `wall_reflector_frame` (tâm cặp dải, pháp tuyến tường) và + # `wall_reflector_target` (pose base_link phải đạt). Chỉ dò, không phát cmd_vel. Chặng di chuyển là + # compound `GOTOWALLSTATION` (compound_actions_params.yaml); chặng đó còn bị chặn bằng allow-list + # marker. + detect_wall_reflector: + # [-] Loại action nội bộ; đổi phải khớp bước action trong compound, sai tên sẽ không định tuyến. + action_types: [DetectWallReflectors] + # [frame] Đích base_link; đổi phải đồng bộ move_to, sai frame có thể dùng nhầm TF cũ. + output_frame: wall_reflector_target + # [frame] Tâm/pháp tuyến; để "" tắt, đổi tên phải đổi công cụ quan sát. + marker_frame: wall_reflector_frame + # [topic] Lidar sau. PHẢI khớp một topic trong sensor_store_params.yaml. Kiểm trên robot `/b_scan` + # là lidar nào: thang intensity của mỗi loại lidar khác hẳn nhau, profile phải đo theo đúng lidar đó. + scan_topic: /b_scan + # [-] Lùi vào tường; đổi forward phải đổi lidar và kiểm lại heading. + entry_direction: backward + # [frame] Prior/quạt theo thân robot; đổi frame phải là frame gắn cứng, sai lệch làm sai ROI. + prior_frame: base_link + # [-] Profile dùng khi order không mang khoá `reflector_profile`. + default_profile: wall_pair + # [-] Khóa trong actionParameters để chọn profile; đổi phải đồng bộ phía gửi order. + profile_param_key: reflector_profile + # [s] Chờ robot hết rung; tăng an toàn hơn nhưng chậm dò. + settle_delay: 0.4 + # [s] Hạn action; tăng chờ lâu hơn, phải lớn hơn settle + window + hold. + timeout: 15.0 + # [s] Tuổi scan tối đa; tăng chịu jitter nhưng dễ dùng dữ liệu cũ. + max_scan_age: 0.5 + # [s] Cho phép stamp tương lai; tăng chịu lệch đồng hồ nhưng che lỗi đồng bộ. + max_future_skew: 0.05 + # [s] Hạn giữ detection chờ TF; tăng chịu TF trễ, không vượt max_scan_age. + pending_tf_timeout: 0.2 + # [m] Khoảng tia được xử lý. Dải 3 cm ở xa còn ít tia, sát `tape_min_points`; max_range 1.6 giữ + # phép dò trong tầm robot dừng trước trạm. Tăng max thì dải xa thiếu tia và bị loại; giảm quá + # khoảng cách lidar–tường cộng nửa baseline tường thì mất support. + min_range: 0.1 + max_range: 1.6 + # [-] Range 0 coi là không echo; P1 vẫn loại range 0 khỏi support ở cả hai chế độ. + zero_range_is_no_echo: true + # [số] Giới hạn tải; tăng cho cảnh phức tạp tốn CPU, vượt hạn thì loại scan chứ không cắt. + max_candidates: 16 + max_pairs: 120 + max_scan_rays: 4096 + # [s, mẫu] Cửa sổ và số scan độc lập; tăng giảm nhiễu nhưng làm chậm chốt. + sample_window: 1.0 + min_samples: 5 + # [m, rad] Trần độ tản; tăng dễ chốt hơn nhưng không bảo đảm độ chính xác thật. + max_spread_xy: 0.03 + max_spread_yaw: 0.05 + # [s] Thời gian giữ ổn định; tăng giảm chốt nhất thời nhưng tăng latency. + hold_time: 0.0 + # [m] Ngưỡng gom cụm; 0 tắt, nếu bật phải > max_spread_xy. + jump_threshold: 0.0 + # [s, tỉ lệ, mẫu] Giới hạn cụm khi bật gom; recency lớn giữ cụm cũ lâu hơn. + cluster_recency: 0.3 + min_cluster_fraction: 0.6 + min_cluster_samples: 3 + debug: + # [-] Log theo nhóm mặc định bật; tắt từng nhóm để giảm log, lỗi không bị tắt. + state: true + detect: true + skip: true + profiles: + wall_pair: + # [m] Dải rộng 0.03, tâm cách 0.09 (khe tường giữa 0.06): dải đang thử ngày 12/11/2026. Dán + # dải khác thì đo lại cả hai số bằng thước, ở đúng độ cao lidar. + tape_width: 0.03 + tape_spacing: 0.09 + # [m] Dung sai kích thước. Số theo sim (S300, bước tia 0.337°). Tăng chịu góc xiên/tầm xa hơn + # nhưng dễ ghép nhầm một vật sáng khác; giảm quá thì cặp thật ở xa bị loại vì `width`/`spacing`. + width_tolerance: 0.010 + spacing_tolerance: 0.010 + # [thang intensity của lidar] Tạm theo nanoScan3 (thang 0–255, bão hoà 255), đo dải trên chân + # xe 3/11/2026: lõi dải 240–255, tường 195–215, một điểm sáng không phải dải tới 243. + # ► PHẢI đo lại với dải trên tường, ở tầm xa nhất định dùng: dải bẩn/xa có thể tụt dưới ngưỡng. + # `/b_scan` là lidar khác thì thang khác hẳn — đo, đừng chép. + tape_min_intensity: 240.0 + tape_core_intensity: 240.0 + # [tia] Ít nhất 3 tia core; tăng chống nhiễu nhưng dải 30 mm ở xa hoặc nhìn xiên không đủ tia. + tape_min_points: 3 + # [rad, tỉ lệ] Bloom lidar thật CHƯA đo: 0 = không mask thêm, core chiếm toàn run. Đo độ loang + # quanh dải trong bag rồi mới bật. + tape_bloom_max_angle: 0.0 + tape_plateau_min_fraction: 1.0 + # [m] Bound mép và trần lượng tử, số theo sim; tăng trần nhận góc xấu hơn nhưng sai số lớn hơn. + edge_bias_bound: 0.002 + max_edge_uncertainty: 0.03 + # [-] Cos tối thiểu tia/tường; tăng loại góc xiên sớm hơn. + min_ray_wall_cos: 0.35 + # [tia, m] Support mỗi bên và baseline: tường phẳng phải kéo dài ~0.3 m mỗi bên cặp dải. + # Tăng giúp fit bền nhưng khó dò khi dải gần mép tường. + wall_min_points_each_side: 5 + wall_min_span: 0.65 + # [m] Theo sigma sim 0.01: RMS 2.5 sigma, residual 6 sigma. Đo nhiễu range lidar thật trên + # tường phẳng rồi đặt lại. Tăng dễ lọt tường/vật sai. + wall_max_rms: 0.025 + wall_max_residual: 0.06 + # [m] Khoảng hở tối đa giữa hai tia tường liên tiếp: phải bao một dải (0.03) + một bước tia ở + # tầm xa + nhiễu. Lidar thật có bloom che kín khe 0.06 thì phải ≥ cả cặp (0.12) + hai skirt. + # Tăng có thể che lỗ hoặc vật chắn trong cửa sổ tường. + wall_max_gap: 0.08 + # [m] 0 không ngoại suy mép khỏi support; tăng nhận được gần mép nhưng kém tin cậy. + wall_max_extrapolation: 0.0 + # [m] Chênh residual nhóm; tăng dễ gộp hai mặt khác nhau. + wall_merge_distance: 0.025 + # [-, m, rad] Prior tắt; bật phải đo tâm/yaw trong base_link, dung sai lớn dễ nhầm. + has_prior: false + prior_x: 0.0 + prior_y: 0.0 + prior_yaw: 0.0 + prior_position_tolerance: 0.5 + prior_yaw_tolerance: 0.5 + # [rad] Quạt quanh phía sau; tăng nửa góc thấy rộng hơn nhưng dễ có nhiều cặp. + search_center_yaw: 3.141592653589793 + search_fov: 1.570796326794897 + # [m] Gốc base_link cách mặt tường lúc dừng. |footprint sau| 0.583 + footprint_padding 0.070 + # (cùng nguồn với offset_x của detect_lidar ở trên) → khe đuôi–tường ~0.195 m (trừ dải nhô + # 0.002). PHẢI bằng `dock_face_offset` của marker `wall_station` (maker_sources.yaml). + # ► Chỉnh theo chỗ dừng thật của trạm. Dưới ~0.66 m là đuôi robot chạm tường: nguy hiểm. + offset_x: 0.85 + # [m, rad] Dịch ngang và hiệu chỉnh yaw; đổi phải kiểm lại footprint và chiều lùi. + offset_y: 0.0 + offset_yaw: 0.0 # --- detect: lấy mẫu frame đích rồi ghi ra một frame TF ổn định --------------------------------- # @@ -733,3 +869,7 @@ DockPatternActionHandler: # Bộ dò xe hàng 4 chân từ LiDAR thô. Gói riêng (`trolley_detection_action`). TrolleyDetectionActionHandler: library_path: libtrolley_detection_action_handler + +# Bộ dò trạm dừng trước tường có hai dải phản quang. Gói riêng (`wall_reflector_detection_action`). +WallReflectorDetectionActionHandler: + library_path: libwall_reflector_detection_action_handler diff --git a/config/runtime/compound_actions_params.yaml b/config/runtime/compound_actions_params.yaml index 890972f..7ce6dd0 100644 --- a/config/runtime/compound_actions_params.yaml +++ b/config/runtime/compound_actions_params.yaml @@ -41,6 +41,23 @@ vda5050_src: compound_actions: + # --- GOTOWALLSTATION: lùi vào trạm dừng trước tường có hai dải phản quang ---------------------- + # + # ⚠ Compound đã khai (12/11/2026) nhưng chặng move_to VẪN BỊ CHẶN: `wall_station` chưa có trong + # allow-list `maker_sources` (maker_sources.yaml), nên move_to bị từ chối "marker + # 'wall_station' is invalid" và compound fail ngay sau bước dò — robot không chạy. Chỉ thêm + # `wall_station` vào allow-list khi đủ cả hai điều kiện: + # 1. `detect_wall_reflector` dò ổn trên robot (action_handlers_params.yaml); + # 2. lỗi dao động tiến/lùi cuối chặng dock của HybridDockingLocalPlanner đã sửa (sim 12/11/2026: + # robot lắc 21–30 mm trước đích, không bao giờ vào xy_goal_tolerance, mission không kết thúc). + # Dò xong mới lùi tới target; thất bại phải giữ clear_queue_on_failure=true. + GOTOWALLSTATION: + steps: + - {action: DetectWallReflectors} + # Marker `wall_station`: DockPlanner mating_edge, mặt tường sau đuôi robot đúng + # dock_face_offset. Thiếu marker thì DockPlanner đòi footprint_dock và không khởi tạo được. + - {move_to: wall_reflector_target, profile: docking, marker: wall_station} + # --- charge: vào trạm sạc --------------------------------------------------------------------- CHARGE: steps: diff --git a/config/runtime/maker_sources.yaml b/config/runtime/maker_sources.yaml index cbdbb72..536a199 100644 --- a/config/runtime/maker_sources.yaml +++ b/config/runtime/maker_sources.yaml @@ -93,3 +93,23 @@ docking_marker_profiles: # Goal teach ở tâm mặt pallet → dock không đóng góp khoảng dừng, footprint_dock bị bỏ qua. dock_anchor: face footprint_dock: [[0.5,-0.5],[0.5,0.5],[-0.5,0.5],[-0.5,-0.5]] + + # Trạm dừng trước tường có hai dải phản quang (DetectWallReflectors → `wall_reflector_target`). + # ⚠ TẮT: `wall_station` CHƯA có trong allow-list `maker_sources` ở đầu file, nên chưa đường nào dùng + # được profile này. Đây là chốt chặn chặng lùi của compound `GOTOWALLSTATION`: chỉ thêm tên vào + # allow-list khi đủ hai điều kiện ghi ở compound đó (compound_actions_params.yaml). + # Goal = pose base_link lúc đã dừng (bộ dò cộng sẵn offset_x của profile tường), mặt tường nằm + # sau đuôi robot đúng `dock_face_offset` → cùng ngữ nghĩa với `charger`: mating_edge, nên + # DockPlanner bỏ qua footprint_dock (khai cho đủ khoá, không vào công thức). + wall_station: + global_planner: DockPlanner + local_planner: HybridDockingLocalPlanner + dock_anchor: mating_edge + footprint_dock: [[0.05,-1.0],[0.05,1.0],[-0.05,1.0],[-0.05,-1.0]] + # [m] PHẢI bằng `offset_x` của profile tường đang dùng (detect_wall_reflector, wall_pair: 0.85): + # khoảng từ goal base_link tới mặt tường. Lệch thì planner tính sai chỗ còn được xoay. + # ► Chỉnh: đổi offset_x của profile thì đổi số này theo; trong (0, 2.0] m. + dock_face_offset: 0.85 + # [m] Khe hở thêm cho vòng quét khi xoay tại chỗ gần tường. Tăng an toàn hơn nhưng có thể cấm + # xoay khi robot đã gần trạm. + dock_pivot_safety_margin: 0.10 diff --git a/src/Algorithms/Packages/actions/wall_reflector_detection_action b/src/Algorithms/Packages/actions/wall_reflector_detection_action new file mode 160000 index 0000000..b5da961 --- /dev/null +++ b/src/Algorithms/Packages/actions/wall_reflector_detection_action @@ -0,0 +1 @@ +Subproject commit b5da961449b32617a5285a11d153cb48f36d5d85 diff --git a/src/Libraries/dock_pattern_detector b/src/Libraries/dock_pattern_detector index 5c1688a..95c7df9 160000 --- a/src/Libraries/dock_pattern_detector +++ b/src/Libraries/dock_pattern_detector @@ -1 +1 @@ -Subproject commit 5c1688ac500c223ce7c2b454480777e51a172392 +Subproject commit 95c7df90556fa0196851ce2d76967f395d522a37