feat(move_base2): wait for a ready global costmap and replay maps in host order
- Replay static maps in arrival order instead of topic order, so a direction grid can no longer be replayed before its static map (F3). - PlannerRunner checks every enabled global layer under the same lock as the snapshot; while not current it keeps the goal, reports waiting_for_costmap, logs the stale layers (throttled) and does not spend planner_patience or watchdog budget. After costmap_ready_timeout [s] (default 10, 0 = legacy behaviour) the attempt fails as before. - Test fixture destroys the server before its fake ports; the control thread could call a destroyed port (race existed before this change).
This commit is contained in:
@@ -53,6 +53,9 @@ struct MoveBase2Config
|
||||
*/
|
||||
double planner_timeout = 5.0;
|
||||
|
||||
/// [s] Continuous global-costmap readiness wait; 0 disables the check (legacy behavior).
|
||||
double costmap_ready_timeout = 10.0;
|
||||
|
||||
/**
|
||||
* Watchdog (2026-09-11): thread riêng đọc bảng trạng thái thành phần, kết luận "treo" theo ngân
|
||||
* sách từng hàng. `watchdog.planner_timeout` được chép từ @ref planner_timeout khi nạp.
|
||||
|
||||
@@ -109,6 +109,9 @@ struct ControlLoopConfig
|
||||
/// [s] Chu kỳ danh nghĩa, chỉ dùng cho dt của cycle ĐẦU TIÊN khi chưa có mốc thời gian trước đó.
|
||||
double nominal_control_period = 0.05;
|
||||
|
||||
/// [s] Maximum continuous global-costmap wait; 0 disables the readiness check.
|
||||
double costmap_ready_timeout = 10.0;
|
||||
|
||||
/// Công tắc log chẩn đoán. Xem `MoveBase2Config::debug_*` để biết từng nhóm in cái gì.
|
||||
bool debug_state = true;
|
||||
bool debug_plan = true;
|
||||
|
||||
@@ -48,7 +48,8 @@ enum class ComponentPhase : std::uint8_t
|
||||
kBusy, ///< Đang làm việc.
|
||||
kStopping, ///< Đã được bảo dừng (preempt/cancel) nhưng chưa thoát.
|
||||
kPaused, ///< Đã xác nhận tạm dừng (chỉ action, pha 3).
|
||||
kHung ///< Watchdog kết luận: bận quá ngân sách mà không nhích (pha 4).
|
||||
kHung, ///< Watchdog kết luận: bận quá ngân sách mà không nhích (pha 4).
|
||||
kWaitingForCostmap ///< Retaining the request until global costmap data is ready.
|
||||
};
|
||||
|
||||
const char* toString(Component component);
|
||||
|
||||
@@ -28,6 +28,7 @@ enum class PlannerFeedback
|
||||
{
|
||||
kIdle, ///< Chưa có tin gì mới kể từ cycle trước.
|
||||
kBusy, ///< Đang lập plan, chưa có kết quả.
|
||||
kWaitingForCostmap, ///< Goal retained while the global costmap becomes current.
|
||||
kPlanReady, ///< Có plan mới, không rỗng, sẵn sàng đẩy xuống controller.
|
||||
kFailed ///< Lần lập plan gần nhất thất bại.
|
||||
};
|
||||
@@ -190,6 +191,7 @@ struct StateMachineInput
|
||||
bool emergency = false;
|
||||
|
||||
PlannerFeedback planner = PlannerFeedback::kIdle;
|
||||
bool planner_costmap_wait_finished = false;
|
||||
ControllerFeedback controller = ControllerFeedback::kIdle;
|
||||
RecoveryFeedback recovery = RecoveryFeedback::kIdle;
|
||||
ActionFeedback action = ActionFeedback::kIdle;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#define MOVE_BASE2_NAVIGATION_SERVER_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -60,6 +61,8 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Nạp cấu hình và các cổng cho control loop.
|
||||
* @warning Các cổng trong deps là non-owning: bên cấp phải giữ chúng sống tới khi control
|
||||
* thread đã được dừng và join, kể cả khi dựa vào destructor của NavigationServer.
|
||||
* @param[out] error Lý do không cấu hình được.
|
||||
*/
|
||||
bool configureLoop(const ControlLoopConfig& config, const ControlLoopDeps& deps,
|
||||
@@ -423,6 +426,10 @@ private:
|
||||
/// Bảo vệ dữ liệu sensor và footprint: host ghi từ thread của nó, control loop đọc.
|
||||
mutable std::mutex data_mutex_;
|
||||
|
||||
/// Latest arrival order per stored static-map topic; guarded by data_mutex_.
|
||||
std::map<std::string, std::uint64_t> static_map_sequences_;
|
||||
std::uint64_t next_static_map_sequence_ = 0;
|
||||
|
||||
std::vector<robot_geometry_msgs::Point> footprint_;
|
||||
bool footprint_pending_ = false;
|
||||
std::map<std::string, robot_sensor_msgs::DepthCameraData::ConstPtr> depth_camera_data_;
|
||||
|
||||
@@ -108,6 +108,12 @@ public:
|
||||
/// @brief Có lượt lập plan nào đang chạy không.
|
||||
virtual bool isPlanning() const = 0;
|
||||
|
||||
/// Configure the global readiness wait before accepting requests. Zero keeps legacy behavior.
|
||||
virtual void setCostmapReadyTimeout(double /*seconds*/) {}
|
||||
|
||||
/// Atomically sample the wait and consume the completion event since the previous sample.
|
||||
virtual bool costmapWaitState(bool& finished) { finished = false; return false; }
|
||||
|
||||
/**
|
||||
* @brief Lấy kết quả nếu đã có. Không chặn.
|
||||
*
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#define MOVE_BASE2_RUNNERS_PLANNER_RUNNER_H_
|
||||
|
||||
#include <condition_variable>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
@@ -38,6 +39,15 @@ class Costmap2DROBOT;
|
||||
namespace move_base2
|
||||
{
|
||||
|
||||
/// Decision for a continuous readiness wait. A zero timeout preserves legacy planning behavior.
|
||||
enum class CostmapReadyDecision { kPlan, kWait, kTimeout };
|
||||
inline CostmapReadyDecision costmapReadyDecision(bool ready, double elapsed, double timeout)
|
||||
{
|
||||
if (timeout == 0.0 || ready)
|
||||
return CostmapReadyDecision::kPlan;
|
||||
return elapsed >= timeout ? CostmapReadyDecision::kTimeout : CostmapReadyDecision::kWait;
|
||||
}
|
||||
|
||||
/**
|
||||
* @class PlannerRunner
|
||||
* @brief Nạp và chạy global planner thế hệ 1 (`robot_nav_core::BaseGlobalPlanner`) qua Boost.DLL,
|
||||
@@ -177,6 +187,8 @@ public:
|
||||
const robot_protocol_msgs::Order* order, std::uint64_t tag) override;
|
||||
|
||||
bool isPlanning() const override;
|
||||
void setCostmapReadyTimeout(double seconds) override;
|
||||
bool costmapWaitState(bool& finished) override;
|
||||
|
||||
bool pollPlan(PlanResult& result) override;
|
||||
|
||||
@@ -268,6 +280,15 @@ private:
|
||||
bool running_ = false; ///< Thread đang chạy plugin.
|
||||
bool discard_ = false; ///< Lượt đang chạy đã bị huỷ — vứt kết quả khi nó về.
|
||||
bool has_result_ = false;
|
||||
double costmap_ready_timeout_ = 10.0; ///< [s], protected by mutex_.
|
||||
bool waiting_for_costmap_ = false;
|
||||
bool costmap_wait_finished_ = false;
|
||||
// Written only by the planner thread; throttle a persistent outage across failed attempts.
|
||||
bool costmap_wait_problem_active_ = false;
|
||||
std::chrono::steady_clock::time_point last_costmap_wait_log_;
|
||||
std::chrono::steady_clock::time_point last_costmap_timeout_log_;
|
||||
std::string costmap_stale_names_;
|
||||
bool costmap_stale_names_reserved_ = false;
|
||||
|
||||
robot_nav_core::BaseGlobalPlanner* active_ = nullptr; ///< Non-owning, trỏ vào @ref planners_.
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user