optimal
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
||||
#include <robot/console.h>
|
||||
|
||||
namespace move_base2
|
||||
{
|
||||
namespace
|
||||
@@ -400,6 +402,13 @@ bool ControlLoop::step()
|
||||
action_feedback_ = ActionFeedback::kIdle;
|
||||
|
||||
// --- 3. Thi hành output ---------------------------------------------------------------------
|
||||
// Nhãn của yêu cầu SẮP bị thay. Preempt bật cả `report_outcome` lẫn `accept_request` trong cùng
|
||||
// một cycle, mà phần báo kết quả nằm sau phần nhận yêu cầu — không giữ lại id cũ ở đây thì kết
|
||||
// quả của chặng cũ sẽ được báo dưới id của chặng MỚI, và mission layer mất dấu cả hai.
|
||||
const std::uint64_t outgoing_mission_id =
|
||||
has_active_request_ ? active_request_.mission_sequence_id : 0;
|
||||
const bool had_active_request = has_active_request_;
|
||||
|
||||
if (output.accept_request)
|
||||
{
|
||||
active_request_ = pending_request_;
|
||||
@@ -408,6 +417,21 @@ bool ControlLoop::step()
|
||||
latest_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.
|
||||
if (active_request_.has_goal)
|
||||
{
|
||||
robot::log_info("[move_base2] Nhận goal (mission %llu): x=%.3f y=%.3f frame=%s.\n",
|
||||
static_cast<unsigned long long>(active_request_.mission_sequence_id),
|
||||
active_request_.goal.pose.position.x, active_request_.goal.pose.position.y,
|
||||
active_request_.goal.header.frame_id.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
robot::log_info("[move_base2] Nhận yêu cầu chỉ-action (mission %llu), %zu action.\n",
|
||||
static_cast<unsigned long long>(active_request_.mission_sequence_id),
|
||||
active_request_.actions.size());
|
||||
}
|
||||
|
||||
// Nhãn mới: mọi lượt lập plan đang bay thuộc về goal cũ và phải bị vứt khi về.
|
||||
++plan_tag_;
|
||||
deps_.planner->cancelPlan();
|
||||
@@ -546,19 +570,49 @@ bool ControlLoop::step()
|
||||
has_outcome_ = true;
|
||||
++outcome_report_count_;
|
||||
|
||||
if (deps_.mission != nullptr && has_active_request_ &&
|
||||
active_request_.mission_sequence_id != 0)
|
||||
// Log kết cục ra terminal — bản cũ báo "Goal reached!" tại đây, host và người vận hành đều
|
||||
// dựa vào dòng này để biết chặng kết thúc ra sao. Chỉ chạy đúng một lần mỗi chặng.
|
||||
switch (output.outcome)
|
||||
{
|
||||
deps_.mission->reportOutcome(active_request_.mission_sequence_id, output.outcome);
|
||||
case NavigationOutcome::kSucceeded:
|
||||
robot::log_success("[move_base2] Goal reached (mission %llu).\n",
|
||||
static_cast<unsigned long long>(outgoing_mission_id));
|
||||
break;
|
||||
case NavigationOutcome::kPreempted:
|
||||
robot::log_info("[move_base2] Goal bị thay bởi goal mới (mission %llu: PREEMPTED).\n",
|
||||
static_cast<unsigned long long>(outgoing_mission_id));
|
||||
break;
|
||||
case NavigationOutcome::kCancelled:
|
||||
robot::log_info("[move_base2] Goal bị huỷ (mission %llu: CANCELLED).\n",
|
||||
static_cast<unsigned long long>(outgoing_mission_id));
|
||||
break;
|
||||
case NavigationOutcome::kFailed:
|
||||
robot::log_error("[move_base2] Navigation thất bại (mission %llu: ABORTED): %s\n",
|
||||
static_cast<unsigned long long>(outgoing_mission_id),
|
||||
last_reason_ != nullptr ? last_reason_ : "");
|
||||
break;
|
||||
}
|
||||
|
||||
has_active_request_ = false;
|
||||
if (deps_.mission != nullptr && had_active_request && outgoing_mission_id != 0)
|
||||
{
|
||||
deps_.mission->reportOutcome(outgoing_mission_id, output.outcome);
|
||||
}
|
||||
|
||||
// Preempt vừa báo kết quả chặng cũ VỪA nhận chặng mới trong cùng cycle. Chỉ xoá yêu cầu đang
|
||||
// chạy khi thực sự không có chặng mới nào thay thế.
|
||||
if (!output.accept_request)
|
||||
{
|
||||
has_active_request_ = false;
|
||||
latest_plan_.clear();
|
||||
planner_running_ = false;
|
||||
}
|
||||
cancel_requested_ = false;
|
||||
latest_plan_.clear();
|
||||
planner_running_ = false;
|
||||
}
|
||||
|
||||
return !output.report_outcome;
|
||||
// false = "yêu cầu hiện tại vừa kết thúc, không còn gì để chạy". Preempt CŨNG báo kết quả (cho
|
||||
// chặng cũ) nhưng ngay lập tức nhận chặng mới — lúc đó runtime vẫn đang chạy, nên không được trả
|
||||
// false. Điều kiện đúng là "vào state terminal", không phải "có báo kết quả".
|
||||
return !isTerminal(output.state);
|
||||
}
|
||||
|
||||
const char* ControlLoop::lastOutcome() const
|
||||
|
||||
Reference in New Issue
Block a user