update
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
*********************************************************************/
|
||||
#include <move_base2/control_loop.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
#include <robot/console.h>
|
||||
@@ -25,6 +27,58 @@ constexpr double kQuaternionNormTolerance = 1e-2;
|
||||
/// điều khiển — log mỗi cycle sẽ nhấn chìm mọi dòng khác.
|
||||
constexpr double kStaleCostmapLogThrottle = 5.0;
|
||||
|
||||
/// [s] Log debug tạm phục vụ test đường recovery/controller. Ngắn hơn throttle runtime mặc định để
|
||||
/// không bị mất dấu trong các fail diễn ra trong vài trăm ms sau detour.
|
||||
constexpr double kDebugControlLogThrottle = 0.2;
|
||||
|
||||
const char* toString(PlannerFeedback feedback)
|
||||
{
|
||||
switch (feedback)
|
||||
{
|
||||
case PlannerFeedback::kIdle:
|
||||
return "idle";
|
||||
case PlannerFeedback::kBusy:
|
||||
return "busy";
|
||||
case PlannerFeedback::kPlanReady:
|
||||
return "plan_ready";
|
||||
case PlannerFeedback::kFailed:
|
||||
return "failed";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
const char* toString(ControllerFeedback feedback)
|
||||
{
|
||||
switch (feedback)
|
||||
{
|
||||
case ControllerFeedback::kIdle:
|
||||
return "idle";
|
||||
case ControllerFeedback::kCommandValid:
|
||||
return "command_valid";
|
||||
case ControllerFeedback::kNoValidCommand:
|
||||
return "no_valid_command";
|
||||
case ControllerFeedback::kGoalReached:
|
||||
return "goal_reached";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
const char* toString(RecoveryFeedback feedback)
|
||||
{
|
||||
switch (feedback)
|
||||
{
|
||||
case RecoveryFeedback::kIdle:
|
||||
return "idle";
|
||||
case RecoveryFeedback::kRunning:
|
||||
return "running";
|
||||
case RecoveryFeedback::kSucceeded:
|
||||
return "succeeded";
|
||||
case RecoveryFeedback::kFailed:
|
||||
return "failed";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// ================================================================================================
|
||||
@@ -46,6 +100,11 @@ bool ControlLoopConfig::validate(std::string& error) const
|
||||
error = "nominal_control_period must be > 0 [s]";
|
||||
return false;
|
||||
}
|
||||
if (!std::isfinite(planner_frequency) || planner_frequency < 0.0)
|
||||
{
|
||||
error = "planner_frequency must be >= 0 [Hz] (0 = no background replanning)";
|
||||
return false;
|
||||
}
|
||||
if (position.local_planner_name.empty())
|
||||
{
|
||||
error = "profile 'position' must have local_planner_name";
|
||||
@@ -77,6 +136,8 @@ std::string ControlLoopConfig::describe() const
|
||||
out << velocity.describe();
|
||||
out << "ControlLoop:\n";
|
||||
out << " nominal_control_period: " << nominal_control_period << " s\n";
|
||||
out << " planner_frequency : " << planner_frequency << " Hz"
|
||||
<< (planner_frequency > 0.0 ? "" : " (no background replanning)") << '\n';
|
||||
out << " robot_base_frame : " << robot_base_frame << '\n';
|
||||
out << " profile position : " << position.global_planner_name << " / "
|
||||
<< position.local_planner_name << '\n';
|
||||
@@ -89,6 +150,11 @@ std::string ControlLoopConfig::describe() const
|
||||
return out.str();
|
||||
}
|
||||
|
||||
bool ControlLoopConfig::PathMonitorConfig::monitors(MotionProfile profile) const
|
||||
{
|
||||
return std::find(profiles.begin(), profiles.end(), profile) != profiles.end();
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// ControlLoop
|
||||
// ================================================================================================
|
||||
@@ -119,6 +185,54 @@ bool ControlLoop::configure(const ControlLoopConfig& config, const ControlLoopDe
|
||||
|
||||
config_ = config;
|
||||
deps_ = deps;
|
||||
|
||||
// Bật giám sát mà không có đường xử lý nào là cấu hình vô nghĩa — và trước đây nó im lặng. Không
|
||||
// chặn boot (navigation vẫn phải chạy), nhưng phải hét lên: người vận hành khai `enabled: true`
|
||||
// thì tin rằng cơ chế đang chạy.
|
||||
if (config_.path_monitor.enabled)
|
||||
{
|
||||
if (deps_.path_check == nullptr)
|
||||
{
|
||||
robot::log_error("[move_base2] path_monitor is enabled but no PathCheckPort is wired — path "
|
||||
"monitoring stays OFF.\n");
|
||||
}
|
||||
else if (!config_.path_monitor.path_blocked_enabled && !config_.path_monitor.off_path_enabled)
|
||||
{
|
||||
robot::log_warning("[move_base2] path_monitor/enabled is true but BOTH sub-monitors are off "
|
||||
"(path_blocked_enabled=false, off_path_enabled=false) — path monitoring "
|
||||
"does nothing.\n");
|
||||
}
|
||||
else if (config_.state_machine.recovery_routes.path_blocked.empty() &&
|
||||
config_.state_machine.recovery_routes.off_path.empty())
|
||||
{
|
||||
robot::log_error("[move_base2] path_monitor is enabled but BOTH recovery routes "
|
||||
"'path_blocked' and 'off_path' are empty (behaviors failed to load?) — path "
|
||||
"monitoring stays OFF.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// In trạng thái THẬT của từng phép đo, đã gộp cả ba nút: đọc một dòng là biết cái nào sống.
|
||||
const bool blocked_on = config_.path_monitor.path_blocked_enabled &&
|
||||
config_.path_monitor.horizon > 0.0 &&
|
||||
!config_.state_machine.recovery_routes.path_blocked.empty();
|
||||
const bool off_path_on = config_.path_monitor.off_path_enabled &&
|
||||
config_.path_monitor.max_cross_track > 0.0 &&
|
||||
!config_.state_machine.recovery_routes.off_path.empty();
|
||||
robot::log_info("[move_base2] path monitor ON (confirm=%.2f s, check=%.2f s):\n"
|
||||
" path_blocked: %s (flag=%s, horizon=%.2f m, route=%zu)\n"
|
||||
" off_path : %s (flag=%s, max_cross_track=%.2f m, route=%zu)\n",
|
||||
config_.path_monitor.confirm_time, config_.path_monitor.check_period,
|
||||
blocked_on ? "ON" : "OFF",
|
||||
config_.path_monitor.path_blocked_enabled ? "on" : "off",
|
||||
config_.path_monitor.horizon,
|
||||
config_.state_machine.recovery_routes.path_blocked.size(),
|
||||
off_path_on ? "ON" : "OFF",
|
||||
config_.path_monitor.off_path_enabled ? "on" : "off",
|
||||
config_.path_monitor.max_cross_track,
|
||||
config_.state_machine.recovery_routes.off_path.size());
|
||||
}
|
||||
}
|
||||
|
||||
initialized_ = true;
|
||||
reset();
|
||||
return true;
|
||||
@@ -153,6 +267,9 @@ void ControlLoop::reset()
|
||||
|
||||
has_last_cycle_time_ = false;
|
||||
has_oscillation_origin_ = false;
|
||||
last_plan_started_ = robot::Time();
|
||||
resetPathMonitor();
|
||||
has_last_plan_applied_ = false;
|
||||
|
||||
has_outcome_ = false;
|
||||
outcome_report_count_ = 0;
|
||||
@@ -394,6 +511,18 @@ void ControlLoop::collectPlannerResult()
|
||||
// rỗng lọt xuống sẽ thành front()/back() trên vector rỗng ở tầng dưới.
|
||||
if (!result.succeeded || result.plan.empty())
|
||||
{
|
||||
// Replan NỀN hỏng (đang kControlling): bỏ qua, plan cũ vẫn hiệu lực và robot đang bám nó bình
|
||||
// thường. Không kích backup planner ở đây — một lượt replan nền hụt (robot đi qua vùng hẹp,
|
||||
// costmap tạm bít) mà đổi hẳn sang SBPL là mất quỹ đạo NURBS của order cho phần còn lại của
|
||||
// chặng. Backup chỉ dành cho lúc THẬT SỰ cần plan mà không có (kPlanning).
|
||||
if (state_machine_.state() == NavigationState::kControlling)
|
||||
{
|
||||
robot::log_warning_throttle(5.0, "[move_base2] background replan failed; keeping the "
|
||||
"current plan.\n");
|
||||
planner_feedback_ = PlannerFeedback::kFailed;
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback thuộc policy của control loop, không phải recovery: planner chính đã kết thúc nên
|
||||
// worker rảnh để nạp/chạy SBPL ngay cycle này. Chỉ thử một lần cho cả request; backup fail thì
|
||||
// giữ kFailed để state machine đi đúng đường recovery hiện có.
|
||||
@@ -421,10 +550,172 @@ void ControlLoop::collectPlannerResult()
|
||||
return;
|
||||
}
|
||||
|
||||
// Luật "không thay plan sạch bằng plan bẩn" (contract 2026-08-04d).
|
||||
//
|
||||
// Không có luật này thì cơ chế detour tự phá chính nó: `CustomPlanner` mù costmap nên mỗi nhịp
|
||||
// `planner_frequency` nó trả lại đúng đường thẳng xuyên vật cản, ghi đè đường vòng vừa lập, rồi
|
||||
// PathMonitor lại khai hoả — robot dừng-detour-chạy-dừng mỗi giây và ngân sách route cạn rất
|
||||
// nhanh.
|
||||
//
|
||||
// Chỉ áp ở kControlling, nơi ĐANG có một plan để giữ. Ở kPlanning vẫn nhận plan bẩn như cũ:
|
||||
// PathMonitor sẽ khai hoả ngay khi vào kControlling, nên mọi tình huống tuyến-bị-chắn đi qua đúng
|
||||
// MỘT đường xử lý thay vì hai.
|
||||
//
|
||||
// Hệ quả đẹp: khi robot đã đi qua vật cản, plan thẳng của planner chính hết bị chắn nên được nhận
|
||||
// lại — robot tự quay về đúng tuyến/NURBS của order, không cần cơ chế nào để "kết thúc detour".
|
||||
if (state_machine_.state() == NavigationState::kControlling && !latest_plan_.empty() &&
|
||||
planIsBlocked(result.plan, 0))
|
||||
{
|
||||
robot::log_warning_throttle(5.0, "[move_base2] a fresh plan runs into an obstacle; keeping the "
|
||||
"current plan.\n");
|
||||
planner_feedback_ = PlannerFeedback::kFailed;
|
||||
return;
|
||||
}
|
||||
|
||||
latest_plan_.swap(result.plan);
|
||||
// Tuyến THAM CHIẾU của chặng = plan do PLANNER sinh, không phải plan đã bị recovery thay
|
||||
// (contract 2026-08-05e). Detour nối lại vào nó nên robot tự quay về tuyến order thay vì trôi
|
||||
// dần theo từng đường vòng, và `max_deviation` đo đúng hành lang mà fleet đã duyệt.
|
||||
order_plan_ = latest_plan_;
|
||||
planner_feedback_ = PlannerFeedback::kPlanReady;
|
||||
}
|
||||
|
||||
void ControlLoop::resetPathMonitor()
|
||||
{
|
||||
path_blocked_ = false;
|
||||
off_path_ = false;
|
||||
has_last_path_check_ = false;
|
||||
blocked_seen_ = false;
|
||||
off_path_seen_ = false;
|
||||
}
|
||||
|
||||
bool ControlLoop::planIsBlocked(const std::vector<robot_geometry_msgs::PoseStamped>& plan,
|
||||
std::size_t from_index) const
|
||||
{
|
||||
if (deps_.path_check == nullptr || !(config_.path_monitor.horizon > 0.0) || plan.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
PlanBlockResult result;
|
||||
if (!deps_.path_check->checkPlan(plan, from_index, config_.path_monitor.horizon, result))
|
||||
{
|
||||
// Không kết luận được (thiếu TF/costmap). "Không biết" KHÔNG được suy thành "bẩn": làm vậy là
|
||||
// robot dừng mỗi lần TF trễ một nhịp.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result.blocked)
|
||||
{
|
||||
last_block_distance_ = result.distance; // [m] chỉ để log; không tham gia quyết định.
|
||||
}
|
||||
return result.blocked && result.distance >= config_.path_monitor.min_detour_distance;
|
||||
}
|
||||
|
||||
void ControlLoop::updatePathMonitor(const robot::Time& now,
|
||||
const robot_geometry_msgs::PoseStamped& robot_pose,
|
||||
bool pose_available, bool costmap_stale)
|
||||
{
|
||||
const ControlLoopConfig::PathMonitorConfig& cfg = config_.path_monitor;
|
||||
|
||||
// Cổng vào: chỉ giám sát khi thực sự đang bám một plan của một profile được phép, với dữ liệu còn
|
||||
// dùng được. Thiếu bất kỳ điều kiện nào thì XOÁ luôn trạng thái debounce — nếu chỉ bỏ qua, chuỗi
|
||||
// "đúng liên tục" sẽ được nối lại qua một quãng gián đoạn và `confirm_time` mất ý nghĩa.
|
||||
const bool monitorable = cfg.enabled && deps_.path_check != nullptr && has_active_request_ &&
|
||||
pose_available && !costmap_stale && !latest_plan_.empty() &&
|
||||
state_machine_.state() == NavigationState::kControlling &&
|
||||
cfg.monitors(active_request_.profile);
|
||||
|
||||
if (!monitorable)
|
||||
{
|
||||
resetPathMonitor();
|
||||
return;
|
||||
}
|
||||
|
||||
// Route rỗng = KHÔNG có đường xử lý cho trigger đó. Khai hoả trong tình trạng này là biến một cơ
|
||||
// chế đang tắt thành ABORT tức thì: state machine thấy cờ, gọi escalateToRecovery, route cạn ngay
|
||||
// từ phần tử đầu, và chặng chết ngay lần đầu thấy vật cản. Giám sát cái mà không ai xử lý được
|
||||
// thì thà đừng giám sát — để `controller_patience` lo như trước khi có cơ chế này.
|
||||
//
|
||||
// Ba nút độc lập cho mỗi phép đo, cố ý: cờ riêng (`path_blocked_enabled`/`off_path_enabled`,
|
||||
// 2026-08-06 — nói thẳng ý định thay vì đặt ngưỡng về 0), ngưỡng của chính nó, và route.
|
||||
const bool blocked_route_ready = cfg.path_blocked_enabled &&
|
||||
!config_.state_machine.recovery_routes.path_blocked.empty();
|
||||
const bool off_path_route_ready = cfg.off_path_enabled &&
|
||||
!config_.state_machine.recovery_routes.off_path.empty();
|
||||
|
||||
// Nhịp quét riêng: đọc vài chục ô costmap mỗi control cycle 30 Hz là phí, mà vật cản cũng không
|
||||
// xuất hiện nhanh hơn chu kỳ cập nhật costmap (6 Hz).
|
||||
if (has_last_path_check_ && (now - last_path_check_).toSec() < cfg.check_period)
|
||||
{
|
||||
return;
|
||||
}
|
||||
last_path_check_ = now;
|
||||
has_last_path_check_ = true;
|
||||
|
||||
const std::size_t from = nearestIndex(latest_plan_, robot_pose);
|
||||
|
||||
// --- Phép đo 1: tuyến phía trước có bị chắn không -------------------------------------------
|
||||
const bool blocked_now = blocked_route_ready && planIsBlocked(latest_plan_, from);
|
||||
if (blocked_now)
|
||||
{
|
||||
if (!blocked_seen_)
|
||||
{
|
||||
blocked_since_ = now;
|
||||
blocked_seen_ = true;
|
||||
}
|
||||
if (!path_blocked_ && (now - blocked_since_).toSec() >= cfg.confirm_time)
|
||||
{
|
||||
path_blocked_ = true;
|
||||
robot::log_warning("[move_base2] PathMonitor: the path ahead is blocked at %.2f m (horizon "
|
||||
"%.2f m) — stopping to plan a detour.\n",
|
||||
last_block_distance_, cfg.horizon);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
blocked_seen_ = false;
|
||||
path_blocked_ = false;
|
||||
}
|
||||
|
||||
// --- Phép đo 2: robot đã lệch khỏi plan bao xa ----------------------------------------------
|
||||
//
|
||||
// Đo so với PLAN ĐANG CHẠY, không phải tuyến gốc của order: sau một lượt detour hợp lệ, plan đang
|
||||
// chạy CHÍNH LÀ đường vòng và robot nằm trên nó, nên không khai hoả oan. Ràng buộc "lệch bao
|
||||
// nhiêu so với tuyến fleet" là việc của `max_deviation` bên trong behavior detour.
|
||||
const bool grace = has_last_plan_applied_ &&
|
||||
(now - last_plan_applied_).toSec() < cfg.grace_after_new_plan;
|
||||
|
||||
if (off_path_route_ready && cfg.max_cross_track > 0.0 && !grace)
|
||||
{
|
||||
const double error = crossTrackError(latest_plan_, robot_pose); // [m]
|
||||
if (error > cfg.max_cross_track)
|
||||
{
|
||||
if (!off_path_seen_)
|
||||
{
|
||||
off_path_since_ = now;
|
||||
off_path_seen_ = true;
|
||||
}
|
||||
if (!off_path_ && (now - off_path_since_).toSec() >= cfg.confirm_time)
|
||||
{
|
||||
off_path_ = true;
|
||||
robot::log_warning("[move_base2] PathMonitor: the robot is %.2f m off the plan (limit "
|
||||
"%.2f m) — stopping.\n", error, cfg.max_cross_track);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
off_path_seen_ = false;
|
||||
off_path_ = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
off_path_seen_ = false;
|
||||
off_path_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ControlLoop::runController(robot_geometry_msgs::Twist& candidate)
|
||||
{
|
||||
candidate = robot_geometry_msgs::Twist();
|
||||
@@ -486,6 +777,15 @@ bool ControlLoop::step()
|
||||
travelled = std::hypot(dx, dy);
|
||||
}
|
||||
|
||||
// Costmap còn hạn không — hỏi ở ĐÂY chứ không ở mục 3.5 như trước: PathMonitor cần nó, mà monitor
|
||||
// phải chạy xong trước state machine. Vẫn là một lời gọi mỗi cycle, chỉ đổi vị trí.
|
||||
const bool costmap_stale = config_.require_current_costmap && deps_.costmap_status != nullptr &&
|
||||
!deps_.costmap_status->isCurrent();
|
||||
|
||||
// --- 1b. Giám sát tuyến ---------------------------------------------------------------------
|
||||
// Chạy TRƯỚC state machine: hai cờ nó sinh ra là dữ liệu vào của state machine ngay cycle này.
|
||||
updatePathMonitor(now, robot_pose, pose_available, costmap_stale);
|
||||
|
||||
// --- 2. State machine -----------------------------------------------------------------------
|
||||
StateMachineInput input;
|
||||
input.now = now;
|
||||
@@ -500,8 +800,11 @@ bool ControlLoop::step()
|
||||
input.recovery = recovery_feedback_;
|
||||
input.action = action_feedback_;
|
||||
input.pose_available = pose_available;
|
||||
input.costmap_current = !costmap_stale;
|
||||
input.robot_stopped = arbiter_.stopped();
|
||||
input.travelled_since_oscillation_reset = travelled;
|
||||
input.path_blocked = path_blocked_;
|
||||
input.off_path = off_path_;
|
||||
|
||||
// Cùng một chỉ số dùng cho cả cycle khởi động recovery lẫn các cycle tick: state machine chỉ tăng
|
||||
// chỉ số khi behavior kết thúc, nên `nextRecoveryIndex()` chính là behavior sắp chạy hoặc đang
|
||||
@@ -516,6 +819,11 @@ bool ControlLoop::step()
|
||||
if (output.state_changed)
|
||||
{
|
||||
last_reason_ = output.reason;
|
||||
robot::log_info("[move_base2][debug] state -> %s: %s "
|
||||
"(planner=%s controller=%s recovery=%s pose=%s active_request=%s).\n",
|
||||
toString(output.state), output.reason != nullptr ? output.reason : "",
|
||||
toString(input.planner), toString(input.controller), toString(input.recovery),
|
||||
pose_available ? "yes" : "no", has_active_request_ ? "yes" : "no");
|
||||
}
|
||||
|
||||
// Cờ một-lần đã được state machine tiêu thụ xong ở lời gọi trên.
|
||||
@@ -542,6 +850,7 @@ bool ControlLoop::step()
|
||||
has_active_request_ = true;
|
||||
has_pending_request_ = false;
|
||||
latest_plan_.clear();
|
||||
order_plan_.clear();
|
||||
has_outcome_ = false;
|
||||
|
||||
// Log một lần tại sườn nhận goal — không nằm trên đường lặp của control loop.
|
||||
@@ -563,6 +872,10 @@ bool ControlLoop::step()
|
||||
++plan_tag_;
|
||||
deps_.planner->cancelPlan();
|
||||
planner_running_ = false;
|
||||
|
||||
// Nhịp replan nền đếm lại từ đầu chặng — lượt plan đầu tiên của chặng do state machine yêu
|
||||
// cầu, replan nền chỉ bắt đầu sau đó một chu kỳ đầy đủ.
|
||||
last_plan_started_ = now;
|
||||
}
|
||||
|
||||
if (output.reset_oscillation_origin && pose_available)
|
||||
@@ -585,6 +898,28 @@ bool ControlLoop::step()
|
||||
{
|
||||
// Controller từ chối plan: coi như lần lập plan này hỏng, để chu kỳ kiên nhẫn tiếp tục chạy.
|
||||
planner_feedback_ = PlannerFeedback::kFailed;
|
||||
robot::log_error("[move_base2][debug] controller rejected plan with %zu pose(s); "
|
||||
"first=(%.3f, %.3f, frame=%s), last=(%.3f, %.3f, frame=%s).\n",
|
||||
latest_plan_.size(), latest_plan_.front().pose.position.x,
|
||||
latest_plan_.front().pose.position.y,
|
||||
latest_plan_.front().header.frame_id.c_str(),
|
||||
latest_plan_.back().pose.position.x, latest_plan_.back().pose.position.y,
|
||||
latest_plan_.back().header.frame_id.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Mốc cho `grace_after_new_plan`: ngay sau khi đổi plan, pose robot có thể còn lệch so với
|
||||
// plan vừa tới (rõ nhất lúc preempt/đổi chặng). Đo lệch tuyến ngay lúc đó là khai hoả oan.
|
||||
last_plan_applied_ = now;
|
||||
has_last_plan_applied_ = true;
|
||||
|
||||
robot::log_info("[move_base2][debug] controller accepted plan with %zu pose(s); "
|
||||
"first=(%.3f, %.3f, frame=%s), last=(%.3f, %.3f, frame=%s).\n",
|
||||
latest_plan_.size(), latest_plan_.front().pose.position.x,
|
||||
latest_plan_.front().pose.position.y,
|
||||
latest_plan_.front().header.frame_id.c_str(),
|
||||
latest_plan_.back().pose.position.x, latest_plan_.back().pose.position.y,
|
||||
latest_plan_.back().header.frame_id.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -593,6 +928,19 @@ bool ControlLoop::step()
|
||||
deps_.recovery->cancel();
|
||||
}
|
||||
|
||||
// Giám sát tuyến hết đường vòng (contract 2026-08-05e): KHÔNG kết thúc chặng — robot bám tiếp
|
||||
// plan cũ và trigger bị khoá tới khi đi được quá `oscillation_distance`. Log đúng MỘT dòng ở
|
||||
// sườn khoá, vì sau đó nhánh monitor im lặng hoàn toàn và người vận hành sẽ không hiểu vì sao
|
||||
// robot vẫn tiến về phía vật cản.
|
||||
if (output.monitor_trigger_suppressed)
|
||||
{
|
||||
robot::log_warning("[move_base2] %s: no detour left — continuing on the current plan. From "
|
||||
"here the controller is the only safety net: it stops at the obstacle and "
|
||||
"controller_patience escalates to controlling_failed. This trigger stays "
|
||||
"muted until the robot travels %.2f m.\n",
|
||||
toString(output.recovery_trigger), config_.state_machine.oscillation_distance);
|
||||
}
|
||||
|
||||
robot_geometry_msgs::Twist candidate;
|
||||
|
||||
if (output.start_recovery)
|
||||
@@ -628,6 +976,13 @@ bool ControlLoop::step()
|
||||
// Họ recovery sinh lại đường đi: coi kết quả như một plan mới, chờ state machine đẩy xuống.
|
||||
latest_plan_ = tick.path;
|
||||
planner_feedback_ = PlannerFeedback::kPlanReady;
|
||||
robot::log_info("[move_base2][debug] recovery produced path with %zu pose(s); "
|
||||
"first=(%.3f, %.3f, frame=%s), last=(%.3f, %.3f, frame=%s).\n",
|
||||
latest_plan_.size(), latest_plan_.front().pose.position.x,
|
||||
latest_plan_.front().pose.position.y,
|
||||
latest_plan_.front().header.frame_id.c_str(),
|
||||
latest_plan_.back().pose.position.x, latest_plan_.back().pose.position.y,
|
||||
latest_plan_.back().header.frame_id.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -677,8 +1032,6 @@ bool ControlLoop::step()
|
||||
// nó đi là bịt mất lối phục hồi duy nhất còn tác dụng. Behavior họ velocity không bị thiệt vì
|
||||
// chúng đo tiến độ bằng POSE: robot không nhúc nhích thì chúng tự hết giờ và báo hỏng, chứ không
|
||||
// báo thành công nhầm.
|
||||
const bool costmap_stale = config_.require_current_costmap && deps_.costmap_status != nullptr &&
|
||||
!deps_.costmap_status->isCurrent();
|
||||
if (costmap_stale)
|
||||
{
|
||||
// Throttle: đây là vòng lặp điều khiển, và tình trạng này kéo dài hàng giây.
|
||||
@@ -687,12 +1040,67 @@ bool ControlLoop::step()
|
||||
"costmap is describing a past world).\n");
|
||||
}
|
||||
|
||||
if (output.state == NavigationState::kControlling && !pose_available)
|
||||
{
|
||||
robot::log_warning_throttle(
|
||||
kDebugControlLogThrottle,
|
||||
"[move_base2][debug] controller skipped while CONTROLLING: pose unavailable "
|
||||
"(reason=%s, controller_feedback_in=%s, recovery_cursor=%zu/%zu).\n",
|
||||
output.reason != nullptr ? output.reason : "", toString(input.controller),
|
||||
output.recovery_route_cursor, output.recovery_route_size);
|
||||
}
|
||||
|
||||
if (output.run_controller && costmap_stale)
|
||||
{
|
||||
robot::log_warning_throttle(
|
||||
kDebugControlLogThrottle,
|
||||
"[move_base2][debug] controller skipped while CONTROLLING: costmap stale "
|
||||
"(reason=%s, controller_feedback_in=%s, recovery_cursor=%zu/%zu).\n",
|
||||
output.reason != nullptr ? output.reason : "", toString(input.controller),
|
||||
output.recovery_route_cursor, output.recovery_route_size);
|
||||
}
|
||||
|
||||
if (output.run_controller && !costmap_stale)
|
||||
{
|
||||
runController(candidate);
|
||||
if (controller_feedback_ == ControllerFeedback::kNoValidCommand)
|
||||
{
|
||||
robot::log_warning_throttle(
|
||||
kDebugControlLogThrottle,
|
||||
"[move_base2][debug] controller returned no valid command "
|
||||
"(reason=%s, planner_in=%s, controller_in=%s, recovery_in=%s, pose=%s, "
|
||||
"recovery_cursor=%zu/%zu).\n",
|
||||
output.reason != nullptr ? output.reason : "", toString(input.planner),
|
||||
toString(input.controller), toString(input.recovery), pose_available ? "yes" : "no",
|
||||
output.recovery_route_cursor, output.recovery_route_size);
|
||||
}
|
||||
// else if (controller_feedback_ == ControllerFeedback::kCommandValid)
|
||||
// {
|
||||
// robot::log_info_throttle(kDebugControlLogThrottle,
|
||||
// "[move_base2][debug] controller command valid: v=%.3f wz=%.3f.\n",
|
||||
// candidate.linear.x, candidate.angular.z);
|
||||
// }
|
||||
}
|
||||
|
||||
if (output.start_planner && pose_available && !planner_running_)
|
||||
// Replan nền (contract 2026-08-04): đang bám plan và tới nhịp `planner_frequency` thì khởi động
|
||||
// một lượt lập plan mới trên thread planner. Plan mới về được kControlling nhận ngay (apply_plan)
|
||||
// mà KHÔNG đổi state — controller không dừng một cycle nào. Đây là cơ chế thay plan duy nhất
|
||||
// trong lúc chạy, vì controller hỏng không còn kéo máy về kPlanning nữa.
|
||||
//
|
||||
// Nhịp đếm lại mỗi lần (TÁI) vào kControlling: sau recovery bám tiếp plan cũ — hoặc nhận path
|
||||
// detour — plan đó phải sống được trọn một chu kỳ planner_frequency trước khi lượt replan nền
|
||||
// đầu tiên có quyền thay nó. Không đếm lại thì đồng hồ vẫn mang cả quãng thời gian nằm trong
|
||||
// recovery và replan nền nổ ngay cycle đầu sau khi quay lại, đè mất path detour vừa nộp.
|
||||
if (output.state_changed && output.state == NavigationState::kControlling)
|
||||
{
|
||||
last_plan_started_ = now;
|
||||
}
|
||||
|
||||
const bool periodic_replan_due =
|
||||
config_.planner_frequency > 0.0 && output.state == NavigationState::kControlling &&
|
||||
(now - last_plan_started_).toSec() >= 1.0 / config_.planner_frequency;
|
||||
|
||||
if ((output.start_planner || periodic_replan_due) && pose_available && !planner_running_)
|
||||
{
|
||||
// `start_planner` là tín hiệu MỨC ("hãy đang lập plan"), bật lại mỗi cycle chừng nào state
|
||||
// machine còn ở kPlanning — không phải sườn. Kick lại một lượt đang chạy sẽ vừa bị cổng từ
|
||||
@@ -702,10 +1110,15 @@ bool ControlLoop::step()
|
||||
const robot_protocol_msgs::Order* order =
|
||||
backup_global_planner_active_ ? nullptr : active_request_.order.get();
|
||||
planner_running_ = deps_.planner->startPlan(robot_pose, active_request_.goal, order, plan_tag_);
|
||||
if (!planner_running_)
|
||||
if (planner_running_)
|
||||
{
|
||||
last_plan_started_ = now;
|
||||
}
|
||||
else if (output.start_planner)
|
||||
{
|
||||
// Không khởi động được (chưa có planner, pose hỏng...). Coi như một lượt hỏng để đồng hồ
|
||||
// kiên nhẫn tiếp tục chạy, thay vì đứng im ở kPlanning vô hạn.
|
||||
// kiên nhẫn tiếp tục chạy, thay vì đứng im ở kPlanning vô hạn. Riêng replan NỀN không khởi
|
||||
// động được thì bỏ qua — plan cũ vẫn hiệu lực, nhịp sau thử lại.
|
||||
planner_feedback_ = PlannerFeedback::kFailed;
|
||||
}
|
||||
}
|
||||
@@ -737,6 +1150,17 @@ bool ControlLoop::step()
|
||||
static_cast<unsigned long long>(outgoing_mission_id));
|
||||
break;
|
||||
case NavigationOutcome::kFailed:
|
||||
if (output.reason != nullptr &&
|
||||
std::strcmp(output.reason, "no recovery behavior left") == 0)
|
||||
{
|
||||
robot::log_error("[move_base2][debug] abort detail: recovery route exhausted "
|
||||
"(trigger=%s cursor=%zu size=%zu, planner_in=%s, controller_in=%s, "
|
||||
"recovery_in=%s, pose=%s, costmap_current=%s).\n",
|
||||
toString(output.recovery_trigger), output.recovery_route_cursor,
|
||||
output.recovery_route_size, toString(input.planner),
|
||||
toString(input.controller), toString(input.recovery),
|
||||
pose_available ? "yes" : "no", costmap_stale ? "no" : "yes");
|
||||
}
|
||||
robot::log_error("[move_base2] Navigation failed (mission %llu: ABORTED): %s\n",
|
||||
static_cast<unsigned long long>(outgoing_mission_id),
|
||||
last_reason_ != nullptr ? last_reason_ : "");
|
||||
|
||||
Reference in New Issue
Block a user