feat: add the 4-leg trolley detection action

TrolleyDetectionActionHandler finds a 4-leg trolley in a raw LaserScan with
dock_pattern_detector's LegPatternMatcher, filters the detections and writes a
static dock_target frame for the docking leg that drives under the trolley.

- entry_direction forward/backward sets the goal heading; a lidar that faces
  the wrong way fails the action instead of writing a reversed goal
- an upside-down lidar (roll pi in TF) is detected from TF and its bearings
  are mirrored; a scan plane tilted more than 5 deg fails the action
- profiles validated at boot; optional prior, reflective tape (all/entry)
- gtest (11 tests) incl. a recorded Gazebo scan from a roll-pi lidar
- sim models trolley_4legs (+ taped variants) the robot can drive under,
  spawn launch and generator script
- doc/MEASURE_AND_CONFIGURE.md: how to measure a trolley and fill the profile
This commit is contained in:
2026-10-28 13:33:52 +07:00
commit bfdcac512f
20 changed files with 9137 additions and 0 deletions

81
README.md Normal file
View File

@@ -0,0 +1,81 @@
# 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. Hai chân như vậy là không dò được.
- **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
```