Compare commits
9 Commits
9cf84c641c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b9a0cede5 | |||
| 422a505c3d | |||
| c94c5b2b0c | |||
| 07e2fd3b38 | |||
| 9d31c0e5db | |||
| 7c93fe47aa | |||
| 7c969d037b | |||
| 1f04a95e1b | |||
| a301987808 |
@@ -116,16 +116,14 @@ endif()
|
||||
# Focused contract tests use a tiny self-contained runner so both catkin and
|
||||
# standalone builds exercise the same code without adding a test dependency.
|
||||
#
|
||||
# Tests are a development-machine concern: a catkin workspace is where they run,
|
||||
# while the standalone CMake build is the robot deployment path and must not
|
||||
# produce test executables. Force with -DBUILD_DOCK_PLANNER_TESTS=ON to build
|
||||
# them from a standalone build.
|
||||
# Tests are OFF by default in both build modes; enable with
|
||||
# -DBUILD_DOCK_PLANNER_TESTS=ON.
|
||||
#
|
||||
# include(CTest) used to sit here for the standalone branch. It is deliberately
|
||||
# gone: it defines BUILD_TESTING=ON for the WHOLE CMake tree, which switched the
|
||||
# tests of every other package in the aggregate build back on.
|
||||
option(BUILD_DOCK_PLANNER_TESTS "Build the dock_planner contract tests"
|
||||
${BUILDING_WITH_CATKIN})
|
||||
OFF)
|
||||
|
||||
if(BUILD_DOCK_PLANNER_TESTS AND
|
||||
(NOT BUILDING_WITH_CATKIN OR CATKIN_ENABLE_TESTING))
|
||||
@@ -133,7 +131,9 @@ if(BUILD_DOCK_PLANNER_TESTS AND
|
||||
enable_testing()
|
||||
endif()
|
||||
add_executable(${PROJECT_NAME}_test test/dock_planner_test.cpp)
|
||||
target_link_libraries(${PROJECT_NAME}_test PRIVATE ${PROJECT_NAME})
|
||||
# The test builds YAML nodes for the config loader directly; the library links
|
||||
# yaml-cpp PRIVATE and does not pass it on, so the test links it itself.
|
||||
target_link_libraries(${PROJECT_NAME}_test PRIVATE ${PROJECT_NAME} yaml-cpp)
|
||||
if(BUILDING_WITH_CATKIN)
|
||||
add_dependencies(${PROJECT_NAME}_test ${catkin_EXPORTED_TARGETS})
|
||||
endif()
|
||||
|
||||
328
README.md
328
README.md
@@ -1,85 +1,295 @@
|
||||
# Dock Planner
|
||||
|
||||
Global planner cho docking Ackermann theo một maneuver xác định:
|
||||
Global planner sinh đường vào dock, implement `robot_nav_core::BaseGlobalPlanner`
|
||||
và export bằng `BOOST_DLL_ALIAS` với symbol `DockPlanner`.
|
||||
|
||||
Planner chủ yếu sinh **hình học**. Có thể bật kiểm tra `LETHAL_OBSTACLE` trong
|
||||
costmap cho các đoạn tiếp cận và điểm xoay của hai kiểu pivot; terminal đi vào
|
||||
dock không được kiểm tra vì LETHAL gần charger/chân trolley có thể là tiếp xúc
|
||||
dự kiến. Direct entry và single cusp vẫn chỉ kiểm tra hình học — xem "Phạm vi
|
||||
an toàn hiện tại".
|
||||
|
||||
## Các kiểu đường
|
||||
|
||||
Planner thử các kiểu legacy theo ladder hiện có và lấy kiểu **đầu tiên dựng
|
||||
được**. Kiểu nào không dựng được thì **rơi xuống kiểu kế tiếp**, không bao giờ
|
||||
trở thành lỗi. Chỉ khi mọi kiểu legacy đều trượt mới thử back-off pivot, nếu
|
||||
được bật. Chỉ khi cả ladder và back-off đều trượt mới trả `false` kèm một dòng
|
||||
log liệt kê đủ số đo.
|
||||
|
||||
```text
|
||||
start -- tiến theo cung tròn --> cusp -- lùi thẳng --> goal
|
||||
1. direct_entry start ──── cung ────╮
|
||||
╰─ thẳng ─► goal
|
||||
|
||||
2. straight_pivot_straight start ── thẳng ─ ⟳B ─ thẳng ─ V ⟳xoay⟳ ─► goal
|
||||
đoạn thẳng đầu có thể lấn ra sau điểm start
|
||||
|
||||
3. single_cusp goal ◄─ thẳng ─ ✖cusp
|
||||
╰─ cung ─── start
|
||||
lấn thêm `cusp_extension` mét về phía XA dock
|
||||
|
||||
4. backoff_pivot_straight start ── back-off ─ ⟳B ─ thẳng ─ V ⟳xoay⟳ ─► goal
|
||||
chỉ dùng khi mọi kiểu legacy thất bại; cần differential
|
||||
```
|
||||
|
||||
Planner chỉ sinh hình học. Collision/free-space checking chưa được implement.
|
||||
Đoạn cuối của cả bốn kiểu luôn **thẳng** và trùng hướng yaw của goal: robot phải
|
||||
đạt đúng hướng trước khi chui vào dock.
|
||||
|
||||
## Luồng xử lý
|
||||
|
||||
1. `DockPlanner::initialize()` load và validate config.
|
||||
2. Lấy `wheel_base` từ TF `front_axle_frame -> rear_axle_frame`, giống
|
||||
`StanleyControl`.
|
||||
3. Tính giới hạn động học bicycle:
|
||||
### Kiểu nào được chọn
|
||||
|
||||
```text
|
||||
minimum_turning_radius = wheel_base / tan(max_steering_angle)
|
||||
turns_in_place = (model == differential) && (minimum_turning_radius == 0)
|
||||
pivot_enabled = turns_in_place || (pivot_fallback_extension > 0)
|
||||
prefer_pivot = pivot_enabled && ( turns_in_place
|
||||
|| cusp không đặt được
|
||||
|| cusp_extension > pivot_fallback_extension )
|
||||
```
|
||||
|
||||
4. `DockCalc` đổi start sang hệ tọa độ goal: longitudinal dọc trục dock và
|
||||
lateral vuông góc trục dock.
|
||||
5. Chọn cusp ở phía trước start, đủ xa dock và đủ xa để cung tiếp cận có bán
|
||||
kính không nhỏ hơn `minimum_turning_radius`.
|
||||
6. Lấy mẫu cung tiến. Pose yaw luôn cùng chiều tangent của cung, không dùng yaw
|
||||
hiện tại của robot.
|
||||
7. Lấy mẫu đoạn thẳng từ cusp về goal. Pose yaw giữ bằng goal yaw nên controller
|
||||
phân loại đoạn này là chạy lùi.
|
||||
8. Ghép hai đoạn, bỏ điểm cusp trùng và đóng dấu frame/time.
|
||||
| tình huống | thứ tự thử |
|
||||
|---|---|
|
||||
| `turns_in_place` | direct_entry → **pivot** → cusp |
|
||||
| `cusp_extension` vượt ngưỡng hoặc cusp không đặt được | direct_entry → **pivot** → cusp |
|
||||
| cusp rẻ | direct_entry → **cusp** → pivot |
|
||||
| `pivot_fallback_extension = 0`, không turns_in_place | direct_entry → **cusp** |
|
||||
|
||||
## Hợp đồng hình học
|
||||
`backoff_pivot_straight` nằm sau toàn bộ ladder trên. Nó chỉ được thử khi
|
||||
`model: differential`, pivot đang bật theo quy tắc hiện có, và
|
||||
`pivot_backoff_max_distance > 0`. Đường này không dùng `minimum_turning_radius`
|
||||
hay `max_steering_angle`: nó giữ nguyên yaw thân xe khi back-off, dừng ở
|
||||
`pivot_vertex_distance + path_point_spacing`, rồi dùng đoạn pivot và terminal
|
||||
hiện có. Nếu hướng thân xe cách vuông góc với trục tiếp cận dưới 15° (chiếu dọc
|
||||
trục nhỏ hơn 0.26 m trên mỗi mét) hoặc quãng back-off vượt giới hạn, kiểu này
|
||||
bị loại. Một rotation block tại B để local planner đổi sang hướng của đoạn pivot
|
||||
khi cần; rotation block tại vertex vẫn theo cách cũ.
|
||||
|
||||
- Goal yaw phải chỉ từ dock ra phía robot tiếp cận. Start phải có longitudinal
|
||||
dương trong frame goal; planner từ chối start nằm phía sau dock thay vì âm
|
||||
thầm đảo goal yaw.
|
||||
- Robot footprint phải có ít nhất ba điểm, hữu hạn, có X/Y extent dương. Đoạn
|
||||
cuối luôn lùi nên khoảng cách cusp tối thiểu dùng `rear_extent` của robot.
|
||||
- `dock_anchor: center` cộng near-face `front_extent` của `footprint_dock` vào
|
||||
khoảng cách cusp. `dock_anchor: face` bỏ qua dock footprint.
|
||||
- Cung đầu luôn chạy tiến và có `radius >= minimum_turning_radius`.
|
||||
- Đoạn cuối nằm đúng trên trục dock, chạy lùi và có yaw bằng goal yaw.
|
||||
- Path có đúng một lần đổi chiều tại cusp.
|
||||
- Mọi lỗi TF, NaN/Inf, footprint sai, bán kính sai hoặc maneuver vượt giới hạn
|
||||
đều trả `false`; planner không trả partial path.
|
||||
`cusp_extension = cusp_distance − start_longitudinal`, tức cusp bắt robot chạy ra
|
||||
xa dock thêm bao nhiêu **so với chỗ nó đang đứng**. Đại lượng này cố ý là **tương
|
||||
đối**: một số tuyệt đối kiểu "chiều sâu lối đi" sẽ tính cả chỗ robot đang đứng
|
||||
vào phần "cần thêm", và loại sạch mọi manơ xuất phát từ khoảng cách bình thường.
|
||||
|
||||
`footprint_dock` và `dock_anchor` được move_base2 copy từ
|
||||
`docking_marker_profiles/<marker>/` vào namespace `DockPlanner` trước khi tạo
|
||||
plugin.
|
||||
`direct_entry` chỉ vào danh sách khi `direct_entry_min_curve_room > 0` và khoảng
|
||||
chỗ còn lại cho cung vượt ngưỡng đó.
|
||||
|
||||
## Hai mô hình động học
|
||||
|
||||
| | `ackermann` | `differential` |
|
||||
|---|---|---|
|
||||
| `R_min` | **đo**: `wheel_base / tan(max_steering_angle)` | **đọc**: `minimum_turning_radius` |
|
||||
| `wheel_base` | lấy từ TF `rear_axle_frame → front_axle_frame` | không dùng, đặt 0 |
|
||||
| TF trục bánh | bắt buộc phải tra được, không thì `initialize()` fail | **không tra** |
|
||||
| `max_steering_angle` | bắt buộc, phải ∈ (0, π/2) | không đọc, không validate |
|
||||
| axle frames | phải khác nhau, không rỗng | không đọc, không validate |
|
||||
| xoay tại chỗ | chỉ khi `pivot_fallback_extension > 0` | khi `minimum_turning_radius == 0` |
|
||||
|
||||
`R_min == 0` là **giá trị hợp lệ**, không phải lỗi: đó là thứ cho phép planner
|
||||
đặt một cú xoay tại chỗ vào path. Chỉ số âm hoặc không hữu hạn mới là lỗi.
|
||||
|
||||
Back-off pivot chỉ dành cho `model: differential`. Ackermann giữ nguyên ladder
|
||||
và không thử kiểu này, kể cả khi `pivot_backoff_max_distance` lớn hơn 0.
|
||||
|
||||
Khai nhầm `ackermann` cho robot vi sai thì plugin **không nạp được** — nó đi tra
|
||||
frame `steer_link` mà robot vi sai không có.
|
||||
|
||||
## Điểm xoay đặt ở đâu
|
||||
|
||||
```text
|
||||
margin_eff = dock_pivot_safety_margin khi mating_edge và được khai; còn lại dùng pivot_safety_margin
|
||||
|
||||
center / face:
|
||||
Xv = max( straight_distance,
|
||||
circumscribed_radius + dock_extent + margin_eff )
|
||||
|
||||
mating_edge:
|
||||
Xv = max( straight_distance,
|
||||
circumscribed_radius - face_offset + margin_eff )
|
||||
face_offset = dock_face_offset nếu được khai, nếu không dùng mating_extent
|
||||
|
||||
mating_edge terminal floor = max( max(mating_extent - face_offset, 0)
|
||||
+ reverse_distance_padding,
|
||||
path_point_spacing )
|
||||
```
|
||||
|
||||
Xoay tại chỗ quay **mọi** điểm footprint quanh `base_link`, nên kích thước phải
|
||||
dùng là **bán kính ngoại tiếp**, không phải `front_extent`/`rear_extent`. Với
|
||||
footprint 1.65 / −0.35 × ±0.40: ngoại tiếp `hypot(1.65, 0.40) = 1.698 m` trong
|
||||
khi mép sau chỉ 0.35 m. Đặt điểm xoay theo mép sau là góc robot cắt vào dock.
|
||||
Với `mating_edge`, `dock_face_offset` đo từ goal quay về mặt dock thật nên offset
|
||||
lớn hơn sẽ đưa điểm xoay và terminal floor gần dock hơn. Giá trị phải khớp số đo;
|
||||
khai lớn quá có thể làm robot quét vào dock.
|
||||
|
||||
`circumscribed_radius` là max `hypot(x, y)` trên các đỉnh footprint. Chính xác
|
||||
tuyệt đối, kể cả footprint lõm: khoảng cách là hàm lồi nên cực đại trên đa giác
|
||||
luôn rơi vào một đỉnh.
|
||||
|
||||
Chiều chạy đoạn 1 chọn theo **|góc xoay| nhỏ nhất**. Trên cả hai phía dock, lựa
|
||||
chọn đó trùng chiều đoạn cuối, nên path có **một chiều chạy duy nhất** từ đầu tới
|
||||
cuối — không có điểm đổi chiều nào, tốt hơn `single_cusp` về mặt điều khiển.
|
||||
|
||||
## Khối xoay được mã hoá thế nào — hợp đồng với local planner
|
||||
|
||||
Cú xoay ghi vào path thành một **khối pose cùng vị trí, yaw tăng dần**, chứ không
|
||||
phải một đỉnh gãy trần: robot Ackermann lẫn vi sai đều không đổi hướng tức thời
|
||||
tại vertex được.
|
||||
|
||||
Ba ràng buộc bắt buộc, sai một cái là khối bị nuốt mất:
|
||||
|
||||
1. Khối ghi bằng `push_back`, **không** qua `appendUnique()` — hàm đó tồn tại
|
||||
đúng để xoá pose không di chuyển, tức xoá sạch khối xoay.
|
||||
2. Khối tối thiểu **4 pose cùng vị trí**. `StanleyControl::planDivision` chỉ tách
|
||||
segment xoay sau `++rot_count > 2`, mà `rot_count` chỉ tăng ở pose có
|
||||
`same_xy_prev`. Planner phát 7 pose (vertex + `kPivotBlockSteps`).
|
||||
3. Bước yaw mỗi pose phải `> kPlanEpsilon` (`1e-6`), nếu không `same_yaw` đúng và
|
||||
Case 1 không đếm.
|
||||
|
||||
Đổi local planner docking sang plugin khác thì phải kiểm lại ba điều trên —
|
||||
planner mới có nhận dạng khối pose cùng vị trí không.
|
||||
|
||||
## Mép nào của robot áp vào dock
|
||||
|
||||
**Suy ra** theo từng lần lập plan, không cấu hình được:
|
||||
|
||||
| robot đứng phía | mép áp dock | đoạn dẫn | đoạn cuối |
|
||||
|---|---|---|---|
|
||||
| `+X` của goal | sau (`rear_extent`) | tiến | lùi |
|
||||
| `−X` của goal | trước (`front_extent`) | lùi | tiến |
|
||||
|
||||
Suy được vì goal đã offset sẵn từ tầng trên sao cho `base_link` dừng đúng tại
|
||||
goal khi manơ hoàn tất. Start nằm đúng trên trục ngang của goal thì không suy
|
||||
được phía nào và plan bị từ chối.
|
||||
|
||||
## Tham số cấu hình
|
||||
|
||||
File mặc định: `config/dock_global_params.yaml`.
|
||||
File mặc định đi kèm gói: `config/dock_global_params.yaml`. Cây đang chạy nằm ở
|
||||
`move_base2/config/runtime/` và `pnkx_nav_core/config/`.
|
||||
|
||||
| Tham số | Mặc định | Đơn vị | Mô tả |
|
||||
|---|---:|---|---|
|
||||
| `kinematics/front_axle_frame` | `steer_link` | frame | Frame tâm trục lái |
|
||||
| `kinematics/rear_axle_frame` | `base_link` | frame | Frame tâm trục sau/reference |
|
||||
| `kinematics/max_steering_angle` | `0.50` | rad | Góc lái bicycle lớn nhất khi robot đang chạy |
|
||||
| `maneuver/minimum_forward_distance` | `0.25` | m | Đoạn tiến tối thiểu trước cusp |
|
||||
| `maneuver/maximum_forward_extension` | `3.0` | m | Độ mở rộng cusp tối đa tính từ start |
|
||||
| `terminal/reverse_distance_padding` | `0.0` | m | Khoảng lùi thẳng cộng thêm ngoài robot/dock extent |
|
||||
| `sampling/path_point_spacing` | `0.05` | m | Khoảng cách lấy mẫu mục tiêu |
|
||||
| Tham số | Mặc định | Đơn vị | Model | Mô tả |
|
||||
|---|---:|---|---|---|
|
||||
| `kinematics/model` | `ackermann` | — | cả hai | `ackermann` \| `differential` |
|
||||
| `kinematics/front_axle_frame` | `steer_link` | frame | ackermann | Frame tâm trục lái |
|
||||
| `kinematics/rear_axle_frame` | `base_link` | frame | ackermann | Frame tâm trục sau |
|
||||
| `kinematics/max_steering_angle` | `0.50` | rad | ackermann | Góc lái bicycle lớn nhất |
|
||||
| `kinematics/minimum_turning_radius` | `0.0` | m | differential | 0 = xoay tại chỗ được |
|
||||
| `maneuver/minimum_forward_distance` | `0.25` | m | cả hai | Đoạn dẫn tối thiểu trước cusp |
|
||||
| `maneuver/maximum_forward_extension` | `3.0` | m | cả hai | Trần `cusp_extension`; vượt thì LOẠI kiểu 3 |
|
||||
| `maneuver/maximum_cusp_distance` | `0.0` | m | cả hai | Trần đoạn thẳng cusp → goal của `single_cusp`; 0 = không giới hạn |
|
||||
| `maneuver/direct_entry_min_curve_room` | `0.0` | m | cả hai | 0 = tắt kiểu 1 |
|
||||
| `maneuver/pivot_fallback_extension` | `0.0` | m | cả hai | 0 = tắt kiểu 2 (bỏ qua khi `turns_in_place`) |
|
||||
| `maneuver/pivot_safety_margin` | `0.15` | m | cả hai | Khe hở vòng quét khi xoay ↔ mặt dock |
|
||||
| `dock_face_offset` | unset | m | `mating_edge` | Goal lùi về mặt dock thật; hợp lệ trong `(0, 2]`, unset dùng `mating_extent` |
|
||||
| `dock_pivot_safety_margin` | unset | m | `mating_edge` | Override per-marker cho khe hở; hợp lệ trong `[0, 1]` |
|
||||
| `maneuver/pivot_backoff_max_distance` | `0.0` | m | differential | 0 = tắt back-off pivot; tối đa 3 m |
|
||||
| `maneuver/pivot_check_costmap` | `false` | bool | cả hai pivot | Kiểm tra lethal trên các đoạn thẳng và vùng xoay |
|
||||
| `terminal/reverse_distance_padding` | `0.0` | m | cả hai | Khoảng hở cộng thêm cho đoạn cuối |
|
||||
| `terminal/straight_length` | `0.0` | m | cả hai | Độ dài đoạn thẳng cuối mong muốn |
|
||||
| `dock_straight_length` | unset | m | cả hai | Override `terminal/straight_length` theo marker, hợp lệ trong `[0, 2]` |
|
||||
| `dock_maximum_cusp_distance` | unset | m | cả hai | Override trần `maneuver/maximum_cusp_distance` theo marker; 0 = không giới hạn |
|
||||
| `sampling/path_point_spacing` | `0.05` | m | cả hai | Khoảng cách lấy mẫu |
|
||||
|
||||
`wheel_base` và `minimum_turning_radius` là giá trị dẫn xuất, không khai trong
|
||||
YAML để tránh cấu hình mâu thuẫn.
|
||||
`wheel_base` không khai trong YAML: nó là giá trị đo, để tránh cấu hình mâu thuẫn.
|
||||
|
||||
Điều kiện bắt buộc:
|
||||
`footprint_dock` và `dock_anchor` cũng không khai ở đây — `move_base2` chọn theo
|
||||
từng marker rồi rót vào namespace `DockPlanner` trước khi dựng plugin.
|
||||
Hai khoá tuỳ chọn `dock_face_offset` và `dock_pivot_safety_margin` cũng nằm ở
|
||||
root của planner namespace, được `move_base2` chép riêng theo marker. Khi marker
|
||||
không khai một trong hai khoá, `move_base2` ghi YAML `null` để xoá override còn
|
||||
sót từ marker trước; DockPlanner đọc `null` như chưa khai.
|
||||
Chỉ có tác dụng khi `dock_anchor: mating_edge`. Khai với `center` hoặc `face` thì
|
||||
DockPlanner từ chối khởi động.
|
||||
`dock_straight_length` cũng là khoá tuỳ chọn ở root planner namespace, được chép
|
||||
theo marker và xoá bằng YAML `null` khi marker kế tiếp không khai. Khoá này hợp lệ
|
||||
với cả ba `dock_anchor`; nếu unset, DockPlanner dùng `terminal/straight_length`.
|
||||
Đoạn thẳng cuối được đặt theo `max(terminal floor, giá trị hiệu lực)`; tăng giá trị
|
||||
cần thêm khoảng trống từ vị trí bắt đầu và có thể đổi hình đường đi sang cusp hoặc xoay.
|
||||
`dock_maximum_cusp_distance` cũng nằm ở root planner namespace và hợp lệ với mọi
|
||||
`dock_anchor`. Thiếu hoặc YAML `null` dùng `maneuver/maximum_cusp_distance`;
|
||||
khai `0` tắt trần cho riêng marker, kể cả khi mặc định khác 0. Trần này giới hạn
|
||||
khoảng cách cusp → goal, khác với `maximum_forward_extension` chỉ giới hạn phần
|
||||
đi thêm từ vị trí xuất phát. Vượt trần thì loại `single_cusp`, thử các hình còn
|
||||
lại; nếu không có hình phù hợp thì planner báo lỗi. Giảm trần có thể tránh đoạn
|
||||
thẳng quá dài nhưng dễ thất bại hơn khi robot xuất phát xa goal.
|
||||
`dock_anchor: center` cộng nửa thân dock phía tiếp cận vào khoảng hở;
|
||||
`dock_anchor: face` bỏ qua `footprint_dock` hoàn toàn.
|
||||
`dock_anchor: mating_edge` cũng bỏ qua `footprint_dock`. Nó dành cho goal đã được tầng
|
||||
trên offset sẵn thành vị trí `base_link` lúc dock xong (ví dụ trạm sạc dò bằng lidar với
|
||||
`offset_x`): mặt dock nằm phía sau goal một khoảng `dock_face_offset`, hoặc `rear_extent`
|
||||
(lùi vào) / `front_extent` (tiến vào) nếu offset không khai. Terminal floor không còn
|
||||
ép `rear_extent`: nó dùng khoảng cách còn lại từ mặt thật tới mating edge, padding, và
|
||||
ít nhất một `path_point_spacing`. Khi `straight_length` lớn hơn floor, nó ấn định độ dài
|
||||
terminal. Công thức pivot ở trên áp dụng cho `straight_pivot_straight` và back-off pivot;
|
||||
đường direct-entry và cusp không đổi.
|
||||
|
||||
- Hai axle frame khác nhau và không rỗng.
|
||||
- `0 < max_steering_angle < pi/2`.
|
||||
- `0 < minimum_forward_distance <= maximum_forward_extension`.
|
||||
- `reverse_distance_padding >= 0`.
|
||||
- `0 < path_point_spacing <= 1.0`.
|
||||
Ví dụ KIT 0.65 × 0.69, `dock_face_offset: 0.40`,
|
||||
`dock_pivot_safety_margin: 0.10`, `straight_length: 0.2`:
|
||||
`minimum_cusp_distance = max(0.325 - 0.40, 0)`, rồi floored ở `0.05 m`;
|
||||
terminal là `0.2 m`, và `Xv = max(0.2, 0.474 - 0.40 + 0.10) = 0.2 m`.
|
||||
|
||||
Điều kiện validate:
|
||||
|
||||
- `ackermann`: hai axle frame khác nhau và không rỗng, `0 < max_steering_angle < π/2`,
|
||||
`wheel_base >= 0`.
|
||||
- `differential`: `minimum_turning_radius >= 0`.
|
||||
- Chung: `0 < minimum_forward_distance <= maximum_forward_extension`,
|
||||
`direct_entry_min_curve_room >= 0`, `pivot_fallback_extension >= 0`,
|
||||
`pivot_safety_margin >= 0`, `0 <= pivot_backoff_max_distance <= 3 m`,
|
||||
`reverse_distance_padding >= 0`,
|
||||
`straight_length >= 0`, `0 < path_point_spacing <= 1.0`.
|
||||
- Cả `dock_face_offset` và `dock_pivot_safety_margin` chỉ hợp lệ với
|
||||
`dock_anchor: mating_edge`; khai cùng `center` hoặc `face` thì DockPlanner từ
|
||||
chối khởi động. `dock_face_offset` phải hữu hạn và thuộc `(0, 2] m`, còn
|
||||
`dock_pivot_safety_margin` phải hữu hạn và thuộc `[0, 1] m`.
|
||||
- `dock_straight_length` phải hữu hạn và thuộc `[0, 2] m`, với mọi `dock_anchor`.
|
||||
- `maneuver/maximum_cusp_distance` và `dock_maximum_cusp_distance` phải hữu hạn và >= 0 m.
|
||||
|
||||
`max_steering_angle` phải là góc lái tương đương theo bicycle model, không phải
|
||||
servo tick hay góc pivot đặc biệt tại vận tốc bằng không. Giá trị mặc định chỉ
|
||||
là điểm bắt đầu cho APM; phải thay bằng số đo trên robot thật.
|
||||
servo tick hay góc pivot tại vận tốc bằng không. Giá trị mặc định chỉ là điểm
|
||||
bắt đầu; phải thay bằng số đo trên robot thật.
|
||||
|
||||
## Log
|
||||
|
||||
Mỗi lần lập plan in một dòng đủ để biết vì sao kiểu đó được chọn:
|
||||
|
||||
```text
|
||||
[dock_calc] Generated rear-edge dock path: selected_maneuver=straight_pivot_straight,
|
||||
model=ackermann, poses=70 (approach=23, terminal=48), terminal straight 2.348 m driven
|
||||
reverse, min_radius=2.4287 m, start=(long=2.800 m, lateral=0.600 m in approach frame),
|
||||
curve_room=1.950 m, cusp_extension=1.598 m (pivot threshold=1.000 m), arc_radius=inf,
|
||||
pivot_vertex=2.348 m, pivot_angle=-0.9263 rad, circumscribed_radius=1.698 m.
|
||||
```
|
||||
|
||||
Kiểu bị loại in ở mức info, không phải error — bị loại là chuyện bình thường vì
|
||||
còn kiểu khác. Chỉ khi hết kiểu mới có một dòng error liệt kê đủ số đo.
|
||||
|
||||
Dòng log footprint in mỗi lần lập plan là cố ý: footprint robot do host đẩy vào
|
||||
lúc chạy và âm thầm rơi về bản trong costmap YAML nếu host không đẩy. Hai bản
|
||||
chênh nhau hơn một mét ở đầu xe là chuyện có thật, và chênh đó dịch điểm xoay
|
||||
đúng bằng ngần ấy.
|
||||
|
||||
## Phạm vi an toàn hiện tại
|
||||
|
||||
`check_free_space`, `cost_threshold`, `allow_unknown` và
|
||||
`calib_safety_distance` không được đọc. Cung tiến có thể quét một vùng lớn phía
|
||||
trước và bên hông robot; chưa được phép coi path hợp lệ về collision chỉ vì core
|
||||
hình học trả thành công.
|
||||
`pivot_check_costmap` mặc định `false`. Khi bật, cả `straight_pivot_straight`
|
||||
và `backoff_pivot_straight` kiểm tra:
|
||||
|
||||
- Vùng tròn bán kính `circumscribed_radius + margin_eff` tại mỗi điểm
|
||||
xoay; mọi cell LETHAL giao với vùng tròn hoặc phần vùng quét ngoài bản đồ sẽ
|
||||
loại kiểu pivot.
|
||||
- Footprint đã rasterize tại mọi sample của các đoạn tiếp cận: back-off và đoạn
|
||||
thẳng từ B tới đỉnh pivot (hoặc đoạn thẳng tiếp cận của pivot cũ); cell LETHAL
|
||||
hoặc footprint đi ra ngoài bản đồ sẽ loại kiểu pivot. Bỏ qua sample bắt đầu.
|
||||
- Không kiểm tra đoạn terminal từ đỉnh pivot vào dock. Charger có thể là LETHAL
|
||||
gần điểm dừng, còn trolley có chân LETHAL sát footprint khi robot đi giữa hai
|
||||
chân; va chạm trên terminal tiếp tục thuộc trách nhiệm local planner.
|
||||
- `NO_INFORMATION` được xem là trống. Các cost khác LETHAL cũng không bị coi là
|
||||
va chạm bởi kiểm tra này.
|
||||
|
||||
`check_free_space`, `cost_threshold`, `allow_unknown` và `calib_safety_distance`
|
||||
**không được đọc**. Kiểm tra pivot không làm các path hình học khác thành path
|
||||
đã kiểm tra va chạm:
|
||||
|
||||
- `margin_eff` (override chỉ ở `mating_edge`, nếu không là `pivot_safety_margin`) chỉ chặn phía **gần dock** — bảo đảm vòng quét khi xoay
|
||||
không chạm mặt dock. Nó không biết gì về tường, kệ hay người bên cạnh.
|
||||
- Kiểu 1 và 3 không được kiểm tra costmap. Kiểu back-off có giới hạn chiều dài,
|
||||
nhưng vẫn cần đủ không gian trống phía sau robot.
|
||||
- Cung của kiểu 1 và 3 quét một vùng rộng ở hai bên hông robot.
|
||||
|
||||
Đừng thêm khoá cấu hình cho những tính năng an toàn chưa hiện thực — YAML khai
|
||||
một khoá không ai đọc thì nguy hiểm hơn là không khai.
|
||||
|
||||
@@ -1,43 +1,181 @@
|
||||
# DockPlanner: forward curve, one direction change, then reverse straight.
|
||||
# DockPlanner — global planner sinh đường vào dock.
|
||||
#
|
||||
# Collision/free-space checking is intentionally not configured here yet:
|
||||
# DockPlanner currently generates geometry only. Do not add cost_threshold,
|
||||
# allow_unknown, or check_free_space until the collision checker is implemented.
|
||||
# ĐÂY LÀ BẢN MẶC ĐỊNH ĐI KÈM GÓI. Mục đích: triển khai nhanh, copy ra là chạy
|
||||
# được, không phải ngồi dựng lại file config từ đầu. Giá trị ở đây là giá trị an
|
||||
# toàn/trung tính, KHÔNG phải giá trị đã tune cho một robot cụ thể.
|
||||
# Cây config đang chạy nằm ở move_base2/config/runtime/ và pnkx_nav_core/config/.
|
||||
# Sửa tham số ở hai cây đó thì phải đồng bộ khoá (và tài liệu) về đây.
|
||||
#
|
||||
# Bốn kiểu đường. Planner thử theo ladder cấu hình và lấy kiểu ĐẦU TIÊN dựng được; kiểu nào
|
||||
# không dựng được thì rơi xuống kiểu kế tiếp, KHÔNG bao giờ biến thành lỗi:
|
||||
# 1. direct_entry — một cung hội tụ vào trục goal rồi đi thẳng vào. Một chiều
|
||||
# chạy, không dừng, không xoay. Rẻ nhất khi chạy.
|
||||
# 2. straight_pivot_straight — một đoạn thẳng, một cú XOAY TẠI CHỖ ghi tường
|
||||
# minh vào path (một khối pose cùng vị trí, yaw tăng dần), rồi một đoạn
|
||||
# thẳng vào goal. Điểm xoay nằm GIỮA robot và dock nên KHÔNG lấn thêm một
|
||||
# mét nào, đổi lại có thêm một lần dừng để xoay.
|
||||
# 3. single_cusp — cua rời XA dock tới điểm đổi chiều (cusp) rồi lùi thẳng vào.
|
||||
# Lấn thêm chỗ về phía xa dock đúng bằng quãng phải đi ra.
|
||||
# 4. backoff_pivot_straight — chỉ cho differential, lùi/tiến thẳng theo hướng
|
||||
# thân xe hiện tại tới khi đủ chỗ xoay, rồi dùng hình học pivot ở trên.
|
||||
# Chỉ thử sau khi mọi kiểu cũ đều thất bại; mặc định bị tắt.
|
||||
# Thứ tự ưu tiên giữa 2 và 3 do `kinematics/model` và `maneuver/*` quyết định —
|
||||
# xem comment của từng khoá.
|
||||
# Đoạn cuối của cả bốn kiểu luôn THẲNG và trùng hướng yaw của goal: robot phải đạt
|
||||
# đúng hướng trước khi chui vào dock — đi cong vào gầm trolley rất dễ va.
|
||||
#
|
||||
# Mép nào của robot áp vào dock được SUY RA theo từng lần lập plan, dựa vào phía
|
||||
# robot đang đứng so với goal. Không khai báo bằng tham số:
|
||||
# robot ở phía +X của goal -> lead-in đi TIẾN, đoạn cuối đi LÙI
|
||||
# (mép sau áp dock: càng nâng chui vào pallet)
|
||||
# robot ở phía -X của goal -> lead-in đi LÙI, đoạn cuối đi TIẾN
|
||||
# (mép trước áp dock: chấu sạc ở đầu xe)
|
||||
# Suy được như vậy vì goal đã được offset sẵn từ tầng trên, sao cho base_link
|
||||
# dừng đúng tại goal khi manơ hoàn tất.
|
||||
#
|
||||
# Kiểm tra costmap chỉ áp dụng cho các kiểu pivot khi bật `pivot_check_costmap`;
|
||||
# các kiểu direct_entry và single_cusp vẫn chỉ kiểm tra hình học.
|
||||
DockPlanner:
|
||||
# Boost.DLL library containing the exported symbol "DockPlanner".
|
||||
# Thư viện Boost.DLL chứa symbol export tên "DockPlanner".
|
||||
library_path: libdock_planner
|
||||
|
||||
# ══════════════════════════════════════════════════════════════════════════════
|
||||
# ĐỘNG HỌC — khoá nào có tác dụng phụ thuộc `model`. Khoá của model KIA được
|
||||
# đọc vào nhưng KHÔNG dùng và KHÔNG kiểm tra, nên để lại giá trị cũ vô hại.
|
||||
#
|
||||
# khoá ackermann differential
|
||||
# ───────────────────────────── ─────────── ────────────
|
||||
# front_axle_frame DÙNG bỏ qua
|
||||
# rear_axle_frame DÙNG bỏ qua
|
||||
# max_steering_angle DÙNG bỏ qua
|
||||
# minimum_turning_radius bỏ qua DÙNG
|
||||
# ══════════════════════════════════════════════════════════════════════════════
|
||||
kinematics:
|
||||
# Axle frames used to measure wheel_base from TF, matching StanleyControl.
|
||||
# Mô hình dẫn động. Quyết định planner ĐO hay ĐỌC bán kính cua nhỏ nhất, và
|
||||
# robot có được xoay tại chỗ hay không.
|
||||
# ackermann — có trục lái. R_min được ĐO: wheel_base lấy từ TF hai frame
|
||||
# trục bánh, chia cho tan(max_steering_angle). Robot không
|
||||
# đổi được hướng nếu không di chuyển.
|
||||
# differential — hai bánh chủ động độc lập. KHÔNG có trục lái nên KHÔNG tra
|
||||
# TF trục bánh. R_min ĐỌC thẳng từ minimum_turning_radius.
|
||||
# ► Chỉnh: để nhầm `ackermann` cho robot vi sai thì plugin KHÔNG NẠP ĐƯỢC —
|
||||
# nó đi tra frame `steer_link` mà robot vi sai không hề có.
|
||||
model: ackermann
|
||||
|
||||
# ── chỉ có tác dụng khi model: ackermann ─────────────────────────────────────
|
||||
|
||||
# Hai frame trục bánh, dùng để ĐO wheel_base từ TF. Phải trùng cặp frame
|
||||
# StanleyControl đang dùng, lệch là bán kính cua tính ra sai.
|
||||
front_axle_frame: "steer_link"
|
||||
rear_axle_frame: "base_link"
|
||||
|
||||
# [rad] Maximum equivalent bicycle steering angle while driving the
|
||||
# approach curve. Measure this on the real robot; this is not a servo tick,
|
||||
# steering-wheel angle, or the special standstill-pivot angle.
|
||||
max_steering_angle: 0.50
|
||||
# [rad] Góc lái lớn nhất của mô hình xe đạp tương đương khi đang chạy.
|
||||
# PHẢI đo trên robot thật. KHÔNG phải tick servo, KHÔNG phải góc vô lăng,
|
||||
# cũng KHÔNG phải góc pivot tại chỗ.
|
||||
# R_min = wheel_base / tan(góc này).
|
||||
# Khai lớn hơn thực tế -> sinh cung robot bám không nổi, robot lệch path.
|
||||
# Khai nhỏ hơn thực tế -> đường vòng rộng, tốn không gian.
|
||||
max_steering_angle: 0.5
|
||||
|
||||
# ── chỉ có tác dụng khi model: differential ──────────────────────────────────
|
||||
|
||||
# [m] Bán kính cua nhỏ nhất, khai trực tiếp vì robot vi sai không có góc lái.
|
||||
# 0 — CHO PHÉP xoay tại chỗ. Đây là giá trị bình thường của robot vi sai,
|
||||
# và nó bật kiểu đường 2 (thẳng + xoay + thẳng) làm kiểu CHÍNH: kiểu
|
||||
# này không lấn thêm một mét nào về phía xa dock.
|
||||
# > 0 — CẤM xoay tại chỗ (ví dụ đang chở tải cao, xoay tại chỗ dễ đổ).
|
||||
# Planner quay về dùng cung y như ackermann, bán kính tối thiểu đúng
|
||||
# bằng số này, và kiểu 2 chỉ còn bật qua pivot_fallback_extension.
|
||||
minimum_turning_radius: 0.0
|
||||
|
||||
maneuver:
|
||||
# [m] The cusp is placed at least this far forward from the start. This
|
||||
# guarantees a real forward leg before the reverse terminal segment.
|
||||
# [m] Cusp đặt cách điểm xuất phát ít nhất khoảng này, đo theo hướng RỜI XA
|
||||
# dock. Bảo đảm luôn có đoạn lead-in thật trước khi đổi chiều, thay vì cusp
|
||||
# trùng ngay vị trí robot.
|
||||
minimum_forward_distance: 0.25
|
||||
|
||||
# [m] Reject a maneuver that has to extend farther than this from the start
|
||||
# to satisfy the turning-radius and dock-clearance constraints.
|
||||
# [m] Cusp phải nằm xa hơn khoảng này so với điểm xuất phát thì kiểu 3 bị
|
||||
# LOẠI (không phải fail): planner chuyển sang kiểu khác, chỉ khi không kiểu
|
||||
# nào dựng được mới trả lỗi.
|
||||
# Tăng lên nếu robot đứng lệch nhiều mà vẫn muốn giữ đường có cusp; giảm
|
||||
# xuống để đẩy sớm sang kiểu 2.
|
||||
maximum_forward_extension: 3.0
|
||||
|
||||
# [m] Trần đoạn thẳng từ cusp tới goal của single_cusp (khoảng xuất phát dọc trục + phần tiến thêm).
|
||||
# 0 = không giới hạn; vượt trần thì bỏ hình cusp và thử hình xoay, hết hình khả dụng thì báo fail.
|
||||
# Giảm giúp tránh lùi thẳng quá dài nhưng dễ fail khi robot xuất phát xa goal.
|
||||
# Marker có thể ghi đè bằng dock_maximum_cusp_distance trong maker_sources.yaml.
|
||||
maximum_cusp_distance: 0.0
|
||||
|
||||
# [m] Bật kiểu 1 (direct_entry — một cung hội tụ vào trục goal rồi đi thẳng
|
||||
# vào, giữ nguyên một chiều chạy) khi khoảng chỗ còn lại cho cung — khoảng
|
||||
# cách dọc trục từ robot tới goal trừ độ dài đoạn thẳng cuối — vượt số này.
|
||||
# Bán kính cung VẪN bị kiểm với R_min. Trượt phép kiểm nào thì rơi xuống
|
||||
# kiểu sau, nên khoá này chỉ có thể BỚT một lần đổi chiều, không bao giờ thêm.
|
||||
# 0 = tắt hẳn kiểu 1.
|
||||
direct_entry_min_curve_room: 0.0
|
||||
|
||||
# [m] Chuyển từ kiểu 3 (cusp) sang kiểu 2 (thẳng + xoay + thẳng) khi cusp bắt
|
||||
# robot chạy RA XA dock thêm quá số này, đo từ chỗ robot ĐANG ĐỨNG.
|
||||
# So sánh cố ý là TƯƠNG ĐỐI. Lấy một con số tuyệt đối kiểu "chiều sâu lối đi"
|
||||
# rồi so với vị trí robot là tính cả chỗ robot đang đứng vào phần "cần thêm",
|
||||
# và mọi manơ xuất phát từ khoảng cách bình thường đều bị loại sạch.
|
||||
# 0 — TẮT hẳn chuyển sang kiểu 2 (hành vi cũ, ưu tiên đường cusp).
|
||||
# nhỏ hơn — chuyển sang xoay tại chỗ sớm hơn: tiết kiệm lối đi, thêm 1 lần dừng.
|
||||
# lớn hơn — ưu tiên cusp: chạy mượt hơn, chiếm nhiều lối đi hơn.
|
||||
# ⚠ Chỉ khai > 0 khi CHẮC robot xoay tại chỗ được quanh base_link.
|
||||
# KHÔNG có tác dụng khi model=differential VÀ minimum_turning_radius=0 — lúc
|
||||
# đó kiểu 2 đã là kiểu chính rồi, không cần ngưỡng nào bật nó.
|
||||
pivot_fallback_extension: 0.0
|
||||
|
||||
# [m] Khoảng hở giữa vòng tròn thân robot quét khi xoay tại chỗ và mặt gần
|
||||
# của dock. Áp dụng cho CẢ HAI model, mỗi khi kiểu 2 được dùng.
|
||||
# Xoay tại chỗ quay MỌI điểm footprint quanh base_link, nên kích thước phải
|
||||
# tính là BÁN KÍNH NGOẠI TIẾP, luôn lớn hơn phần nhô mép dùng cho đoạn thẳng
|
||||
# cuối. Ví dụ footprint 1.65/0.35 x ±0.40: ngoại tiếp 1.698 m trong khi mép
|
||||
# sau chỉ 0.35 m — chênh 1.35 m.
|
||||
# Điểm xoay đặt tại: max(độ dài đoạn thẳng cuối, ngoại tiếp + nửa thân dock
|
||||
# phía tiếp cận + số này).
|
||||
# Tăng lên: điểm xoay lùi ra xa dock hơn, an toàn hơn. Tăng quá thì điểm xoay
|
||||
# vượt qua chỗ robot đứng, kiểu 2 bị loại và planner quay về cusp.
|
||||
pivot_safety_margin: 0.15
|
||||
|
||||
# [m] Quãng back-off tối đa cho kiểu backoff_pivot_straight cuối cùng, chỉ dùng khi model=differential.
|
||||
# Tăng lên cho phép cứu robot đang đứng gần điểm xoay; giảm xuống hoặc 0 sẽ làm ít trường hợp được cứu hơn.
|
||||
# ⚠ Đặt quá lớn có thể lấn vào lối đi phía sau robot.
|
||||
pivot_backoff_max_distance: 0.0
|
||||
|
||||
# Bật kiểm tra LETHAL trên các đoạn tiếp cận (back-off, tới đỉnh pivot) và vòng quét tại điểm xoay.
|
||||
# Không kiểm tra terminal vào dock: cell LETHAL gần charger/chân trolley có thể là tiếp xúc dự kiến.
|
||||
# NO_INFORMATION được xem là trống; LETHAL và ngoài bản đồ chặn các phần được kiểm tra.
|
||||
# false bỏ qua vật cản costmap, có thể sinh đường đâm vào chướng ngại vật.
|
||||
pivot_check_costmap: false
|
||||
|
||||
terminal:
|
||||
# [m] Extra reverse-straight distance beyond the robot rear extent and, for
|
||||
# dock_anchor=center, the dock near-face extent.
|
||||
# [m] Khoảng hở CỘNG THÊM cho đoạn thẳng cuối, ngoài phần thân robot nhô ra ở
|
||||
# mép áp dock (rear_extent khi đoạn cuối đi lùi, front_extent khi đi tiến) và,
|
||||
# nếu dock_anchor=center, ngoài nửa thân dock phía tiếp cận.
|
||||
# Tăng lên nếu thấy robot dừng quá sát dock.
|
||||
reverse_distance_padding: 0.0
|
||||
|
||||
# [m] Độ dài đoạn thẳng cuối MONG MUỐN. Giá trị thực tế là
|
||||
# max(giá trị này, phần nhô mép áp dock + nửa thân dock + padding), nên đặt 0
|
||||
# là chỉ dùng khoảng hở tối thiểu.
|
||||
# Tăng lên thì robot có quãng thẳng dài hơn để chỉnh hết sai số hướng trước
|
||||
# khi vào dock, ĐỔI LẠI ăn vào chỗ dành cho cung, nên đặt lớn quá sẽ đẩy plan
|
||||
# sang kiểu có cusp hoặc kiểu xoay tại chỗ.
|
||||
# Với mating_edge + dock_face_offset, terminal floor không còn là rear_extent nên straight_length (ví dụ 0.2 m) quyết định độ dài terminal.
|
||||
# Marker có thể ghi đè bằng dock_straight_length trong maker_sources.yaml.
|
||||
straight_length: 0.0
|
||||
|
||||
sampling:
|
||||
# [m] Maximum target spacing along both the forward arc and reverse line.
|
||||
# [m] Khoảng cách lớn nhất giữa hai điểm liên tiếp trên đường, áp dụng cho cả
|
||||
# đoạn cung lẫn đoạn thẳng. Nhỏ hơn = đường mượt hơn nhưng nhiều điểm hơn.
|
||||
path_point_spacing: 0.05
|
||||
|
||||
# footprint_dock and dock_anchor are selected per marker by move_base2 and
|
||||
# copied into this namespace before the plugin is constructed.
|
||||
# footprint_dock và dock_anchor KHÔNG khai ở đây. move_base2 chọn theo từng
|
||||
# marker rồi rót vào namespace này trước khi khởi tạo plugin.
|
||||
#
|
||||
# dock_anchor: 'center' (default) — goal is the dock footprint center; the
|
||||
# near-face extent of footprint_dock contributes to cusp clearance.
|
||||
# 'face' — goal already sits on the approach face; footprint_dock is ignored.
|
||||
# dock_anchor: 'center' (mặc định) — goal nằm ở tâm dock; nửa thân dock phía
|
||||
# tiếp cận (lấy từ footprint_dock) được cộng vào khoảng hở cusp.
|
||||
# 'face' — goal đã nằm sẵn trên mặt tiếp cận; footprint_dock bị bỏ qua.
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#ifndef DOCK_PLANNER_DOCK_CALC_H_
|
||||
#define DOCK_PLANNER_DOCK_CALC_H_
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <robot_geometry_msgs/PoseStamped.h>
|
||||
@@ -20,18 +22,30 @@ struct RobotGeometry
|
||||
// bounding-box center — e.g. a forklift whose forks extend past base_link.
|
||||
double front_extent = 0.0; // [m], origin to the +X edge
|
||||
double rear_extent = 0.0; // [m], origin to the -X edge
|
||||
// Farthest footprint vertex from the frame origin. This is the radius the
|
||||
// body sweeps when it turns on the spot, so it -- not front_extent or
|
||||
// rear_extent -- is what has to clear the dock at a pivot vertex. It is
|
||||
// always the larger of the two for any footprint that has width.
|
||||
double circumscribed_radius = 0.0; // [m]
|
||||
};
|
||||
|
||||
/** Pure docking-path geometry. Collision checking is intentionally out of scope. */
|
||||
/** Docking geometry with optional external checks; this class stays costmap-agnostic. */
|
||||
class DockCalc
|
||||
{
|
||||
public:
|
||||
using RotationClear = std::function<bool(const robot_geometry_msgs::Pose&, double)>;
|
||||
using FootprintClear = std::function<bool(const robot_geometry_msgs::Pose&)>;
|
||||
|
||||
DockCalc();
|
||||
explicit DockCalc(const DockPlannerConfig& config);
|
||||
~DockCalc();
|
||||
|
||||
void setConfig(const DockPlannerConfig& config);
|
||||
|
||||
/** Install optional costmap-backed checks without adding costmap types to this geometry class. */
|
||||
void setCostmapCheckCallbacks(RotationClear rotation_clear,
|
||||
FootprintClear footprint_clear);
|
||||
|
||||
bool makePlanMoveToDock(
|
||||
const robot_geometry_msgs::PoseStamped& start,
|
||||
const robot_geometry_msgs::PoseStamped& goal,
|
||||
@@ -41,6 +55,8 @@ public:
|
||||
|
||||
private:
|
||||
DockPlannerConfig config_;
|
||||
RotationClear rotation_clear_;
|
||||
FootprintClear footprint_clear_;
|
||||
std::mutex calculation_mutex_;
|
||||
|
||||
static double distance(const robot_geometry_msgs::Pose& first,
|
||||
@@ -64,10 +80,54 @@ private:
|
||||
const robot_geometry_msgs::Pose& goal,
|
||||
double approach_yaw, double heading_offset,
|
||||
double start_longitudinal,
|
||||
double start_lateral, double minimum_cusp_distance,
|
||||
double start_lateral, double cusp_distance,
|
||||
double minimum_turning_radius,
|
||||
std::vector<robot_geometry_msgs::Pose>& path,
|
||||
double& cusp_distance, double& curve_radius) const;
|
||||
double& curve_radius) const;
|
||||
|
||||
/**
|
||||
* @brief Where the cusp has to sit, without sampling anything.
|
||||
*
|
||||
* Split out of sampleLeadIn so the caller can compare the cost of the
|
||||
* single-cusp shape against the other shapes BEFORE committing to it.
|
||||
* @p extension is how much further away from the dock the cusp pushes the
|
||||
* robot, measured from where it already stands, and is the quantity the
|
||||
* pivot fallback threshold is compared against.
|
||||
*
|
||||
* Returns false when that extension leaves (0, maximum_forward_extension],
|
||||
* which is a normal outcome: the caller then plans another shape.
|
||||
*/
|
||||
bool cuspPlacement(double start_longitudinal, double start_lateral,
|
||||
double minimum_cusp_distance,
|
||||
double minimum_turning_radius,
|
||||
double& cusp_distance, double& extension) const;
|
||||
|
||||
/**
|
||||
* @brief Straight leg to a vertex on the goal axis, then an explicit
|
||||
* on-the-spot rotation onto the terminal heading.
|
||||
*
|
||||
* The vertex sits BETWEEN the robot and the dock, so this shape never
|
||||
* claims space further from the dock than the robot already occupies --
|
||||
* that is the whole reason it exists. @p vertex_distance must already
|
||||
* include the clearance the swept circle needs; see makePlanMoveToDock.
|
||||
*
|
||||
* The rotation is written into the path as a block of poses that share a
|
||||
* position and step in yaw, because an Ackermann or differential base
|
||||
* cannot change heading instantly at a bare polyline vertex. The block is
|
||||
* emitted with push_back rather than appendUnique, which would drop every
|
||||
* pose in it for not moving.
|
||||
*
|
||||
* Returns false when the vertex is not ahead of the robot or the leg is too
|
||||
* short to sample; the caller then plans another shape.
|
||||
*/
|
||||
bool samplePivotPolyline(const robot_geometry_msgs::Pose& start,
|
||||
const robot_geometry_msgs::Pose& goal,
|
||||
double approach_yaw, double heading_offset,
|
||||
double start_longitudinal, double start_lateral,
|
||||
double vertex_distance,
|
||||
std::vector<robot_geometry_msgs::Pose>& path,
|
||||
double& pivot_angle,
|
||||
bool allow_one_spacing_leg = false) const;
|
||||
|
||||
/**
|
||||
* @brief No-cusp entry: one arc that converges onto the goal axis, then the
|
||||
@@ -92,6 +152,10 @@ private:
|
||||
const robot_geometry_msgs::Pose& goal,
|
||||
double goal_yaw,
|
||||
std::vector<robot_geometry_msgs::Pose>& path) const;
|
||||
|
||||
bool checkPivotPathCostmap(const std::vector<robot_geometry_msgs::Pose>& path,
|
||||
double rotation_radius, bool skip_start_pose,
|
||||
std::string& reason) const;
|
||||
};
|
||||
|
||||
} // namespace dock_planner
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <robot_nav_core/base_global_planner.h>
|
||||
#include <robot_costmap_2d/costmap_2d.h>
|
||||
|
||||
#include "dock_planner/dock_calc.h"
|
||||
#include "dock_planner/dock_planner_config.h"
|
||||
@@ -27,10 +28,15 @@ public:
|
||||
static robot_nav_core::BaseGlobalPlanner::Ptr create();
|
||||
|
||||
private:
|
||||
bool rotationClear(const robot_geometry_msgs::Pose& pose, double radius) const;
|
||||
bool footprintClear(const robot_geometry_msgs::Pose& pose);
|
||||
|
||||
robot_costmap_2d::Costmap2DROBOT* costmap_robot_ = nullptr; // non-owning
|
||||
bool initialized_ = false;
|
||||
std::string global_frame_;
|
||||
std::vector<robot_geometry_msgs::Point> footprint_dock_;
|
||||
std::vector<robot_costmap_2d::MapLocation> footprint_map_polygon_;
|
||||
std::vector<robot_costmap_2d::MapLocation> footprint_map_cells_;
|
||||
DockCalc dock_calc_;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef DOCK_PLANNER_DOCK_PLANNER_CONFIG_H_
|
||||
#define DOCK_PLANNER_DOCK_PLANNER_CONFIG_H_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include <robot/node_handle.h>
|
||||
@@ -18,35 +19,77 @@ inline constexpr double kPi = 3.14159265358979323846;
|
||||
* footprint_dock is added to the approach distance.
|
||||
* kFace: goal is already on the approach face; footprint_dock does not
|
||||
* contribute to the approach distance and is ignored entirely.
|
||||
* kMatingEdge: goal is the docked base_link pose, already offset upstream
|
||||
* (e.g. by the detector). Same as kFace, except that the on-the-spot pivot
|
||||
* clearance is measured from the real dock face, dock_face_offset behind the
|
||||
* goal (or mating_extent when the optional offset is unset), instead of from
|
||||
* the goal.
|
||||
* footprint_dock is ignored.
|
||||
*/
|
||||
enum class DockAnchor
|
||||
{
|
||||
kCenter,
|
||||
kFace,
|
||||
kMatingEdge,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Drive kinematics the path geometry has to respect.
|
||||
*
|
||||
* kAckermann: steered front axle. The minimum turning radius is measured, not
|
||||
* declared -- wheel_base comes from the axle TF and is combined with
|
||||
* max_steering_angle. The robot cannot change heading without moving.
|
||||
* kDifferential: independently driven wheels. There is no steered axle and no
|
||||
* axle TF to look up, so the minimum turning radius is declared directly and is
|
||||
* normally 0, meaning the robot can turn on the spot.
|
||||
*/
|
||||
enum class KinematicModel
|
||||
{
|
||||
kAckermann,
|
||||
kDifferential,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Runtime parameters that materially affect the docking path geometry.
|
||||
*
|
||||
* Collision checking is intentionally not part of this contract yet. Adding a
|
||||
* parameter for an unimplemented safety feature would make the YAML misleading.
|
||||
* Costmap checking is opt-in and applies only to pivot maneuvers.
|
||||
*/
|
||||
struct DockPlannerConfig
|
||||
{
|
||||
/**
|
||||
* Default kAckermann so an existing YAML that never heard of this key keeps
|
||||
* behaving exactly as before.
|
||||
*/
|
||||
KinematicModel kinematic_model = KinematicModel::kAckermann;
|
||||
|
||||
// Ackermann only. A differential base has no steered axle, so these are
|
||||
// neither read nor validated when kinematic_model is kDifferential.
|
||||
std::string front_axle_frame = "steer_link";
|
||||
std::string rear_axle_frame = "base_link";
|
||||
double max_steering_angle = 0.50; // [rad], equivalent bicycle steering angle
|
||||
double wheel_base = 0.0; // [m], resolved from axle TF by DockPlanner
|
||||
|
||||
/**
|
||||
* [m] Differential only. 0 means the base may turn on the spot, which is the
|
||||
* normal case and unlocks the straight-pivot-straight shape as the primary
|
||||
* maneuver. Set it above 0 to forbid on-the-spot turns -- for instance while
|
||||
* carrying a tall load -- and the planner falls back to the same arc-based
|
||||
* shapes an Ackermann base uses.
|
||||
*/
|
||||
double minimum_turning_radius = 0.0;
|
||||
|
||||
double reverse_distance_padding = 0.0; // [m], additional cusp clearance from dock
|
||||
double minimum_forward_distance = 0.25; // [m], guarantees a forward leg before reversing
|
||||
double maximum_forward_extension = 3.0; // [m], rejects unexpectedly large maneuvers
|
||||
/** [m] Maximum single-cusp terminal length; 0 disables the cap. */
|
||||
double maximum_cusp_distance = 0.0;
|
||||
double path_point_spacing = 0.05; // [m]
|
||||
|
||||
/**
|
||||
* [m] Requested length of the straight terminal leg. The effective length is
|
||||
* max(straight_length, mating robot extent + dock near extent + padding), so
|
||||
* 0 keeps the clearance-only behaviour.
|
||||
* max(straight_length, terminal clearance floor), so 0 keeps the
|
||||
* clearance-only behaviour. For mating_edge, the floor accounts for any
|
||||
* remaining gap between dock_face_offset and the robot's mating extent.
|
||||
*/
|
||||
double straight_length = 0.0;
|
||||
|
||||
@@ -59,6 +102,51 @@ struct DockPlannerConfig
|
||||
*/
|
||||
double direct_entry_min_curve_room = 0.0;
|
||||
|
||||
/**
|
||||
* [m] Ackermann only. Switch from the single-cusp shape to
|
||||
* straight-pivot-straight once the cusp forces the robot this much further
|
||||
* AWAY from the dock than where it already stands. The comparison is
|
||||
* deliberately relative to the robot's current standoff: an absolute aisle
|
||||
* measurement counts space the robot already occupies and rejects every
|
||||
* maneuver planned from a normal approach distance.
|
||||
* 0 disables the shape entirely and always plans a cusp.
|
||||
* Ignored when kinematic_model is kDifferential, where the pivot shape is
|
||||
* the primary maneuver rather than a fallback.
|
||||
*/
|
||||
double pivot_fallback_extension = 0.0;
|
||||
|
||||
/**
|
||||
* [m] Clearance kept between the circle the body sweeps while it turns on
|
||||
* the spot and the near face of the dock. Turning on the spot rotates every
|
||||
* footprint point about base_link, so the relevant robot dimension is the
|
||||
* circumscribed radius, which is always larger than the mating extent the
|
||||
* straight terminal is sized from. This margin pushes the pivot vertex that
|
||||
* much further away from the dock.
|
||||
*/
|
||||
double pivot_safety_margin = 0.15;
|
||||
|
||||
/**
|
||||
* [m] Optional per-marker distance from the mating_edge goal back to the
|
||||
* real dock face. Unset uses the robot mating extent; only valid for
|
||||
* DockAnchor::kMatingEdge.
|
||||
*/
|
||||
std::optional<double> dock_face_offset = std::nullopt;
|
||||
|
||||
/** [m] Optional per-marker override for pivot_safety_margin. */
|
||||
std::optional<double> dock_pivot_safety_margin = std::nullopt;
|
||||
|
||||
/** [m] Per-marker override for terminal/straight_length; null means unset. */
|
||||
std::optional<double> dock_straight_length = std::nullopt;
|
||||
|
||||
/** [m] Per-marker override for maneuver/maximum_cusp_distance; null means unset. */
|
||||
std::optional<double> dock_maximum_cusp_distance = std::nullopt;
|
||||
|
||||
/** [m] Maximum straight back-off distance for the differential-only last-resort pivot. 0 disables it. */
|
||||
double pivot_backoff_max_distance = 0.0;
|
||||
|
||||
/** Check pivot rotations and straight legs against lethal costmap cells. */
|
||||
bool pivot_check_costmap = false;
|
||||
|
||||
/**
|
||||
* Per-marker key copied down by move_base2 (like footprint_dock).
|
||||
* Default kCenter keeps the legacy formula for existing profiles.
|
||||
@@ -71,8 +159,19 @@ struct DockPlannerConfig
|
||||
/** Validate values supplied directly by tests or another non-YAML adapter. */
|
||||
bool validate(std::string& error) const;
|
||||
|
||||
/** Radius at the rear-axle reference point for the bicycle model. */
|
||||
/**
|
||||
* Smallest radius the path geometry may use, in metres.
|
||||
* Ackermann: derived from the measured wheel base and the steering limit.
|
||||
* Differential: the declared value, 0 when turning on the spot is allowed.
|
||||
* NaN when the model's inputs are unusable.
|
||||
*/
|
||||
double minimumTurningRadius() const;
|
||||
|
||||
/** True when the model needs the axle TF resolved before planning. */
|
||||
bool requiresAxleTf() const
|
||||
{
|
||||
return kinematic_model == KinematicModel::kAckermann;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dock_planner
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <data_convert/data_convert.h>
|
||||
#include <robot/robot.h>
|
||||
@@ -15,6 +16,45 @@ namespace
|
||||
|
||||
constexpr double kEpsilon = 1e-9;
|
||||
|
||||
/**
|
||||
* Poses appended after the vertex to describe the on-the-spot rotation.
|
||||
* StanleyControl::planDivision only splits a rotation out of the plan after
|
||||
* three consecutive samples that share a position, so the block needs at least
|
||||
* four poses counting the vertex itself; six keeps margin for any consumer that
|
||||
* counts differently.
|
||||
*/
|
||||
constexpr int kPivotBlockSteps = 6;
|
||||
|
||||
/** Below this the robot is already on the terminal heading. [rad] */
|
||||
constexpr double kNegligiblePivot = 1e-6;
|
||||
|
||||
/** Path shapes the planner can produce, in no particular order. */
|
||||
enum class Shape
|
||||
{
|
||||
kNone,
|
||||
kDirectEntry,
|
||||
kPivot,
|
||||
kCusp,
|
||||
kBackoffPivot,
|
||||
};
|
||||
|
||||
const char* shapeName(Shape shape)
|
||||
{
|
||||
switch (shape)
|
||||
{
|
||||
case Shape::kDirectEntry:
|
||||
return "direct_entry";
|
||||
case Shape::kPivot:
|
||||
return "straight_pivot_straight";
|
||||
case Shape::kCusp:
|
||||
return "single_cusp";
|
||||
case Shape::kBackoffPivot:
|
||||
return "backoff_pivot_straight";
|
||||
default:
|
||||
return "none";
|
||||
}
|
||||
}
|
||||
|
||||
bool finitePoint(const robot_geometry_msgs::Point& point)
|
||||
{
|
||||
return std::isfinite(point.x) && std::isfinite(point.y) && std::isfinite(point.z);
|
||||
@@ -69,6 +109,14 @@ void DockCalc::setConfig(const DockPlannerConfig& config)
|
||||
config_ = config;
|
||||
}
|
||||
|
||||
void DockCalc::setCostmapCheckCallbacks(RotationClear rotation_clear,
|
||||
FootprintClear footprint_clear)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(calculation_mutex_);
|
||||
rotation_clear_ = std::move(rotation_clear);
|
||||
footprint_clear_ = std::move(footprint_clear);
|
||||
}
|
||||
|
||||
double DockCalc::distance(const robot_geometry_msgs::Pose& first,
|
||||
const robot_geometry_msgs::Pose& second)
|
||||
{
|
||||
@@ -105,6 +153,7 @@ RobotGeometry DockCalc::computeGeometry(
|
||||
double max_x = std::numeric_limits<double>::lowest();
|
||||
double min_y = std::numeric_limits<double>::max();
|
||||
double max_y = std::numeric_limits<double>::lowest();
|
||||
double max_radius = 0.0;
|
||||
|
||||
for (const auto& point : footprint)
|
||||
{
|
||||
@@ -116,6 +165,10 @@ RobotGeometry DockCalc::computeGeometry(
|
||||
max_x = std::max(max_x, point.x);
|
||||
min_y = std::min(min_y, point.y);
|
||||
max_y = std::max(max_y, point.y);
|
||||
// Distance is convex, so its maximum over a polygon is always attained
|
||||
// at a vertex -- true even for a concave footprint. Scanning the
|
||||
// vertices is therefore exact, not an approximation.
|
||||
max_radius = std::max(max_radius, std::hypot(point.x, point.y));
|
||||
}
|
||||
|
||||
RobotGeometry geometry;
|
||||
@@ -123,6 +176,7 @@ RobotGeometry DockCalc::computeGeometry(
|
||||
geometry.width = max_y - min_y;
|
||||
geometry.front_extent = max_x;
|
||||
geometry.rear_extent = -min_x;
|
||||
geometry.circumscribed_radius = max_radius;
|
||||
return geometry;
|
||||
}
|
||||
|
||||
@@ -142,44 +196,20 @@ bool DockCalc::sampleLeadIn(
|
||||
double heading_offset,
|
||||
double start_longitudinal,
|
||||
double start_lateral,
|
||||
double minimum_cusp_distance,
|
||||
double cusp_distance,
|
||||
double minimum_turning_radius,
|
||||
std::vector<robot_geometry_msgs::Pose>& path,
|
||||
double& cusp_distance,
|
||||
double& curve_radius) const
|
||||
{
|
||||
path.clear();
|
||||
cusp_distance = std::numeric_limits<double>::quiet_NaN();
|
||||
curve_radius = std::numeric_limits<double>::infinity();
|
||||
|
||||
const double lateral = std::fabs(start_lateral);
|
||||
double forward_extension = config_.minimum_forward_distance;
|
||||
|
||||
// A circle tangent to the dock axis at the cusp and passing through the
|
||||
// start has R = (dx^2 + lateral^2) / (2*lateral). Select the smallest dx
|
||||
// that guarantees R >= the Ackermann limit. If lateral >= 2*R_min, the
|
||||
// lateral offset alone already makes the circle conservative enough.
|
||||
if (lateral > kEpsilon)
|
||||
{
|
||||
const double radicand = 2.0 * minimum_turning_radius * lateral -
|
||||
lateral * lateral;
|
||||
if (radicand > 0.0)
|
||||
{
|
||||
forward_extension = std::max(forward_extension, std::sqrt(radicand));
|
||||
}
|
||||
}
|
||||
|
||||
cusp_distance = std::max(minimum_cusp_distance,
|
||||
start_longitudinal + forward_extension);
|
||||
// Where the cusp goes is decided by cuspPlacement() before any shape is
|
||||
// sampled, so this function only has to honour it.
|
||||
const double actual_extension = cusp_distance - start_longitudinal;
|
||||
if (!std::isfinite(actual_extension) || actual_extension <= kEpsilon ||
|
||||
actual_extension > config_.maximum_forward_extension + kEpsilon)
|
||||
if (!std::isfinite(actual_extension) || actual_extension <= kEpsilon)
|
||||
{
|
||||
robot::log_error(
|
||||
"[dock_calc] Lead-in cusp extension %.3f m is outside (0, %.3f] m "
|
||||
"(start_longitudinal=%.3f m, minimum_cusp=%.3f m).\n",
|
||||
actual_extension, config_.maximum_forward_extension,
|
||||
start_longitudinal, minimum_cusp_distance);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -267,6 +297,170 @@ bool DockCalc::sampleLeadIn(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DockCalc::cuspPlacement(double start_longitudinal, double start_lateral,
|
||||
double minimum_cusp_distance,
|
||||
double minimum_turning_radius,
|
||||
double& cusp_distance, double& extension) const
|
||||
{
|
||||
cusp_distance = std::numeric_limits<double>::quiet_NaN();
|
||||
extension = std::numeric_limits<double>::quiet_NaN();
|
||||
|
||||
const double lateral = std::fabs(start_lateral);
|
||||
double forward_extension = config_.minimum_forward_distance;
|
||||
|
||||
// A circle tangent to the dock axis at the cusp and passing through the
|
||||
// start has R = (dx^2 + lateral^2) / (2*lateral). Select the smallest dx
|
||||
// that guarantees R >= the steering limit. If lateral >= 2*R_min, the
|
||||
// lateral offset alone already makes the circle conservative enough, and a
|
||||
// differential base with R_min = 0 never needs any extra dx at all.
|
||||
if (lateral > kEpsilon)
|
||||
{
|
||||
const double radicand = 2.0 * minimum_turning_radius * lateral -
|
||||
lateral * lateral;
|
||||
if (radicand > 0.0)
|
||||
{
|
||||
forward_extension = std::max(forward_extension, std::sqrt(radicand));
|
||||
}
|
||||
}
|
||||
|
||||
const double placed = std::max(minimum_cusp_distance,
|
||||
start_longitudinal + forward_extension);
|
||||
const double actual_extension = placed - start_longitudinal;
|
||||
if (!std::isfinite(actual_extension) || actual_extension <= kEpsilon ||
|
||||
actual_extension > config_.maximum_forward_extension + kEpsilon)
|
||||
{
|
||||
// Informational, not an error: another shape may still be planned. The
|
||||
// caller logs an error only if every shape is exhausted.
|
||||
robot::log_info(
|
||||
"[dock_calc] Single-cusp extension %.3f m is outside (0, %.3f] m "
|
||||
"(start_longitudinal=%.3f m, minimum_cusp=%.3f m); trying another shape.\n",
|
||||
actual_extension, config_.maximum_forward_extension,
|
||||
start_longitudinal, minimum_cusp_distance);
|
||||
return false;
|
||||
}
|
||||
|
||||
const double effective_maximum_cusp_distance =
|
||||
config_.dock_maximum_cusp_distance.value_or(config_.maximum_cusp_distance);
|
||||
if (effective_maximum_cusp_distance > 0.0 && placed > effective_maximum_cusp_distance)
|
||||
{
|
||||
robot::log_info(
|
||||
"[dock_calc] Single-cusp distance %.3f m exceeds cap %.3f m "
|
||||
"(source=%s); trying another shape.\n",
|
||||
placed, effective_maximum_cusp_distance,
|
||||
config_.dock_maximum_cusp_distance ? "marker" : "default");
|
||||
return false;
|
||||
}
|
||||
|
||||
cusp_distance = placed;
|
||||
extension = actual_extension;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DockCalc::samplePivotPolyline(
|
||||
const robot_geometry_msgs::Pose& start,
|
||||
const robot_geometry_msgs::Pose& goal,
|
||||
double approach_yaw,
|
||||
double heading_offset,
|
||||
double start_longitudinal,
|
||||
double start_lateral,
|
||||
double vertex_distance,
|
||||
std::vector<robot_geometry_msgs::Pose>& path,
|
||||
double& pivot_angle,
|
||||
bool allow_one_spacing_leg) const
|
||||
{
|
||||
path.clear();
|
||||
pivot_angle = 0.0;
|
||||
|
||||
// The vertex must lie between the robot and the dock. That is the property
|
||||
// this shape is chosen for: it never reaches further from the dock than the
|
||||
// robot already stands, so it costs no extra aisle depth at all.
|
||||
if (!std::isfinite(vertex_distance) ||
|
||||
vertex_distance + kEpsilon >= start_longitudinal)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const double leg_length = std::hypot(start_longitudinal - vertex_distance,
|
||||
start_lateral);
|
||||
// Keep the old pivot's sampling threshold unchanged. Back-off B is placed
|
||||
// one point spacing beyond the vertex, so that fallback can use one segment.
|
||||
const bool too_short = allow_one_spacing_leg
|
||||
? leg_length + kEpsilon < config_.path_point_spacing
|
||||
: leg_length <= 2.0 * config_.path_point_spacing;
|
||||
if (!std::isfinite(leg_length) || too_short)
|
||||
{
|
||||
// Too short to sample into a usable leg; another shape fits better.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Body yaw the terminal is driven at, and therefore the yaw the rotation
|
||||
// has to finish on. It equals goal_yaw on both docking sides, because a
|
||||
// front dock offsets approach_yaw and heading_offset by pi each.
|
||||
const double terminal_yaw = normalizeAngle(approach_yaw + heading_offset);
|
||||
|
||||
// Two ways to drive the first leg: nose-first along it, or in reverse.
|
||||
// Taking the smaller pivot also selects the travel direction the terminal
|
||||
// already uses, on either docking side, so the finished path keeps one
|
||||
// travel direction from end to end and contains no cusp.
|
||||
const double leg_course = std::atan2(-start_lateral,
|
||||
vertex_distance - start_longitudinal);
|
||||
const double forward_yaw = normalizeAngle(approach_yaw + leg_course);
|
||||
const double reverse_yaw = normalizeAngle(forward_yaw + kPi);
|
||||
const double forward_turn = normalizeAngle(terminal_yaw - forward_yaw);
|
||||
const double reverse_turn = normalizeAngle(terminal_yaw - reverse_yaw);
|
||||
const bool drive_forward = std::fabs(forward_turn) <= std::fabs(reverse_turn);
|
||||
const double leg_yaw = drive_forward ? forward_yaw : reverse_yaw;
|
||||
pivot_angle = drive_forward ? forward_turn : reverse_turn;
|
||||
|
||||
const robot_geometry_msgs::Pose vertex = poseFromDockCoordinates(
|
||||
goal, approach_yaw, vertex_distance, 0.0, leg_yaw);
|
||||
|
||||
const int sample_count = std::max(
|
||||
1, static_cast<int>(std::ceil(leg_length / config_.path_point_spacing)));
|
||||
path.reserve(static_cast<std::size_t>(sample_count + 1 + kPivotBlockSteps));
|
||||
for (int index = 0; index <= sample_count; ++index)
|
||||
{
|
||||
const double ratio = static_cast<double>(index) / sample_count;
|
||||
robot_geometry_msgs::Pose pose;
|
||||
pose.position.x = start.position.x + ratio * (vertex.position.x - start.position.x);
|
||||
pose.position.y = start.position.y + ratio * (vertex.position.y - start.position.y);
|
||||
pose.position.z = start.position.z + ratio * (vertex.position.z - start.position.z);
|
||||
pose.orientation = data_convert::createQuaternionMsgFromYaw(leg_yaw);
|
||||
appendUnique(path, pose);
|
||||
}
|
||||
|
||||
if (path.size() < 2)
|
||||
{
|
||||
path.clear();
|
||||
return false;
|
||||
}
|
||||
path.front().position = start.position;
|
||||
path.back() = vertex;
|
||||
|
||||
if (std::fabs(pivot_angle) <= kNegligiblePivot)
|
||||
{
|
||||
// Already on the terminal heading: a block of identical poses would
|
||||
// only make the controller stop for nothing.
|
||||
pivot_angle = 0.0;
|
||||
return true;
|
||||
}
|
||||
|
||||
// push_back, NOT appendUnique: these poses share a position by design and
|
||||
// appendUnique exists to delete exactly that. Losing them would leave a
|
||||
// bare polyline vertex, which no wheeled base can drive through -- heading
|
||||
// cannot change instantaneously at a corner.
|
||||
for (int index = 1; index <= kPivotBlockSteps; ++index)
|
||||
{
|
||||
const double ratio = static_cast<double>(index) /
|
||||
static_cast<double>(kPivotBlockSteps);
|
||||
robot_geometry_msgs::Pose pose = vertex;
|
||||
pose.orientation = data_convert::createQuaternionMsgFromYaw(
|
||||
normalizeAngle(leg_yaw + ratio * pivot_angle));
|
||||
path.push_back(pose);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DockCalc::sampleDirectEntry(
|
||||
const robot_geometry_msgs::Pose& start,
|
||||
const robot_geometry_msgs::Pose& goal,
|
||||
@@ -409,6 +603,63 @@ bool DockCalc::sampleTerminal(
|
||||
return path.size() >= 2;
|
||||
}
|
||||
|
||||
bool DockCalc::checkPivotPathCostmap(
|
||||
const std::vector<robot_geometry_msgs::Pose>& path,
|
||||
double rotation_radius, bool skip_start_pose, std::string& reason) const
|
||||
{
|
||||
reason.clear();
|
||||
if (!config_.pivot_check_costmap ||
|
||||
(!rotation_clear_ && !footprint_clear_))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rotation_checked = false;
|
||||
for (std::size_t index = 0; index < path.size(); ++index)
|
||||
{
|
||||
const auto& pose = path[index];
|
||||
bool same_position_as_previous = false;
|
||||
if (index > 0)
|
||||
{
|
||||
const auto& previous = path[index - 1];
|
||||
same_position_as_previous =
|
||||
std::hypot(pose.position.x - previous.position.x,
|
||||
pose.position.y - previous.position.y) <= kEpsilon;
|
||||
if (same_position_as_previous)
|
||||
{
|
||||
const double yaw_change = normalizeAngle(
|
||||
data_convert::getYaw(pose.orientation) -
|
||||
data_convert::getYaw(previous.orientation));
|
||||
if (std::fabs(yaw_change) > kNegligiblePivot &&
|
||||
!rotation_checked && rotation_clear_ &&
|
||||
!rotation_clear_(pose, rotation_radius))
|
||||
{
|
||||
reason = "rotation sweep is blocked at (" +
|
||||
std::to_string(pose.position.x) + ", " +
|
||||
std::to_string(pose.position.y) + ")";
|
||||
return false;
|
||||
}
|
||||
if (std::fabs(yaw_change) > kNegligiblePivot)
|
||||
{
|
||||
rotation_checked = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
rotation_checked = false;
|
||||
}
|
||||
|
||||
if ((!skip_start_pose || index != 0) && footprint_clear_ &&
|
||||
!footprint_clear_(pose))
|
||||
{
|
||||
reason = "footprint is blocked at (" +
|
||||
std::to_string(pose.position.x) + ", " +
|
||||
std::to_string(pose.position.y) + ")";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DockCalc::makePlanMoveToDock(
|
||||
const robot_geometry_msgs::PoseStamped& start,
|
||||
const robot_geometry_msgs::PoseStamped& goal,
|
||||
@@ -427,13 +678,17 @@ bool DockCalc::makePlanMoveToDock(
|
||||
return false;
|
||||
}
|
||||
|
||||
// 0 is legal for a differential base: it is what allows an on-the-spot
|
||||
// rotation to appear in the path. Only negative or non-finite is an error.
|
||||
const double minimum_turning_radius = config_.minimumTurningRadius();
|
||||
if (!std::isfinite(minimum_turning_radius) || minimum_turning_radius <= kEpsilon)
|
||||
if (!std::isfinite(minimum_turning_radius) || minimum_turning_radius < 0.0)
|
||||
{
|
||||
robot::log_error(
|
||||
"[dock_calc] Kinematics are unresolved: wheel_base=%.6f m, "
|
||||
"max_steering_angle=%.6f rad.\n",
|
||||
config_.wheel_base, config_.max_steering_angle);
|
||||
"[dock_calc] Kinematics are unresolved: model=%s, wheel_base=%.6f m, "
|
||||
"max_steering_angle=%.6f rad, minimum_turning_radius=%.6f m.\n",
|
||||
config_.requiresAxleTf() ? "ackermann" : "differential",
|
||||
config_.wheel_base, config_.max_steering_angle,
|
||||
config_.minimum_turning_radius);
|
||||
return false;
|
||||
}
|
||||
if (!isFinitePose(start.pose) || !isFinitePose(goal.pose))
|
||||
@@ -538,20 +793,41 @@ bool DockCalc::makePlanMoveToDock(
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool mating_edge = config_.dock_anchor == DockAnchor::kMatingEdge;
|
||||
const double face_offset = mating_edge
|
||||
? config_.dock_face_offset.value_or(mating_extent)
|
||||
: 0.0;
|
||||
const double effective_pivot_safety_margin =
|
||||
mating_edge && config_.dock_pivot_safety_margin.has_value()
|
||||
? *config_.dock_pivot_safety_margin
|
||||
: config_.pivot_safety_margin;
|
||||
const double requested_cusp_floor =
|
||||
mating_edge
|
||||
? std::max(mating_extent - face_offset, 0.0) +
|
||||
config_.reverse_distance_padding
|
||||
: mating_extent + dock_extent + config_.reverse_distance_padding;
|
||||
// For mating_edge, only a positive difference between mating_extent and the
|
||||
// measured face offset contributes to the terminal floor. Keep a positive
|
||||
// sampleable floor even when the configured offset reaches or passes the edge.
|
||||
const double minimum_cusp_distance = mating_edge
|
||||
? std::max(requested_cusp_floor,
|
||||
config_.path_point_spacing)
|
||||
: requested_cusp_floor;
|
||||
const std::string effective_face_offset_text =
|
||||
mating_edge ? std::to_string(face_offset) + " m" : "n/a";
|
||||
|
||||
robot::log_info(
|
||||
"[dock_calc] Docking edge=%s (lead-in drives %s, terminal drives %s), "
|
||||
"derived from goal-frame longitudinal=%.3f m. Cusp clearance uses robot "
|
||||
"%s_extent=%.3f m + dock %s_extent=%.3f m + padding=%.3f m.\n",
|
||||
"derived from goal-frame longitudinal=%.3f m. Cusp floor=%.3f m "
|
||||
"(robot=%s_extent %.3f m, dock=%s_extent %.3f m, padding=%.3f m).\n",
|
||||
dock_with_front ? "FRONT" : "REAR",
|
||||
dock_with_front ? "REVERSE" : "FORWARD",
|
||||
dock_with_front ? "FORWARD" : "REVERSE",
|
||||
goal_longitudinal,
|
||||
goal_longitudinal, minimum_cusp_distance,
|
||||
dock_with_front ? "front" : "rear", mating_extent,
|
||||
dock_with_front ? "rear" : "front", dock_extent,
|
||||
config_.reverse_distance_padding);
|
||||
|
||||
const double minimum_cusp_distance = mating_extent + dock_extent +
|
||||
config_.reverse_distance_padding;
|
||||
if (!std::isfinite(minimum_cusp_distance) || minimum_cusp_distance <= kEpsilon)
|
||||
{
|
||||
robot::log_error(
|
||||
@@ -564,48 +840,357 @@ bool DockCalc::makePlanMoveToDock(
|
||||
// Length of the straight terminal leg. The clearance is a floor, not the
|
||||
// target: a robot needs a straight run long enough to settle its heading
|
||||
// before it enters the dock, and that is usually longer than its own overhang.
|
||||
const double effective_straight_length =
|
||||
config_.dock_straight_length.value_or(config_.straight_length);
|
||||
const double effective_maximum_cusp_distance =
|
||||
config_.dock_maximum_cusp_distance.value_or(config_.maximum_cusp_distance);
|
||||
const double straight_distance =
|
||||
std::max(minimum_cusp_distance, config_.straight_length);
|
||||
std::max(minimum_cusp_distance, effective_straight_length);
|
||||
const double curve_room = start_longitudinal - straight_distance;
|
||||
|
||||
std::vector<robot_geometry_msgs::Pose> approach_segment;
|
||||
double cusp_distance = straight_distance;
|
||||
double curve_radius = 0.0;
|
||||
bool direct_entry = false;
|
||||
const bool differential =
|
||||
config_.kinematic_model == KinematicModel::kDifferential;
|
||||
|
||||
// Preferred shape when there is room for it: no direction change at all, so
|
||||
// the controller never has to detect a cusp, and the robot converges onto the
|
||||
// dock axis while still far from the dock.
|
||||
// Vertex of the straight-pivot-straight shape. Turning on the spot rotates
|
||||
// every footprint point about base_link, so the body sweeps its
|
||||
// circumscribed radius here, which is always more than the mating extent
|
||||
// the straight terminal is sized from. Sizing the vertex from the terminal
|
||||
// instead would drive a corner of the robot into the dock.
|
||||
//
|
||||
// With dock_anchor=mating_edge the goal is the docked base_link pose and the
|
||||
// dock face sits face_offset behind it (mating_extent when unset). The sweep
|
||||
// clearance is measured from that real face. face and center keep their
|
||||
// existing face-at-goal / dock_extent geometry.
|
||||
const double pivot_face_offset = mating_edge ? -face_offset : dock_extent;
|
||||
const double pivot_vertex_distance = std::max(
|
||||
straight_distance,
|
||||
robot.circumscribed_radius + pivot_face_offset +
|
||||
effective_pivot_safety_margin);
|
||||
|
||||
// The pivot shape needs a base that can change heading without moving. A
|
||||
// differential base can exactly when its declared turning radius is 0; a
|
||||
// non-zero radius there means on-the-spot turns were forbidden on purpose,
|
||||
// for instance while carrying a tall load. Any other base pivots only if the
|
||||
// integrator says so, which is what a non-zero threshold means.
|
||||
const bool turns_in_place = differential && minimum_turning_radius <= kEpsilon;
|
||||
const bool pivot_enabled =
|
||||
turns_in_place || config_.pivot_fallback_extension > 0.0;
|
||||
|
||||
double cusp_distance = straight_distance;
|
||||
double cusp_extension = std::numeric_limits<double>::quiet_NaN();
|
||||
const bool cusp_reachable =
|
||||
cuspPlacement(start_longitudinal, start_lateral, minimum_cusp_distance,
|
||||
minimum_turning_radius, cusp_distance, cusp_extension);
|
||||
|
||||
// On a differential base the pivot shape is the primary maneuver rather
|
||||
// than a fallback: it costs no extra aisle and needs no arc. On an
|
||||
// Ackermann base it is preferred once the cusp would push the robot further
|
||||
// away from the dock than the threshold, or when no cusp can be placed at
|
||||
// all -- returning no path there would be strictly worse than returning one
|
||||
// with an extra stop.
|
||||
const bool prefer_pivot =
|
||||
pivot_enabled &&
|
||||
(turns_in_place || !cusp_reachable ||
|
||||
cusp_extension > config_.pivot_fallback_extension);
|
||||
|
||||
Shape order[3];
|
||||
int order_size = 0;
|
||||
if (config_.direct_entry_min_curve_room > 0.0 &&
|
||||
curve_room > config_.direct_entry_min_curve_room)
|
||||
{
|
||||
direct_entry = sampleDirectEntry(start.pose, goal.pose, approach_yaw,
|
||||
heading_offset, start_longitudinal,
|
||||
start_lateral, straight_distance,
|
||||
minimum_turning_radius, approach_segment,
|
||||
curve_radius);
|
||||
if (!direct_entry)
|
||||
order[order_size++] = Shape::kDirectEntry;
|
||||
}
|
||||
if (prefer_pivot)
|
||||
{
|
||||
approach_segment.clear();
|
||||
const double lateral = std::fabs(start_lateral);
|
||||
const double radicand = 2.0 * minimum_turning_radius * lateral -
|
||||
lateral * lateral;
|
||||
robot::log_info(
|
||||
"[dock_calc] Direct entry does not fit (curve room=%.3f m, lateral=%.3f m "
|
||||
"needs >= %.3f m at min_radius=%.3f m); planning the single-cusp "
|
||||
"maneuver instead.\n",
|
||||
curve_room, start_lateral,
|
||||
radicand > 0.0 ? std::sqrt(radicand) : 0.0, minimum_turning_radius);
|
||||
order[order_size++] = Shape::kPivot;
|
||||
order[order_size++] = Shape::kCusp;
|
||||
}
|
||||
else
|
||||
{
|
||||
order[order_size++] = Shape::kCusp;
|
||||
if (pivot_enabled)
|
||||
{
|
||||
order[order_size++] = Shape::kPivot;
|
||||
}
|
||||
}
|
||||
|
||||
if (!direct_entry &&
|
||||
!sampleLeadIn(start.pose, goal.pose, approach_yaw, heading_offset,
|
||||
start_longitudinal, start_lateral,
|
||||
straight_distance, minimum_turning_radius,
|
||||
approach_segment, cusp_distance, curve_radius))
|
||||
std::vector<robot_geometry_msgs::Pose> approach_segment;
|
||||
Shape selected = Shape::kNone;
|
||||
double curve_radius = std::numeric_limits<double>::infinity();
|
||||
double pivot_angle = 0.0;
|
||||
|
||||
// Each candidate falls through to the next when it cannot be built, so
|
||||
// adding a shape can never introduce a new way to fail. That was the defect
|
||||
// in the aisle-depth gate this ladder replaced: it rejected shapes without
|
||||
// ever offering a cheaper one.
|
||||
for (int index = 0; index < order_size && selected == Shape::kNone; ++index)
|
||||
{
|
||||
robot::log_error("[dock_calc] Failed to generate the lead-in segment.\n");
|
||||
approach_segment.clear();
|
||||
switch (order[index])
|
||||
{
|
||||
case Shape::kDirectEntry:
|
||||
if (sampleDirectEntry(start.pose, goal.pose, approach_yaw,
|
||||
heading_offset, start_longitudinal,
|
||||
start_lateral, straight_distance,
|
||||
minimum_turning_radius, approach_segment,
|
||||
curve_radius))
|
||||
{
|
||||
selected = Shape::kDirectEntry;
|
||||
}
|
||||
break;
|
||||
|
||||
case Shape::kPivot:
|
||||
if (samplePivotPolyline(start.pose, goal.pose, approach_yaw,
|
||||
heading_offset, start_longitudinal,
|
||||
start_lateral, pivot_vertex_distance,
|
||||
approach_segment, pivot_angle))
|
||||
{
|
||||
std::string safety_reason;
|
||||
bool safe = checkPivotPathCostmap(
|
||||
approach_segment,
|
||||
robot.circumscribed_radius + effective_pivot_safety_margin,
|
||||
true, safety_reason);
|
||||
if (safe)
|
||||
{
|
||||
selected = Shape::kPivot;
|
||||
}
|
||||
else
|
||||
{
|
||||
robot::log_info(
|
||||
"[dock_calc] straight_pivot_straight failed costmap check: %s; "
|
||||
"trying another shape.\n",
|
||||
safety_reason.c_str());
|
||||
approach_segment.clear();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Shape::kCusp:
|
||||
if (cusp_reachable &&
|
||||
sampleLeadIn(start.pose, goal.pose, approach_yaw, heading_offset,
|
||||
start_longitudinal, start_lateral, cusp_distance,
|
||||
minimum_turning_radius, approach_segment,
|
||||
curve_radius))
|
||||
{
|
||||
selected = Shape::kCusp;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string backoff_status = "not enabled";
|
||||
if (selected == Shape::kNone)
|
||||
{
|
||||
if (!differential)
|
||||
{
|
||||
backoff_status = "not enabled: model is ackermann";
|
||||
}
|
||||
else if (!pivot_enabled)
|
||||
{
|
||||
backoff_status = "not enabled: pivot is disabled";
|
||||
}
|
||||
else if (config_.pivot_backoff_max_distance <= 0.0)
|
||||
{
|
||||
backoff_status = "not enabled: pivot_backoff_max_distance is 0";
|
||||
}
|
||||
else
|
||||
{
|
||||
backoff_status = "tried, rejected";
|
||||
std::string backoff_reason;
|
||||
const double start_yaw = normalizeAngle(
|
||||
data_convert::getYaw(start.pose.orientation));
|
||||
const double longitudinal_gain =
|
||||
std::cos(normalizeAngle(start_yaw - approach_yaw));
|
||||
const double backoff_target_longitudinal =
|
||||
pivot_vertex_distance + config_.path_point_spacing;
|
||||
|
||||
if (!std::isfinite(longitudinal_gain) ||
|
||||
std::fabs(longitudinal_gain) <= 0.26)
|
||||
{
|
||||
backoff_reason =
|
||||
"current heading is within 15 degrees of perpendicular to the approach axis "
|
||||
"(longitudinal gain per metre <= 0.26)";
|
||||
}
|
||||
else if (backoff_target_longitudinal <= start_longitudinal + kEpsilon)
|
||||
{
|
||||
backoff_reason =
|
||||
"start is already at or beyond the minimum back-off target";
|
||||
}
|
||||
else
|
||||
{
|
||||
const double backoff_length =
|
||||
(backoff_target_longitudinal - start_longitudinal) /
|
||||
std::fabs(longitudinal_gain);
|
||||
|
||||
// No check of the start footprint against the dock: the robot
|
||||
// physically stands there, and the back-off only moves it away.
|
||||
// With dock_anchor=face the dock is modelled at the goal, which
|
||||
// is the docked base pose, not the real face (the charger apex
|
||||
// sits 0.40 m behind it). That check rejected a robot whose rear
|
||||
// was 0.45 m clear of the charger.
|
||||
if (!std::isfinite(backoff_length) ||
|
||||
backoff_length > config_.pivot_backoff_max_distance + kEpsilon)
|
||||
{
|
||||
backoff_reason =
|
||||
"required back-off length " + std::to_string(backoff_length) +
|
||||
" m exceeds pivot_backoff_max_distance " +
|
||||
std::to_string(config_.pivot_backoff_max_distance) + " m";
|
||||
}
|
||||
else
|
||||
{
|
||||
const int sample_count = std::max(
|
||||
1, static_cast<int>(std::ceil(
|
||||
backoff_length / config_.path_point_spacing)));
|
||||
std::vector<robot_geometry_msgs::Pose> backoff_samples;
|
||||
backoff_samples.reserve(static_cast<std::size_t>(sample_count + 1));
|
||||
const double signed_distance = longitudinal_gain > 0.0
|
||||
? backoff_length
|
||||
: -backoff_length;
|
||||
for (int sample = 0; sample <= sample_count; ++sample)
|
||||
{
|
||||
const double ratio = static_cast<double>(sample) / sample_count;
|
||||
robot_geometry_msgs::Pose backoff_pose = offsetPoint(
|
||||
start.pose, start_yaw, signed_distance * ratio);
|
||||
backoff_pose.orientation =
|
||||
data_convert::createQuaternionMsgFromYaw(start_yaw);
|
||||
appendUnique(backoff_samples, backoff_pose);
|
||||
}
|
||||
backoff_samples.front() = start.pose;
|
||||
|
||||
const robot_geometry_msgs::Pose& point_b = backoff_samples.back();
|
||||
const double point_b_relative_x = point_b.position.x - goal.pose.position.x;
|
||||
const double point_b_relative_y = point_b.position.y - goal.pose.position.y;
|
||||
const double point_b_longitudinal =
|
||||
point_b_relative_x * std::cos(approach_yaw) +
|
||||
point_b_relative_y * std::sin(approach_yaw);
|
||||
const double point_b_lateral =
|
||||
-point_b_relative_x * std::sin(approach_yaw) +
|
||||
point_b_relative_y * std::cos(approach_yaw);
|
||||
std::vector<robot_geometry_msgs::Pose> pivot_samples;
|
||||
double backoff_pivot_angle = 0.0;
|
||||
if (!samplePivotPolyline(
|
||||
point_b, goal.pose, approach_yaw, heading_offset,
|
||||
point_b_longitudinal, point_b_lateral,
|
||||
pivot_vertex_distance, pivot_samples,
|
||||
backoff_pivot_angle, true))
|
||||
{
|
||||
backoff_reason =
|
||||
"the existing pivot leg cannot be built from point B";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<robot_geometry_msgs::Pose> backoff_path;
|
||||
backoff_path.reserve(
|
||||
backoff_samples.size() + pivot_samples.size() +
|
||||
static_cast<std::size_t>(kPivotBlockSteps));
|
||||
for (const auto& sample : backoff_samples)
|
||||
{
|
||||
appendUnique(backoff_path, sample);
|
||||
}
|
||||
|
||||
const double leg_yaw = normalizeAngle(
|
||||
data_convert::getYaw(pivot_samples.front().orientation));
|
||||
const double backoff_rotation =
|
||||
normalizeAngle(leg_yaw - start_yaw);
|
||||
if (std::fabs(backoff_rotation) > kNegligiblePivot)
|
||||
{
|
||||
for (int step = 1; step <= kPivotBlockSteps; ++step)
|
||||
{
|
||||
const double ratio = static_cast<double>(step) /
|
||||
static_cast<double>(kPivotBlockSteps);
|
||||
robot_geometry_msgs::Pose rotation_pose = point_b;
|
||||
rotation_pose.orientation =
|
||||
data_convert::createQuaternionMsgFromYaw(
|
||||
normalizeAngle(start_yaw + ratio * backoff_rotation));
|
||||
backoff_path.push_back(rotation_pose);
|
||||
}
|
||||
}
|
||||
|
||||
for (std::size_t sample = 1;
|
||||
sample < pivot_samples.size(); ++sample)
|
||||
{
|
||||
const auto& pivot_pose = pivot_samples[sample];
|
||||
const bool same_position = !backoff_path.empty() &&
|
||||
std::hypot(
|
||||
backoff_path.back().position.x - pivot_pose.position.x,
|
||||
backoff_path.back().position.y - pivot_pose.position.y) <=
|
||||
kEpsilon;
|
||||
const double yaw_change = same_position
|
||||
? normalizeAngle(
|
||||
data_convert::getYaw(pivot_pose.orientation) -
|
||||
data_convert::getYaw(backoff_path.back().orientation))
|
||||
: 0.0;
|
||||
if (same_position &&
|
||||
std::fabs(yaw_change) > kNegligiblePivot)
|
||||
{
|
||||
backoff_path.push_back(pivot_pose);
|
||||
}
|
||||
else
|
||||
{
|
||||
appendUnique(backoff_path, pivot_pose);
|
||||
}
|
||||
}
|
||||
|
||||
bool safe = true;
|
||||
if (config_.pivot_check_costmap &&
|
||||
(rotation_clear_ || footprint_clear_))
|
||||
{
|
||||
safe = checkPivotPathCostmap(
|
||||
backoff_path,
|
||||
robot.circumscribed_radius +
|
||||
effective_pivot_safety_margin,
|
||||
true, backoff_reason);
|
||||
}
|
||||
|
||||
if (safe)
|
||||
{
|
||||
approach_segment = std::move(backoff_path);
|
||||
pivot_angle = backoff_pivot_angle;
|
||||
selected = Shape::kBackoffPivot;
|
||||
backoff_status = "tried, succeeded";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selected == Shape::kNone)
|
||||
{
|
||||
if (backoff_reason.empty())
|
||||
{
|
||||
backoff_reason = "costmap safety check rejected the path";
|
||||
}
|
||||
backoff_status += ": " + backoff_reason;
|
||||
robot::log_info(
|
||||
"[dock_calc] backoff_pivot_straight failed: %s; no further shapes.\n",
|
||||
backoff_reason.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selected == Shape::kNone || approach_segment.empty())
|
||||
{
|
||||
robot::log_error(
|
||||
"[dock_calc] No docking maneuver could be planned: model=%s, "
|
||||
"start=(long=%.3f m, lateral=%.3f m in approach frame), "
|
||||
"min_radius=%.3f m, straight_distance=%.3f m, "
|
||||
"cusp_reachable=%s (extension=%.3f m, max=%.3f m), "
|
||||
"pivot_enabled=%s (vertex=%.3f m, circumscribed=%.3f m), "
|
||||
"face_offset=%s, pivot_safety_margin=%.3f m, "
|
||||
"straight_length=%.3f m (source=%s), "
|
||||
"maximum_cusp_distance=%.3f m (source=%s), backoff_pivot=%s.\n",
|
||||
differential ? "differential" : "ackermann",
|
||||
start_longitudinal, start_lateral, minimum_turning_radius,
|
||||
straight_distance, cusp_reachable ? "yes" : "no", cusp_extension,
|
||||
config_.maximum_forward_extension, pivot_enabled ? "yes" : "no",
|
||||
pivot_vertex_distance, robot.circumscribed_radius,
|
||||
effective_face_offset_text.c_str(), effective_pivot_safety_margin,
|
||||
effective_straight_length, config_.dock_straight_length ? "marker" : "default",
|
||||
effective_maximum_cusp_distance,
|
||||
config_.dock_maximum_cusp_distance ? "marker" : "default",
|
||||
backoff_status.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -617,14 +1202,22 @@ bool DockCalc::makePlanMoveToDock(
|
||||
return false;
|
||||
}
|
||||
|
||||
// The approach segment is copied verbatim instead of through appendUnique:
|
||||
// the rotation block is a run of poses that deliberately share a position,
|
||||
// and appendUnique exists to delete exactly that. Only the junction between
|
||||
// the two segments is deduplicated, which is all appendUnique ever removed
|
||||
// here for the arc-based shapes.
|
||||
plan.reserve(approach_segment.size() + terminal_segment.size());
|
||||
for (const auto& pose : approach_segment)
|
||||
{
|
||||
appendUnique(plan, pose);
|
||||
}
|
||||
plan.insert(plan.end(), approach_segment.begin(), approach_segment.end());
|
||||
for (const auto& pose : terminal_segment)
|
||||
{
|
||||
appendUnique(plan, pose);
|
||||
if (!plan.empty() &&
|
||||
std::hypot(plan.back().position.x - pose.position.x,
|
||||
plan.back().position.y - pose.position.y) <= kEpsilon)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
plan.push_back(pose);
|
||||
}
|
||||
|
||||
if (plan.size() < 3)
|
||||
@@ -635,20 +1228,26 @@ bool DockCalc::makePlanMoveToDock(
|
||||
plan.front().position = start.pose.position;
|
||||
plan.back() = goal.pose;
|
||||
|
||||
const double terminal_length = distance(approach_segment.back(), goal.pose);
|
||||
robot::log_info(
|
||||
"[dock_calc] Generated %s-edge %s dock path: poses=%zu, approach=%zu (%s), "
|
||||
"terminal=%zu (%s straight %.3f m), wheel_base=%.4f m, max_steer=%.4f rad, "
|
||||
"[dock_calc] Generated %s-edge dock path: selected_maneuver=%s, model=%s, "
|
||||
"poses=%zu (approach=%zu, terminal=%zu), terminal straight %.3f m driven %s, "
|
||||
"min_radius=%.4f m, start=(long=%.3f m, lateral=%.3f m in approach frame), "
|
||||
"curve room=%.3f m, arc_radius=%.4f m.\n",
|
||||
dock_with_front ? "front" : "rear",
|
||||
direct_entry ? "direct (no cusp)" : "single-cusp",
|
||||
plan.size(), approach_segment.size(),
|
||||
direct_entry ? (dock_with_front ? "forward" : "reverse")
|
||||
: (dock_with_front ? "reverse" : "forward"),
|
||||
terminal_segment.size(), dock_with_front ? "forward" : "reverse",
|
||||
cusp_distance, config_.wheel_base, config_.max_steering_angle,
|
||||
minimum_turning_radius, start_longitudinal, start_lateral,
|
||||
curve_room, curve_radius);
|
||||
"curve_room=%.3f m, cusp_extension=%.3f m (pivot threshold=%.3f m), "
|
||||
"arc_radius=%.4f m, pivot_vertex=%.3f m, pivot_angle=%.4f rad, "
|
||||
"circumscribed_radius=%.3f m, face_offset=%s, pivot_safety_margin=%.3f m, "
|
||||
"straight_length=%.3f m (source=%s), maximum_cusp_distance=%.3f m (source=%s).\n",
|
||||
dock_with_front ? "front" : "rear", shapeName(selected),
|
||||
differential ? "differential" : "ackermann",
|
||||
plan.size(), approach_segment.size(), terminal_segment.size(),
|
||||
terminal_length, dock_with_front ? "forward" : "reverse",
|
||||
minimum_turning_radius, start_longitudinal, start_lateral, curve_room,
|
||||
cusp_extension, config_.pivot_fallback_extension, curve_radius,
|
||||
pivot_vertex_distance, pivot_angle, robot.circumscribed_radius,
|
||||
effective_face_offset_text.c_str(), effective_pivot_safety_margin,
|
||||
effective_straight_length, config_.dock_straight_length ? "marker" : "default",
|
||||
effective_maximum_cusp_distance,
|
||||
config_.dock_maximum_cusp_distance ? "marker" : "default");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,14 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include <boost/dll/alias.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <data_convert/data_convert.h>
|
||||
#include <robot/robot.h>
|
||||
#include <robot_costmap_2d/cost_values.h>
|
||||
|
||||
namespace dock_planner
|
||||
{
|
||||
@@ -90,10 +94,144 @@ FootprintLoadStatus loadDockFootprint(
|
||||
return FootprintLoadStatus::kValid;
|
||||
}
|
||||
|
||||
std::string optionalDistanceText(const std::optional<double>& value)
|
||||
{
|
||||
return value.has_value() ? std::to_string(*value) + " m" : "unset";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DockPlanner::DockPlanner() = default;
|
||||
|
||||
bool DockPlanner::rotationClear(const robot_geometry_msgs::Pose& pose,
|
||||
double radius) const
|
||||
{
|
||||
// getCostmap() may return a replacement map after a resize. Keep this
|
||||
// pointer local to the callback and protect every read with that map's mutex.
|
||||
robot_costmap_2d::Costmap2D* costmap =
|
||||
costmap_robot_ == nullptr ? nullptr : costmap_robot_->getCostmap();
|
||||
if (costmap == nullptr || !std::isfinite(pose.position.x) ||
|
||||
!std::isfinite(pose.position.y) || !std::isfinite(radius) || radius < 0.0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::unique_lock<robot_costmap_2d::Costmap2D::mutex_t> lock(
|
||||
*costmap->getMutex());
|
||||
const double resolution = costmap->getResolution();
|
||||
const unsigned int size_x = costmap->getSizeInCellsX();
|
||||
const unsigned int size_y = costmap->getSizeInCellsY();
|
||||
if (!std::isfinite(resolution) || resolution <= 0.0 || size_x == 0 || size_y == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const double map_min_x = costmap->getOriginX();
|
||||
const double map_min_y = costmap->getOriginY();
|
||||
const double map_max_x = map_min_x + resolution * size_x;
|
||||
const double map_max_y = map_min_y + resolution * size_y;
|
||||
if (pose.position.x - radius < map_min_x ||
|
||||
pose.position.y - radius < map_min_y ||
|
||||
pose.position.x + radius >= map_max_x ||
|
||||
pose.position.y + radius >= map_max_y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int min_mx = 0;
|
||||
int min_my = 0;
|
||||
int max_mx = 0;
|
||||
int max_my = 0;
|
||||
costmap->worldToMapNoBounds(pose.position.x - radius,
|
||||
pose.position.y - radius, min_mx, min_my);
|
||||
costmap->worldToMapNoBounds(pose.position.x + radius,
|
||||
pose.position.y + radius, max_mx, max_my);
|
||||
min_mx = std::max(0, min_mx);
|
||||
min_my = std::max(0, min_my);
|
||||
max_mx = std::min(static_cast<int>(size_x) - 1, max_mx);
|
||||
max_my = std::min(static_cast<int>(size_y) - 1, max_my);
|
||||
|
||||
const double half_cell = resolution * 0.5;
|
||||
const double radius_squared = radius * radius;
|
||||
for (int my = min_my; my <= max_my; ++my)
|
||||
{
|
||||
for (int mx = min_mx; mx <= max_mx; ++mx)
|
||||
{
|
||||
double cell_x = 0.0;
|
||||
double cell_y = 0.0;
|
||||
costmap->mapToWorld(static_cast<unsigned int>(mx),
|
||||
static_cast<unsigned int>(my), cell_x, cell_y);
|
||||
const double dx = std::max(
|
||||
std::fabs(cell_x - pose.position.x) - half_cell, 0.0);
|
||||
const double dy = std::max(
|
||||
std::fabs(cell_y - pose.position.y) - half_cell, 0.0);
|
||||
if (dx * dx + dy * dy <= radius_squared &&
|
||||
costmap->getCost(static_cast<unsigned int>(mx),
|
||||
static_cast<unsigned int>(my)) ==
|
||||
robot_costmap_2d::LETHAL_OBSTACLE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DockPlanner::footprintClear(const robot_geometry_msgs::Pose& pose)
|
||||
{
|
||||
// As above, never retain getCostmap() across calls: the master can be
|
||||
// replaced while a planner is running.
|
||||
robot_costmap_2d::Costmap2D* costmap =
|
||||
costmap_robot_ == nullptr ? nullptr : costmap_robot_->getCostmap();
|
||||
if (costmap == nullptr || !std::isfinite(pose.position.x) ||
|
||||
!std::isfinite(pose.position.y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& footprint = costmap_robot_->getRobotFootprint();
|
||||
if (footprint.size() < 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::unique_lock<robot_costmap_2d::Costmap2D::mutex_t> lock(
|
||||
*costmap->getMutex());
|
||||
footprint_map_polygon_.clear();
|
||||
footprint_map_cells_.clear();
|
||||
footprint_map_polygon_.reserve(footprint.size());
|
||||
const double yaw = data_convert::getYaw(pose.orientation);
|
||||
if (!std::isfinite(yaw))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const double cos_yaw = std::cos(yaw);
|
||||
const double sin_yaw = std::sin(yaw);
|
||||
for (const auto& point : footprint)
|
||||
{
|
||||
const double world_x = pose.position.x +
|
||||
cos_yaw * point.x - sin_yaw * point.y;
|
||||
const double world_y = pose.position.y +
|
||||
sin_yaw * point.x + cos_yaw * point.y;
|
||||
robot_costmap_2d::MapLocation map_point;
|
||||
if (!costmap->worldToMap(world_x, world_y, map_point.x, map_point.y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
footprint_map_polygon_.push_back(map_point);
|
||||
}
|
||||
|
||||
costmap->convexFillCells(footprint_map_polygon_, footprint_map_cells_);
|
||||
for (const auto& cell : footprint_map_cells_)
|
||||
{
|
||||
if (costmap->getCost(cell.x, cell.y) == robot_costmap_2d::LETHAL_OBSTACLE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !footprint_map_cells_.empty();
|
||||
}
|
||||
|
||||
bool DockPlanner::initialize(std::string name,
|
||||
robot_costmap_2d::Costmap2DROBOT* costmap_robot)
|
||||
{
|
||||
@@ -133,6 +271,8 @@ bool DockPlanner::initialize(std::string name,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (loaded_config.requiresAxleTf())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Match StanleyControl's axle-TF contract: lookup the front axle in
|
||||
@@ -163,26 +303,43 @@ bool DockPlanner::initialize(std::string name,
|
||||
loaded_config.rear_axle_frame.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// A differential base publishes no steered-axle frame. Looking one up
|
||||
// would throw and take the whole plugin down, so the turning radius
|
||||
// comes from configuration instead and wheel_base stays meaningless.
|
||||
loaded_config.wheel_base = 0.0;
|
||||
}
|
||||
|
||||
const double minimum_turning_radius = loaded_config.minimumTurningRadius();
|
||||
if (!std::isfinite(minimum_turning_radius) || minimum_turning_radius <= 0.0)
|
||||
// 0 is valid for a differential base: it means the robot may turn on the
|
||||
// spot. Only a negative or non-finite radius is a configuration error.
|
||||
if (!std::isfinite(minimum_turning_radius) || minimum_turning_radius < 0.0)
|
||||
{
|
||||
robot::log_error(
|
||||
"[dock_planner] Cannot derive minimum turning radius from wheel_base=%.6f m "
|
||||
"and max_steering_angle=%.6f rad.\n",
|
||||
loaded_config.wheel_base, loaded_config.max_steering_angle);
|
||||
"[dock_planner] Cannot derive minimum turning radius (model=%s, "
|
||||
"wheel_base=%.6f m, max_steering_angle=%.6f rad, "
|
||||
"minimum_turning_radius=%.6f m).\n",
|
||||
loaded_config.requiresAxleTf() ? "ackermann" : "differential",
|
||||
loaded_config.wheel_base, loaded_config.max_steering_angle,
|
||||
loaded_config.minimum_turning_radius);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<robot_geometry_msgs::Point> loaded_footprint;
|
||||
if (loaded_config.dock_anchor == DockAnchor::kFace)
|
||||
if (loaded_config.dock_anchor == DockAnchor::kFace ||
|
||||
loaded_config.dock_anchor == DockAnchor::kMatingEdge)
|
||||
{
|
||||
// Goal sits on the approach face: dock size never enters the approach
|
||||
// formula, so a declared footprint_dock is deliberately ignored.
|
||||
// Goal sits on the approach face (face) or the face touches the robot at
|
||||
// the goal (mating_edge): dock size never enters the approach formula,
|
||||
// so a declared footprint_dock is deliberately ignored.
|
||||
if (planner_nh.hasParam("footprint_dock"))
|
||||
{
|
||||
robot::log_info("[dock_planner] '%s' uses dock_anchor=face; footprint_dock is ignored.\n",
|
||||
name.c_str());
|
||||
robot::log_info("[dock_planner] '%s' uses dock_anchor=%s; footprint_dock is ignored.\n",
|
||||
name.c_str(),
|
||||
loaded_config.dock_anchor == DockAnchor::kFace ? "face"
|
||||
: "mating_edge");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -204,15 +361,43 @@ bool DockPlanner::initialize(std::string name,
|
||||
global_frame_ = costmap_robot->getGlobalFrameID();
|
||||
footprint_dock_ = std::move(loaded_footprint);
|
||||
dock_calc_.setConfig(loaded_config);
|
||||
dock_calc_.setCostmapCheckCallbacks(
|
||||
[this](const robot_geometry_msgs::Pose& pose, double radius)
|
||||
{
|
||||
return rotationClear(pose, radius);
|
||||
},
|
||||
[this](const robot_geometry_msgs::Pose& pose)
|
||||
{
|
||||
return footprintClear(pose);
|
||||
});
|
||||
initialized_ = true;
|
||||
|
||||
const std::string dock_face_offset_text =
|
||||
optionalDistanceText(loaded_config.dock_face_offset);
|
||||
const std::string dock_pivot_safety_margin_text =
|
||||
optionalDistanceText(loaded_config.dock_pivot_safety_margin);
|
||||
const std::string dock_straight_length_text =
|
||||
optionalDistanceText(loaded_config.dock_straight_length);
|
||||
robot::log_info(
|
||||
"[dock_planner] Initialized single-cusp dock maneuver (docking edge is "
|
||||
"derived per plan from the side the robot stands on): TF %s -> %s, "
|
||||
"wheel_base=%.4f m, max_steering_angle=%.4f rad, minimum_turning_radius=%.4f m.\n",
|
||||
loaded_config.front_axle_frame.c_str(), loaded_config.rear_axle_frame.c_str(),
|
||||
"[dock_planner] Initialized dock maneuver (docking edge is derived per plan "
|
||||
"from the side the robot stands on): model=%s, TF %s -> %s, wheel_base=%.4f m, "
|
||||
"max_steering_angle=%.4f rad, minimum_turning_radius=%.4f m, "
|
||||
"pivot_fallback_extension=%.3f m, pivot_safety_margin=%.3f m, "
|
||||
"dock_face_offset=%s, dock_pivot_safety_margin=%s, dock_straight_length=%s, "
|
||||
"maximum_cusp_distance=%.3f m (source=%s), "
|
||||
"pivot_backoff_max_distance=%.3f m, pivot_check_costmap=%s.\n",
|
||||
loaded_config.requiresAxleTf() ? "ackermann" : "differential",
|
||||
loaded_config.requiresAxleTf() ? loaded_config.front_axle_frame.c_str() : "-",
|
||||
loaded_config.requiresAxleTf() ? loaded_config.rear_axle_frame.c_str() : "-",
|
||||
loaded_config.wheel_base, loaded_config.max_steering_angle,
|
||||
minimum_turning_radius);
|
||||
minimum_turning_radius, loaded_config.pivot_fallback_extension,
|
||||
loaded_config.pivot_safety_margin,
|
||||
dock_face_offset_text.c_str(), dock_pivot_safety_margin_text.c_str(),
|
||||
dock_straight_length_text.c_str(),
|
||||
loaded_config.dock_maximum_cusp_distance.value_or(loaded_config.maximum_cusp_distance),
|
||||
loaded_config.dock_maximum_cusp_distance ? "marker" : "default",
|
||||
loaded_config.pivot_backoff_max_distance,
|
||||
loaded_config.pivot_check_costmap ? "true" : "false");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
namespace dock_planner
|
||||
{
|
||||
namespace
|
||||
@@ -26,6 +28,51 @@ bool readOptionalDouble(const robot::NodeHandle& nh, const std::string& key,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readNullableOptionalDouble(const robot::NodeHandle& nh, const std::string& key,
|
||||
std::optional<double>& value, std::string& error)
|
||||
{
|
||||
YAML::Node node;
|
||||
if (!nh.getParam(key, node) || !node.IsDefined() || node.IsNull())
|
||||
{
|
||||
value.reset();
|
||||
return true;
|
||||
}
|
||||
if (!node.IsScalar())
|
||||
{
|
||||
error = "parameter '" + key + "' must be numeric or null";
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
value = node.as<double>();
|
||||
}
|
||||
catch (const YAML::Exception&)
|
||||
{
|
||||
error = "parameter '" + key + "' must be numeric or null";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readOptionalBool(const robot::NodeHandle& nh, const std::string& key,
|
||||
bool& value, std::string& error)
|
||||
{
|
||||
if (!nh.hasParam(key))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parsed = value;
|
||||
if (!nh.getParam(key, parsed, value))
|
||||
{
|
||||
error = "parameter '" + key + "' must be a boolean";
|
||||
return false;
|
||||
}
|
||||
value = parsed;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readOptionalString(const robot::NodeHandle& nh, const std::string& key,
|
||||
std::string& value, std::string& error)
|
||||
{
|
||||
@@ -67,7 +114,42 @@ bool readDockAnchor(const robot::NodeHandle& nh, DockAnchor& anchor, std::string
|
||||
anchor = DockAnchor::kFace;
|
||||
return true;
|
||||
}
|
||||
error = "parameter 'dock_anchor' must be 'center' or 'face' (got '" + parsed + "')";
|
||||
if (parsed == "mating_edge")
|
||||
{
|
||||
anchor = DockAnchor::kMatingEdge;
|
||||
return true;
|
||||
}
|
||||
error = "parameter 'dock_anchor' must be 'center', 'face' or 'mating_edge' (got '" +
|
||||
parsed + "')";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool readKinematicModel(const robot::NodeHandle& nh, KinematicModel& model,
|
||||
std::string& error)
|
||||
{
|
||||
if (!nh.hasParam("kinematics/model"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string parsed;
|
||||
if (!nh.getParam("kinematics/model", parsed, std::string()))
|
||||
{
|
||||
error = "parameter 'kinematics/model' must be a string";
|
||||
return false;
|
||||
}
|
||||
if (parsed == "ackermann")
|
||||
{
|
||||
model = KinematicModel::kAckermann;
|
||||
return true;
|
||||
}
|
||||
if (parsed == "differential")
|
||||
{
|
||||
model = KinematicModel::kDifferential;
|
||||
return true;
|
||||
}
|
||||
error = "parameter 'kinematics/model' must be 'ackermann' or 'differential' (got '" +
|
||||
parsed + "')";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -87,7 +169,18 @@ bool DockPlannerConfig::load(const robot::NodeHandle& nh, DockPlannerConfig& con
|
||||
std::string& error)
|
||||
{
|
||||
DockPlannerConfig loaded;
|
||||
if (!readOptionalString(nh, "kinematics/front_axle_frame",
|
||||
if (!readKinematicModel(nh, loaded.kinematic_model, error) ||
|
||||
!readOptionalDouble(nh, "kinematics/minimum_turning_radius",
|
||||
loaded.minimum_turning_radius, error) ||
|
||||
!readOptionalDouble(nh, "maneuver/pivot_fallback_extension",
|
||||
loaded.pivot_fallback_extension, error) ||
|
||||
!readOptionalDouble(nh, "maneuver/pivot_safety_margin",
|
||||
loaded.pivot_safety_margin, error) ||
|
||||
!readOptionalDouble(nh, "maneuver/pivot_backoff_max_distance",
|
||||
loaded.pivot_backoff_max_distance, error) ||
|
||||
!readOptionalBool(nh, "maneuver/pivot_check_costmap",
|
||||
loaded.pivot_check_costmap, error) ||
|
||||
!readOptionalString(nh, "kinematics/front_axle_frame",
|
||||
loaded.front_axle_frame, error) ||
|
||||
!readOptionalString(nh, "kinematics/rear_axle_frame",
|
||||
loaded.rear_axle_frame, error) ||
|
||||
@@ -99,6 +192,8 @@ bool DockPlannerConfig::load(const robot::NodeHandle& nh, DockPlannerConfig& con
|
||||
loaded.minimum_forward_distance, error) ||
|
||||
!readOptionalDouble(nh, "maneuver/maximum_forward_extension",
|
||||
loaded.maximum_forward_extension, error) ||
|
||||
!readOptionalDouble(nh, "maneuver/maximum_cusp_distance",
|
||||
loaded.maximum_cusp_distance, error) ||
|
||||
!readOptionalDouble(nh, "terminal/straight_length",
|
||||
loaded.straight_length, error) ||
|
||||
!readOptionalDouble(nh, "maneuver/direct_entry_min_curve_room",
|
||||
@@ -109,7 +204,15 @@ bool DockPlannerConfig::load(const robot::NodeHandle& nh, DockPlannerConfig& con
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!readDockAnchor(nh, loaded.dock_anchor, error))
|
||||
if (!readDockAnchor(nh, loaded.dock_anchor, error) ||
|
||||
!readNullableOptionalDouble(nh, "dock_face_offset",
|
||||
loaded.dock_face_offset, error) ||
|
||||
!readNullableOptionalDouble(nh, "dock_pivot_safety_margin",
|
||||
loaded.dock_pivot_safety_margin, error) ||
|
||||
!readNullableOptionalDouble(nh, "dock_straight_length",
|
||||
loaded.dock_straight_length, error) ||
|
||||
!readNullableOptionalDouble(nh, "dock_maximum_cusp_distance",
|
||||
loaded.dock_maximum_cusp_distance, error))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -126,6 +229,11 @@ bool DockPlannerConfig::load(const robot::NodeHandle& nh, DockPlannerConfig& con
|
||||
|
||||
bool DockPlannerConfig::validate(std::string& error) const
|
||||
{
|
||||
if (!std::isfinite(maximum_cusp_distance) || maximum_cusp_distance < 0.0)
|
||||
{
|
||||
error = "parameter 'maneuver/maximum_cusp_distance' must be finite and >= 0 m";
|
||||
return false;
|
||||
}
|
||||
const struct
|
||||
{
|
||||
const char* name;
|
||||
@@ -133,10 +241,15 @@ bool DockPlannerConfig::validate(std::string& error) const
|
||||
} values[] = {
|
||||
{"kinematics/max_steering_angle", max_steering_angle},
|
||||
{"kinematics/wheel_base", wheel_base},
|
||||
{"kinematics/minimum_turning_radius", minimum_turning_radius},
|
||||
{"maneuver/pivot_fallback_extension", pivot_fallback_extension},
|
||||
{"maneuver/pivot_safety_margin", pivot_safety_margin},
|
||||
{"maneuver/pivot_backoff_max_distance", pivot_backoff_max_distance},
|
||||
{"terminal/reverse_distance_padding", reverse_distance_padding},
|
||||
{"terminal/straight_length", straight_length},
|
||||
{"maneuver/minimum_forward_distance", minimum_forward_distance},
|
||||
{"maneuver/maximum_forward_extension", maximum_forward_extension},
|
||||
{"maneuver/maximum_cusp_distance", maximum_cusp_distance},
|
||||
{"maneuver/direct_entry_min_curve_room", direct_entry_min_curve_room},
|
||||
{"sampling/path_point_spacing", path_point_spacing},
|
||||
};
|
||||
@@ -149,6 +262,61 @@ bool DockPlannerConfig::validate(std::string& error) const
|
||||
}
|
||||
}
|
||||
|
||||
const char* anchor_name = dock_anchor == DockAnchor::kMatingEdge
|
||||
? "mating_edge"
|
||||
: (dock_anchor == DockAnchor::kFace ? "face" : "center");
|
||||
if (dock_face_offset.has_value())
|
||||
{
|
||||
if (dock_anchor != DockAnchor::kMatingEdge)
|
||||
{
|
||||
error = std::string("dock_face_offset is only valid with dock_anchor: mating_edge (got ") +
|
||||
anchor_name + ")";
|
||||
return false;
|
||||
}
|
||||
if (!std::isfinite(*dock_face_offset) || *dock_face_offset <= 0.0 ||
|
||||
*dock_face_offset > 2.0)
|
||||
{
|
||||
error = "parameter 'dock_face_offset' must be finite and in (0, 2.0] m";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (dock_pivot_safety_margin.has_value())
|
||||
{
|
||||
if (dock_anchor != DockAnchor::kMatingEdge)
|
||||
{
|
||||
error = std::string(
|
||||
"dock_pivot_safety_margin is only valid with dock_anchor: mating_edge (got ") +
|
||||
anchor_name + ")";
|
||||
return false;
|
||||
}
|
||||
if (!std::isfinite(*dock_pivot_safety_margin) ||
|
||||
*dock_pivot_safety_margin < 0.0 || *dock_pivot_safety_margin > 1.0)
|
||||
{
|
||||
error = "parameter 'dock_pivot_safety_margin' must be finite and in [0, 1.0] m";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (dock_straight_length.has_value() &&
|
||||
(!std::isfinite(*dock_straight_length) || *dock_straight_length < 0.0 ||
|
||||
*dock_straight_length > 2.0))
|
||||
{
|
||||
error = "parameter 'dock_straight_length' must be finite and in [0, 2.0] m";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dock_maximum_cusp_distance.has_value() &&
|
||||
(!std::isfinite(*dock_maximum_cusp_distance) || *dock_maximum_cusp_distance < 0.0))
|
||||
{
|
||||
error = "parameter 'dock_maximum_cusp_distance' must be finite and >= 0 m";
|
||||
return false;
|
||||
}
|
||||
|
||||
// A differential base has no steered axle: validating axle frames or a
|
||||
// steering limit there would reject a perfectly valid configuration and
|
||||
// stop the plugin from loading at all.
|
||||
if (kinematic_model == KinematicModel::kAckermann)
|
||||
{
|
||||
if (front_axle_frame.empty() || rear_axle_frame.empty())
|
||||
{
|
||||
error = "kinematics axle frame names must not be empty";
|
||||
@@ -169,6 +337,13 @@ bool DockPlannerConfig::validate(std::string& error) const
|
||||
error = "resolved kinematics wheel_base must be >= 0 m";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (minimum_turning_radius < 0.0)
|
||||
{
|
||||
error = "parameter 'kinematics/minimum_turning_radius' must be >= 0 m "
|
||||
"(0 allows turning on the spot)";
|
||||
return false;
|
||||
}
|
||||
if (reverse_distance_padding < 0.0)
|
||||
{
|
||||
error = "parameter 'terminal/reverse_distance_padding' must be >= 0 m";
|
||||
@@ -195,6 +370,22 @@ bool DockPlannerConfig::validate(std::string& error) const
|
||||
error = "maneuver maximum_forward_extension must be >= minimum_forward_distance";
|
||||
return false;
|
||||
}
|
||||
if (pivot_fallback_extension < 0.0)
|
||||
{
|
||||
error = "parameter 'maneuver/pivot_fallback_extension' must be >= 0 m "
|
||||
"(0 disables the straight-pivot-straight shape)";
|
||||
return false;
|
||||
}
|
||||
if (pivot_safety_margin < 0.0)
|
||||
{
|
||||
error = "parameter 'maneuver/pivot_safety_margin' must be >= 0 m";
|
||||
return false;
|
||||
}
|
||||
if (pivot_backoff_max_distance < 0.0 || pivot_backoff_max_distance > 3.0)
|
||||
{
|
||||
error = "parameter 'maneuver/pivot_backoff_max_distance' must be in [0, 3] m";
|
||||
return false;
|
||||
}
|
||||
if (path_point_spacing <= 0.0 || path_point_spacing > 1.0)
|
||||
{
|
||||
error = "parameter 'sampling/path_point_spacing' must be in (0, 1] m";
|
||||
@@ -207,6 +398,16 @@ bool DockPlannerConfig::validate(std::string& error) const
|
||||
|
||||
double DockPlannerConfig::minimumTurningRadius() const
|
||||
{
|
||||
if (kinematic_model == KinematicModel::kDifferential)
|
||||
{
|
||||
// 0 is a legal answer here, not a failure: it is what lets the planner
|
||||
// place an explicit on-the-spot rotation in the path.
|
||||
if (!std::isfinite(minimum_turning_radius) || minimum_turning_radius < 0.0)
|
||||
{
|
||||
return std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
return minimum_turning_radius;
|
||||
}
|
||||
if (!(wheel_base > 0.0) || !(max_steering_angle > 0.0) ||
|
||||
!(max_steering_angle < kPi / 2.0))
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user