Files
trolley_detection_action/README.md
duongtd 0000f64dbc feat: read accept_attached_legs and zero_range_is_no_echo
- Handler: reads zero_range_is_no_echo next to range_sigma (lidar
  property), and accept_attached_legs per profile. The boot summary
  prints "zero range = no echo|blocked". The start line prints
  "attached legs on|off". The match line prints "attached N".
- README, doc/MEASURE_AND_CONFIGURE.md: both keys, when to set them,
  and a log-reason row for attached legs. Also the measuring notes left
  over from the previous fix: cart_dim_tolerance covers machining
  differences between trolleys of one type, dimensions are leg
  centre-to-centre (not outer edge), how to measure range_sigma, and
  the confidence row in the log table.

Needs dock_pattern_detector 979bef3 or later.
2026-10-28 16:37:35 +07:00

83 lines
4.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# trolley_detection_action
Handler `action_core::ActionHandler` dò xe hàng 4 chân từ một LaserScan THÔ, khi robot đứng yên ở
pose chuẩn bị trước xe. Kết quả: một TF tĩnh `output_frame` (thường `dock_target`) = pose robot phải
đạt dưới gầm xe, cho chặng `move_to` sau nó. Plugin Boost.DLL, symbol `TrolleyDetectionActionHandler`,
thư viện `libtrolley_detection_action_handler`.
Lõi hình học nằm ở `dock_pattern_detector` (`LegPatternMatcher`, `LegPoseFit`, `LegProfile`); gói này
chỉ là adapter: kho cảm biến, TF, chọn profile, lọc nhiều scan, ghi kết quả.
## Hợp đồng đầu ra
- **Vị trí** = tâm hình chữ nhật tâm 4 chân + `offset_x/y` của profile (cùng công thức với
`dock_pattern`).
- **Heading** theo `entry_direction`:
| `entry_direction` | Lidar dò | Heading của `output_frame` |
|---|---|---|
| `forward` | lidar trước | trỏ **VÀO** xe — robot tiến thẳng vào gầm |
| `backward` | lidar sau | trỏ **RA** cạnh vào — robot lùi thẳng vào gầm |
Lidar của `scan_topic` phải nhìn đúng hướng với `entry_direction`; lệch thì action fail ngay ở scan
đầu (khai lệch là goal ngược 180°).
**Lidar gắn lộn ngược** (hook_150: roll π) tự xử lý từ TF `prior_frame` ← frame scan, không có khoá
cấu hình: trục z của frame scan chỉ xuống thì góc tia được đảo dấu trước khi dò. Driver không lật dữ
liệu; nếu sau này driver lật thì URDF phải bỏ roll π (costmap cũng đọc TF đó). Mặt quét nghiêng quá
5° so với `prior_frame` → action fail (mô hình chân là 2D).
## Các bước dò (mỗi scan)
1. Lọc tia + lọc điểm kéo đuôi.
2. Tách cụm theo thứ tự tia; giữ cụm đứng tự do có bề rộng của một chân.
3. Ghép cặp chân theo `cart_opening` / `cart_depth` / đường chéo → giả thuyết xe.
4. Khớp tư thế trên mọi điểm chân theo mô hình biên chân; kiểm khoảng cách từng cặp chân.
5. Tia đi xuyên qua chỗ một chân phải đứng → loại. Một chân bị che vẫn nhận (`min_legs: 3`).
6. Chọn cạnh vào (dải `entry` → prior yaw → cạnh quay về robot), cổng prior, điểm tin.
7. Hai xe điểm sát nhau ở hai chỗ → từ chối cả lượt (dãy xe đỗ sát) — đặt prior để chọn.
Sau đó `PoseSampleFilter` gom nhiều scan trong `global_frame` và chốt khi đủ ổn định.
## Giới hạn đã biết
- **Xe đỗ ngược chiều**: 4 chân không dải đối xứng hoàn toàn. Bản không dải không phát hiện được;
dán dải ở 2 chân đầu cần vào và bật `tape_legs: entry`.
- **Chân dính vật khác ở độ cao lidar** (tường, thanh giằng, hàng chạm sàn): mép cụm "dính", chân bị
loại, trừ khi bật `accept_attached_legs` (chân yếu: được tính vào `min_legs` nhưng không lập giả
thuyết). Chân dính liền thành một cụm rộng hơn chân thì vẫn mất.
- **Mặt chân bóng** (nhôm/inox): phản xạ gương làm tia "xuyên qua" chỗ chân → xe thật bị loại. Sơn
mờ hoặc dán băng mờ ở độ cao lidar.
## Config
**Đo xe thật và điền profile: [doc/MEASURE_AND_CONFIGURE.md](doc/MEASURE_AND_CONFIGURE.md)** (hình
sinh bằng `doc/gen_fig.py`).
Khoá handler và profile: xem khối `detect_trolley` trong
`move_base2/config/runtime/action_handlers_params.yaml` (comment tiếng Việt từng khoá) và
`test/config/action_handlers_params.yaml`. Plan đầy đủ (quy ước frame, thuật toán, ngân sách sai
số, đo xe thật): `Test/docs/trolley_detection_action/TROLLEY_LEG_DETECTION_PLAN.md` của workspace
phát triển.
## Sim
- **Chạy thử chui gầm: dùng model đơn giản của gói** (`sim/models`, sinh bằng
`sim/gen_trolley_models.py`): `roslaunch trolley_detection_action spawn_trolley.launch` —
`model:=trolley_4legs` (không dải, mặc định), `trolley_4legs_tape_entry`, `trolley_4legs_tape_all`.
Gốc model ở tâm 4 chân, `z = 0`; sàn xe cao 0.380 m nên `hook_150` chui lọt.
- `tci_trolley` của gói `factory_ss_demo` chỉ dùng để **dò**, không chui được trong Gazebo: mesh có
tấm đáy 0.78 × 0.613 × 0.01 m sát sàn và mặt dưới sàn xe 0.352 m (thấp hơn nóc robot 0.3595 m).
Spawn ở `z = 0.3497`; tâm 4 chân = pose model + R(yaw)·(0.509, 0.5275).
## Build và test
```bash
cd /home/duongtd/T800_ws
source devel/setup.bash
catkin_make --pkg dock_pattern_detector trolley_detection_action
./devel/lib/dock_pattern_detector/leg_pose_fit_test
./devel/lib/dock_pattern_detector/leg_pattern_matcher_test
./devel/lib/trolley_detection_action/trolley_detection_action_test
```