feat: snapshot API cho reader — planner solve trên bản copy, hết chặn map-update
Costmap2D::copyFrom: copy metadata + grid, chỉ realloc khi size đổi (operator= delete/new mỗi lần — không hợp copy định kỳ 30 Hz). Caller giữ mutex nguồn. Costmap2DROBOT: key config snapshot_for_readers (mặc định false = nguyên trạng); refreshSnapshot() khoá master mutex đúng bằng thời gian memcpy; getCostmapForRead() trả snapshot khi bật / lưới live khi tắt. Object snapshot ổn định địa chỉ, refresh tại chỗ — không tái tạo con trỏ (bài học DOUBLE_FREE_BUG_FIX_REPORT). Hợp đồng single-consumer: refresh + đọc cùng thread control loop. Kèm: load debug_level (commit trước) + fix priv_nh(priv_nh, name) tự khởi tạo từ chính nó — đổi thành (nh, name), cùng kết quả namespace, hết UB-adjacent. Verify: test_costmap 10/10 (3 test copyFrom mới), sim mission — lock_wait local 53 ms max -> 13 us, p99 cycle 21.4 -> 3.4 ms, local costmap chạy được 10 Hz với 1.2% một core. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -86,6 +86,18 @@ public:
|
||||
*/
|
||||
Costmap2D& operator=(const Costmap2D& map);
|
||||
|
||||
/**
|
||||
* @brief Copy metadata and grid from another costmap, reusing the existing
|
||||
* buffer when the size is unchanged (no delete/new per call).
|
||||
*
|
||||
* Built for periodic snapshotting (readers copy the master grid every
|
||||
* control cycle): operator= reallocates on every call, this only when the
|
||||
* grid size actually changed. The caller must hold the source map's mutex —
|
||||
* this method does not lock the source.
|
||||
* @param map The costmap to copy from
|
||||
*/
|
||||
void copyFrom(const Costmap2D& map);
|
||||
|
||||
/**
|
||||
* @brief Turn this costmap into a copy of a window of a costmap passed in
|
||||
* @param map The costmap to copy
|
||||
|
||||
Reference in New Issue
Block a user