feat(nav): emergency stop latch xuyên BaseNavigation + C API

Copy nội dung sau fix từ T800_ws pnkx_nav_core (branch
dev_recovery_and_manager_mission, commit f4a5c96) — rb_ws khớp byte-for-byte
bản trước fix nên copy thẳng.

CẤP THIẾT: move_base2 submodule (đã bump lên 8d9932c) đã có
NavigationServer::emergency()/clearEmergency() override — thiếu commit này
thì BaseNavigation ở rb_ws không khai virtual tương ứng, override không
khớp base, rb_ws build gãy ngay.

BaseNavigation thêm 2 virtual MỚI Ở CUỐI vtable: emergency(),
clearEmergency() — không đổi chữ ký method cũ (ABI: rebuild đồng bộ
libmove_base.so + C API + mọi host). State EMERGENCY = 14 append cuối enum,
giá trị cũ không đổi (đã verify cả bên C mirror nav_c_api.h).

emergency(): lệnh 0 ngay, huỷ chặng đang chạy (báo CANCELLED đúng 1 lần),
xoá hàng đợi mission, chốt state. Hiệu lực TRƯỚC KHI hàm trả về trên chính
thread gọi (getTwist/getFeedback đổi ngay cả khi control thread đang block
trong plugin); dọn dẹp thật (planner, recovery, action, mission layer)
chạy ở chu kỳ kế tiếp. Trong lúc chốt: moveTo/executeInstantActions bị từ
chối, pause/resume/cancel bị bỏ qua. clearEmergency() đưa về PENDING,
không tự chạy lại — host phải gửi goal mới.

C API: navigation_emergency() / navigation_clear_emergency() trong
nav_c_api_2.h.

Đã verify: virtual signature emergency()/clearEmergency() khớp override
trong move_base2/src/navigation_server.cpp; EMERGENCY=14 append cuối enum
cả hai bên C/C++, không đụng giá trị enum cũ.
This commit is contained in:
2026-09-15 15:21:41 +07:00
parent 1485e7c19c
commit 2921fede24
7 changed files with 240 additions and 6 deletions

View File

@@ -42,6 +42,11 @@ Thư viện này được thiết kế để:
- `pause()` - tạm dừng di chuyển
- `resume()` - tiếp tục di chuyển
- `cancel()` - hủy mục tiêu hiện tại
- `emergency()` - dừng khẩn: lệnh 0 ngay, huỷ chặng đang chạy, xoá hàng đợi mission, chốt
state `EMERGENCY`; mọi `moveTo`/`executeInstantActions` bị từ chối, `pause/resume/cancel` bị
bỏ qua cho tới khi `clearEmergency()`. Có hiệu lực ngay trên thread host cho `getTwist()` /
`getFeedback()`, không chờ control thread
- `clearEmergency()` - gỡ chốt dừng khẩn, về `PENDING`; không tự chạy lại, host phải gửi goal mới
- `setTwistLinear()`, `setTwistAngular()` - điều khiển vận tốc
- **Lấy thông tin**:
- `getRobotPose()` - lấy vị trí hiện tại của robot
@@ -83,6 +88,8 @@ Enum `State` mô tả các trạng thái khác nhau trong quá trình navigation
- **CONTROLLING**: Đang điều khiển robot di chuyển theo plan
- **CLEARING**: Đang dọn dẹp costmap, thực hiện recovery behaviors
- **PAUSED**: Tạm dừng navigation
- **EMERGENCY**: Dừng khẩn đang chốt (2026-09-14). Giá trị 14, thêm cuối enum để các giá trị cũ và
bản C trong `nav_c_api.h` không đổi số. Chỉ `clearEmergency()` mới ra khỏi state này
- **SUCCEEDED**: Hoàn thành thành công
- **ABORTED**: Bị lỗi, không thể hoàn thành
- **PREEMPTED**: Bị hủy bởi mục tiêu mới

View File

@@ -50,7 +50,14 @@ namespace robot
PLANNING,
CONTROLLING,
CLEARING,
PAUSED
PAUSED,
/**
* Emergency stop latched (2026-09-14). The core commands zero, has cancelled the running
* leg and wiped the mission queue, and rejects every new goal until clearEmergency().
* Appended last so the numeric values of the states above — and of the C mirror in
* nav_c_api.h — do not move.
*/
EMERGENCY
};
/**
@@ -117,6 +124,8 @@ namespace robot
return "CLEARING"; // Đang dọn dẹp bản đồ / costmap
case State::PAUSED:
return "PAUSED"; // Tạm dừng
case State::EMERGENCY:
return "EMERGENCY"; // Dừng khẩn, chốt tới khi clearEmergency()
default:
return "UNKNOWN_STATE"; // Không xác định
}
@@ -474,7 +483,8 @@ namespace robot
*
* Lifecycle instantActions — `cancelOrder`, `startPause`, `stopPause` — must NOT come
* through here. They steer the queue rather than being work in it; the host calls
* @ref cancel, @ref pause and @ref resume for those.
* @ref cancel, @ref pause and @ref resume for those. The same goes for an emergency
* stop: it is @ref emergency / @ref clearEmergency, never an action.
*
* @param actions The actions of one `instantActions` message, in the order received.
* Must not be empty; every action needs `actionType` and `actionId`.
@@ -552,6 +562,34 @@ namespace robot
*/
virtual PlannerDataOutput getLocalData() = 0;
/**
* @brief Emergency stop.
*
* From this call onward the core commands zero, the running leg is cancelled (its outcome
* is reported as CANCELLED exactly once), the mission queue is wiped and the core latches
* State::EMERGENCY. While latched every @ref moveTo / @ref executeInstantActions is
* rejected and @ref pause / @ref resume / @ref cancel are ignored.
*
* Unlike the three lifecycle calls above this one takes effect on the **host thread** for
* what the host reads back — @ref getTwist returns zero and @ref getFeedback reports
* EMERGENCY before the call returns, even if the control thread is currently blocked.
* The control thread does the clean-up (planner, recovery, action, mission layer) on its
* next cycle. Idempotent.
*
* @note Added 2026-09-14 at the END of the vtable so the slots of every older method keep
* their index. Still an ABI change: rebuild the plugin (`libmove_base.so`), the C API
* and every host together — an old plugin under a new host crashes on this call.
*/
virtual void emergency() = 0;
/**
* @brief Release the emergency latch.
*
* The core returns to PENDING with nothing queued: nothing resumes by itself, the host
* must submit a new goal to move again. Idempotent; no-op when not latched.
*/
virtual void clearEmergency() = 0;
protected:
// Shared feedback data for navigation status tracking
std::shared_ptr<NavFeedback> nav_feedback_;