temporary storage 7/9/2026 20:41
This commit is contained in:
@@ -9,7 +9,7 @@ về output** (path/vận tốc), đồng thời vẫn dùng global path/costmap
|
||||
## Các thành phần
|
||||
|
||||
- `RecoveryBehavior` (interface, template-method): API non-virtual `configure`/`start`/`update`/
|
||||
`cancel`; plugin chỉ triển khai hook `onConfigure`/`onStart(goal)`/`onUpdate(dt)`.
|
||||
`cancel`; plugin chỉ triển khai hook `onConfigure`/`onStart(goal)`/`onUpdate()`.
|
||||
- `RecoveryContext`: gói con trỏ ngữ cảnh (tf/costmap/global_path) truyền một lần qua `configure`.
|
||||
- `RecoveryGoal`: mục tiêu RUNTIME mỗi lượt (angle/distance/target_pose/params).
|
||||
- `RecoveryResult` / `RecoveryStatus` / `RecoveryOutputType`: hợp đồng output hợp nhất 3 họ +
|
||||
@@ -27,22 +27,20 @@ configure(name, ctx) // 1 lần: cache ctx, đọc config chung, onConf
|
||||
│
|
||||
start(goal) // mỗi lượt: chốt mục tiêu runtime, onStart()
|
||||
│
|
||||
├── one-shot (họ A/B): update(dt) 1 lần ─────────► RecoveryResult{status, path|none, msg}
|
||||
├── one-shot (họ A/B): update() 1 lần ───────────► RecoveryResult{status, path|none, msg}
|
||||
│
|
||||
└── per-cycle (họ C): loop { update(dt) } ──────► RecoveryResult{status, velocity,
|
||||
└── per-cycle (họ C): loop { update() } ────────► RecoveryResult{status, velocity,
|
||||
(tới khi status != kRunning) progress, remaining}
|
||||
```
|
||||
|
||||
## Ghi chú thiết kế
|
||||
|
||||
- Template-method: base xử lý guard vòng đời (configure→start→update), `dt<=0`, `timeout`, đo
|
||||
`elapsed`, và `cancel` một chỗ; plugin không lặp lại các guard này.
|
||||
- Template-method: base xử lý guard vòng đời (configure→start→update) và `cancel` một chỗ;
|
||||
plugin không lặp lại các guard này.
|
||||
- Mục tiêu là RUNTIME qua `RecoveryGoal` (không cố định trong config): cùng plugin phục vụ nhiều
|
||||
yêu cầu góc/khoảng khác nhau. Field = 0 → dùng default plugin đọc ở `onConfigure()`.
|
||||
- `onUpdate(dt)` lấy pose robot từ costmap/tf bên trong; không truyền pose qua tham số.
|
||||
- `onUpdate()` lấy pose robot từ costmap/tf bên trong; không truyền pose qua tham số.
|
||||
- Sau `cancel()`, base tự trả stop output (Twist 0) + `kCancelled`.
|
||||
- Param chung duy nhất còn lại là `timeout` (s, 0 = không giới hạn), base đọc trong `configure()`
|
||||
từ `~/<name>/timeout`; giá trị `NaN/Inf/<0` bị thay bằng 0. Param RIÊNG của plugin đọc trong
|
||||
`onConfigure()`.
|
||||
- Param RIÊNG của plugin đọc trong `onConfigure()`.
|
||||
- Interface KHÔNG include Boost.DLL; export/import là việc của plugin/loader.
|
||||
- Plugin mẫu có dùng Boost.DLL alias, nhưng core contract vẫn không biết loader/adaptor.
|
||||
|
||||
@@ -11,8 +11,8 @@ Package hiện có 4 plugin mẫu dưới `plugins/`:
|
||||
1. Kế thừa `recovery_core::RecoveryBehavior`.
|
||||
2. Override hook `onConfigure()` (tuỳ chọn) — đọc param riêng qua `robot::NodeHandle("~/" + name)`;
|
||||
ngữ cảnh tf/global_path/costmap lấy qua `ctx()`.
|
||||
3. Override `onStart(goal)` + `onUpdate(dt)` theo họ (xem dưới). KHÔNG override
|
||||
`configure/start/update/cancel` — base đã lo guard vòng đời/timeout/cancel/elapsed.
|
||||
3. Override `onStart(goal)` + `onUpdate()` theo họ (xem dưới). KHÔNG override
|
||||
`configure/start/update/cancel` — base đã lo guard vòng đời/cancel.
|
||||
4. Thêm factory `static RecoveryBehaviorPtr create()` **không tham số** + `BOOST_DLL_ALIAS(...)`.
|
||||
|
||||
## Vòng đời (goal-driven)
|
||||
@@ -22,7 +22,7 @@ configure(name, ctx) // 1 lần: cache ctx, đọc config chung, gọi onCo
|
||||
│
|
||||
start(goal) // mỗi lượt: chốt mục tiêu RUNTIME (angle/distance/pose), gọi onStart()
|
||||
│
|
||||
loop update(dt) // mỗi cycle tới khi status != kRunning; base tick elapsed + guard
|
||||
loop update() // mỗi cycle tới khi status != kRunning; base guard vòng đời/cancel
|
||||
│
|
||||
[cancel()] // update() kế tiếp -> stop output + kCancelled
|
||||
```
|
||||
@@ -37,7 +37,7 @@ qua `goal.params` (vd `goal.params["angular_speed"] = 0.8`).
|
||||
|----|----------|--------|
|
||||
| A. path | `onUpdate()` (one-shot) | `RecoveryResult::PathOut(path, kSucceeded)` |
|
||||
| B. none | `onUpdate()` (one-shot) | `RecoveryResult::Succeeded()` / `Failed()` |
|
||||
| C. velocity | `onStart()` chốt goal + `onUpdate(dt)` mỗi cycle | `RecoveryResult::Velocity(twist, kRunning\|kSucceeded)` |
|
||||
| C. velocity | `onStart()` chốt goal + `onUpdate()` mỗi cycle | `RecoveryResult::Velocity(twist, kRunning\|kSucceeded)` |
|
||||
|
||||
Mọi kết quả nên gắn feedback qua `.withProgress(progress, remaining)` và `.withMessage(...)` để
|
||||
caller giám sát tiến độ (progress ∈ [0,1], remaining theo rad/m).
|
||||
@@ -55,7 +55,7 @@ class SpinRecovery : public recovery_core::RecoveryBehavior {
|
||||
return std::make_shared<SpinRecovery>();
|
||||
}
|
||||
protected:
|
||||
// override onConfigure()/onStart(goal)/onUpdate(dt)...
|
||||
// override onConfigure()/onStart(goal)/onUpdate()...
|
||||
};
|
||||
} // namespace recovery_plugins
|
||||
|
||||
@@ -80,7 +80,7 @@ recovery_core::RecoveryGoal goal;
|
||||
goal.angle = 1.57; // "quay 90 độ ngay lượt này"
|
||||
recovery_core::RecoveryResult r = behavior->start(goal);
|
||||
while (r.status == recovery_core::RecoveryStatus::kRunning) {
|
||||
r = behavior->update(dt); // publish r.command; đọc r.progress/r.remaining/r.message
|
||||
r = behavior->update(); // publish r.command; đọc r.progress/r.remaining/r.message
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -7,18 +7,17 @@
|
||||
- **Không collision-check tự động.** Interface không kiểm tra va chạm khi sinh vận tốc
|
||||
(backup/spin) hay khi tạo path. Việc tránh va chạm là trách nhiệm của **plugin** (dùng
|
||||
costmap được cấp qua `initialize`) hoặc của **caller**.
|
||||
- **Không quản lý vòng lặp thời gian thực.** Caller chịu trách nhiệm gọi `computeCommand(dt)`
|
||||
đúng nhịp và publish command.
|
||||
- **Không quản lý vòng lặp thời gian thực.** Caller chịu trách nhiệm gọi `update()` đúng nhịp
|
||||
và publish command.
|
||||
- **Không đảm bảo frame/đơn vị.** Pose lấy từ costmap/tf phải đúng frame; đơn vị phải nhất quán
|
||||
(m, rad, s, m/s, rad/s).
|
||||
- **Guard vòng đời ở base.** `start()` trước `configure()`, hay `update()` trước `start()`, đều trả
|
||||
`RecoveryResult::Failed()`. `dt <= 0`, `NaN`, `Inf`, và `timeout` do base chặn trước khi gọi
|
||||
`onUpdate()`. Sau `cancel()`, base trả stop output (Twist 0) + `kCancelled`.
|
||||
`RecoveryResult::Failed()`. Sau `cancel()`, base trả stop output (Twist 0) + `kCancelled`.
|
||||
|
||||
## Nguyên tắc cho plugin
|
||||
|
||||
- Guard costmap/tf null (lấy qua `ctx()`) trước khi thao tác; fail an toàn -> `RecoveryResult::Failed()`.
|
||||
- Không cần tự guard `dt <= 0`/`NaN`/`Inf`/`timeout` — base đã lo; chỉ tập trung logic recovery.
|
||||
- Không cần tự guard vòng đời/cancel — base đã lo; plugin tập trung logic recovery.
|
||||
- Với họ vận tốc: khi không chắc an toàn, trả **stop command** (Twist 0), không trả vận tốc mù.
|
||||
- Kiểm tra NaN/Inf của pose/vận tốc trước khi xuất command.
|
||||
- Tôn trọng giới hạn vận tốc/gia tốc của robot (đọc qua param).
|
||||
|
||||
Reference in New Issue
Block a user