feat(sim): Gazebo wall model, detection sweep and evaluation scripts

- sim/models/wall_reflector_pair: wall with two 3 cm strips 9 cm apart
  (laser_retro 2000 on the strips, 0 on the wall), generated by
  gen_wall_models.py; spawn_wall_reflector.launch places it.
- sim/eval_wall_reflector.py: compares the published marker/target with the
  Gazebo ground truth, read from the handler success log because the nav
  core TF never reaches ROS; --align-by-robot when map != Gazebo world.
- sim/sweep_wall_detection.py: places the wall at several distances and
  angles behind the robot, sends DetectWallReflectors, writes a CSV and
  dumps the scan of every failed case.
- Handler success log now prints marker, target and frame (debug/state).
- Install sim/ in both catkin and standalone builds.
This commit is contained in:
2026-11-12 13:44:16 +07:00
parent f115fd0efd
commit b5da961449
10 changed files with 713 additions and 3 deletions

118
README.md
View File

@@ -2,7 +2,7 @@
Plugin Boost.DLL `WallReflectorDetectionActionHandler` đọc một `LaserScan` thô từ
`robot_sensor_ports::SensorReader`, gọi `ReflectorPairMatcher`, lọc marker theo nhiều scan và ghi TF
tĩnh cho trạm dừng. Gói không phát vận tốc. P2 chưa có cấu hình runtime, world hay chuỗi mission.
tĩnh cho trạm dừng. Gói không phát vận tốc. Cấu hình và model P3 dưới đây chỉ dành cho mô phỏng.
## Contract
@@ -34,7 +34,7 @@ tĩnh cho trạm dừng. Gói không phát vận tốc. P2 chưa có cấu hình
## Khóa handler
Các khóa đặt dưới namespace của handler trong file test; đây là schema đề xuất cho P3:
Các khóa đặt dưới namespace của handler; cấu hình runtime P3 dùng một profile SIM-ONLY:
| Khóa | Default | Miền / đơn vị |
|---|---|---|
@@ -80,3 +80,117 @@ này trong source tree khi build test. Không có khóa `filter_enabled`.
của handler không điều khiển log của thư viện đó và P2 chưa chứng minh không cấp phát trong mọi tick.
Cần xem xét API/budget của `action_core` nếu đây là yêu cầu cứng. Hiệu chuẩn, nghiệm thu robot, xác nhận
đường sensor→bridge→store và chặng điều hướng thuộc các pha sau.
## Mô phỏng Gazebo: chỉ số SIM-ONLY
Model `sim/models/wall_reflector_pair` có mặt tường tối `x=-0.050 m`, mặt tape nhô
`x=-0.052 m`, tâm hai dải ở `y=±0.045 m`, rộng 0.03 m; dải cao 0.10–0.30 m, bao
cao độ lidar sau 0.184 m. Tường `laser_retro=0`, tape `2000`, ngưỡng `1000`. Matcher
chiếu mép lên **mặt tường**, nên marker ground truth ở `(-0.050,0)` trong frame model,
pháp tuyến `-X`; không lấy mặt tape nhô làm tâm marker. Chạy lại generator khi cần:
```bash
python3 /home/duongtd/T800_ws/src/AMR_T800/pnkx_nav_core/src/Algorithms/Packages/actions/wall_reflector_detection_action/sim/gen_wall_models.py
```
Model sinh hai dải rộng 0.03 m, tâm cách 0.09 m (số người dùng đang thử 12/11/2026). Vị trí spawn
mặc định `(3.99,34.5,π)` đặt mặt dải cách lidar sau của robot khởi tạo tại `(5.5,34.5,0)` khoảng
1.0 m (lidar ở base −0.454 m); dải 3 cm ở 2 m chỉ còn ~2.6 tia S300 sim, dưới `tape_min_points: 3`.
Vị trí lấy từ đọc world; **chưa chạy Gazebo để kiểm chứng** vật cản/va chạm tại đó.
Kiểm tra trong Gazebo trước khi gửi action. Chọn lại `x`, `y`, `yaw` nếu cần. Nếu model
trùng tên đã tồn tại, xóa model cũ hoặc đổi `name` khi spawn.
Sau khi build workspace và `source /home/duongtd/T800_ws/devel/setup.bash` trong mỗi
terminal, thứ tự tối thiểu như sau (5 terminal, dùng lại terminal spawn; chỉ sử dụng trong sim):
1. World và robot:
```bash
roslaunch amr_startup sehc_world.launch robot_type:=hook_150
```
2. Khi Gazebo sẵn sàng, spawn tường:
```bash
roslaunch wall_reflector_detection_action spawn_wall_reflector.launch
```
3. Cấp `/map` và `map→odom` bằng map/localization phù hợp với world. Ví dụ mở map
`sehc_factory` sau khi xác nhận nó thực sự khớp world; AMCL cần pose khởi tạo đúng theo map
và scan/TF hợp lệ, không mặc định map trùng Gazebo world:
```bash
roslaunch amr_startup start_maps.launch map_file:=/home/duongtd/T800_ws/src/AMR_T800/Test/simulators/factory_ss_demo/maps/sehc_factory/sehc_factory.yaml with_virtual_walls:=false
```
Ở terminal khác, sau khi biết pose ban đầu trong map, khởi chạy AMCL với các giá trị đó;
ví dụ lệnh dưới chỉ đúng **nếu đã xác nhận** map trùng world:
```bash
roslaunch /home/duongtd/T800_ws/src/AMR_T800/Controllers/Packages/amr_startup/launch/includes/amcl.launch scan_topic:=/b_scan initial_pose_x:=5.5 initial_pose_y:=34.5 initial_pose_a:=0.0
```
Theo dõi localization hội tụ trước khi dò; số `(5.5,34.5,0)` là pose Gazebo, không tự chứng minh pose map.
4. Host dùng cây dev, sau khi topic/TF sẵn sàng:
```bash
export PNKX_NAV_CORE_CONFIG_DIR=/home/duongtd/T800_ws/src/AMR_T800/pnkx_nav_core/src/Navigations/Packages/move_base2/config/runtime
roslaunch amr_startup amr_control.launch robot_type:=hook_150 with_virtual_walls:=false 2>&1 | tee /tmp/amr_control_wall.log
```
`tee` giữ log để bước đánh giá đọc dòng kết quả của handler.
Host này đổi stamp sim về wall clock cho handler. Kiểm tra log boot đã nạp đúng handler/profile,
sensor store và `/b_scan`; MQTT broker và định danh phải được cấu hình sẵn. Cây root `config/runtime`
hiện comment `/b_scan` trong sensor store nên không dùng được cấu hình mới cho tới khi khai topic.
5. Chỉ dò, không di chuyển: gửi VDA5050 instant action bằng công cụ có sẵn. `--no-validate`
bỏ kiểm schema phía script; phía nhận vẫn có thể từ chối. Xác nhận kết quả của **actionId hiện tại**
trong state/log, không suy ra thành công từ TF cũ.
```bash
python3 /home/duongtd/T800_ws/src/AMR_T800/Controllers/Packages/amr_comunication/scripts/vda5050_send.py /dev/stdin --kind instantActions --no-validate <<'JSON'
{"actions":[{"actionType":"DetectWallReflectors","actionId":"wall-detect-1","blockingType":"HARD","actionParameters":[]}]}
JSON
```
Compound `GoToWallStation` chạy `DetectWallReflectors` rồi `move_to: wall_reflector_target`
qua profile `docking`; nó **ra lệnh di chuyển lùi**, chỉ dùng sau khi xác nhận đường chạy, footprint,
costmap và dừng an toàn trong sim. Profile docking hiện tắt tránh vật cản theo cấu hình hiện có;
`clear_queue_on_failure` phải vẫn bật. Thử qua cùng lệnh instant action ở trên, thay actionType bằng
`GoToWallStation` và actionId bằng một ID mới. Chưa xác nhận end-to-end routing/điều khiển cho scene này.
### Đánh giá pose
Handler ghi marker/target vào **tf3 nội bộ**; `amr_control` chỉ mirror ROS TF → tf3, không phát
ngược lại, nên không đọc được hai frame kết quả bằng ROS TF. Khi thành công, handler log một dòng
(nhóm `debug/state`, phải đang bật):
```text
[wall_reflector][debug] 'detect_wall_reflector': output TF published: marker=(x, y, yaw) target=(x, y, yaw) frame=map
```
Script đọc dòng **cuối** như vậy trong log và so với ground truth từ `/gazebo/model_states`
(mặt tường tối của model, giữa hai dải; target = marker + offset của profile):
```bash
python3 /home/duongtd/T800_ws/src/AMR_T800/pnkx_nav_core/src/Algorithms/Packages/actions/wall_reflector_detection_action/sim/eval_wall_reflector.py --assume-map-equals-world --confirm-current-success --log /tmp/amr_control_wall.log
```
Sau compound `GoToWallStation`, đo pose robot thật trong Gazebo so với target thật (gồm cả sai số
localization và controller, không chỉ detector):
```bash
python3 /home/duongtd/T800_ws/src/AMR_T800/pnkx_nav_core/src/Algorithms/Packages/actions/wall_reflector_detection_action/sim/eval_wall_reflector.py --assume-map-equals-world --confirm-current-success --robot-final
```
Có thể nhập tay số từ dòng log bằng `--marker X Y YAW --target X Y YAW` thay cho `--log`.
Chỉ dùng cờ `--assume-map-equals-world` sau khi đã kiểm chứng hai frame trùng nhau; nếu không,
thay bằng `--world-to-map X Y YAW` với ba số đo độc lập [m,m,rad], là pose world trong map.
Nếu profile/model name thay đổi, truyền `--offset-x`, `--offset-y`, `--offset-yaw`,
`--entry-direction`, `--wall-model`, `--robot-model` tương ứng. Sai số in theo hệ marker thật:
lateral dọc tường, depth theo pháp tuyến, yaw. ModelStates không có stamp và log có thể chứa lượt cũ:
xác nhận actionId hiện tại thành công trước khi đọc; phép đo không đồng bộ, không dùng làm chứng
nhận độ chính xác robot thật.