This commit is contained in:
2026-08-10 21:50:42 +07:00
parent 65f8c7ce1c
commit a2a2ea2829
12 changed files with 713 additions and 74 deletions

View File

@@ -127,6 +127,42 @@ bool MissionLayer::submitGoal(const robot_geometry_msgs::PoseStamped& goal)
return true;
}
bool MissionLayer::submitInstantActions(const std::vector<robot_protocol_msgs::Action>& actions)
{
if (!started_ || !handles(mission_adapters::schema::kInstantAction))
{
return false;
}
if (actions.empty())
{
// Message rỗng không phải lệnh huỷ và cũng không phải lỗi hệ thống — nhưng nhận nó thì host sẽ
// ngồi chờ một kết quả không bao giờ tới, mà fleet lại đang chặn mọi lệnh khác để đợi.
robot::log_warning("[move_base2] MissionLayer: instantActions message carries no action.");
return false;
}
// Message instantActions LUÔN preempt, nên dòng này không phải "có thể có vấn đề" mà là "việc
// đang chạy SẼ bị huỷ". Với chuỗi instantActions trước đó thì đúng ý định. Với một order đang
// chạy thì đó là mất cả tuyến đường — fleet master hiện tại không gửi trong tình huống đó, và đây
// là dòng duy nhất chỉ ra ngày giả định ấy bị vi phạm.
//
// Throttle vì nếu giả định vỡ thì nó vỡ đều, và một dòng mỗi lần trong control loop sẽ nhấn chìm
// log.
if (manager_.hasMission())
{
robot::log_warning_throttle(5.0,
"[move_base2] MissionLayer: instantActions message (%zu action(s), "
"first '%s' id '%s') preempts the work already in the queue — if "
"that was a running order, the order is now cancelled",
actions.size(), actions.front().actionType.c_str(),
actions.front().actionId.c_str());
}
events_.instantActionsEvent(actions);
return true;
}
void MissionLayer::cancel()
{
if (started_)

View File

@@ -10,6 +10,7 @@
#include <cmath>
#include <mission_adapters/mission_request.h>
#include <robot_nav_2d_utils/conversions.h>
namespace move_base2
@@ -746,7 +747,11 @@ bool NavigationServer::removeAllData()
}
// ================================================================================================
// Sáu entry point di chuyển -> một NavigationRequest
// Hai entry point di chuyển -> một NavigationRequest
//
// Bốn entry point mang profile riêng (`dockTo` ×2, `moveStraightTo`, `rotateTo`) đã bị gỡ khỏi
// contract host: chúng submit thẳng vào lõi, bỏ qua mission layer. Docking/go-straight/rotate giờ
// đi qua `profile:` và `marker` của từng chặng trong order — xem MissionAdapterBridge::toProfile.
// ================================================================================================
bool NavigationServer::submit(const NavigationRequest& request)
@@ -814,51 +819,28 @@ bool NavigationServer::moveTo(const robot_protocol_msgs::Order& msg,
return submit(request);
}
bool NavigationServer::dockTo(const std::string& maker,
const robot_geometry_msgs::PoseStamped& goal,
double xy_goal_tolerance, double yaw_goal_tolerance)
bool NavigationServer::executeInstantActions(
const std::vector<robot_protocol_msgs::Action>& actions)
{
(void)xy_goal_tolerance;
(void)yaw_goal_tolerance;
NavigationRequest request;
request.profile = MotionProfile::kDocking;
request.goal = goal;
request.marker = maker;
return submit(request);
}
// KHÔNG có đường rơi xuống `submit()` như `moveTo`. Một instantAction chỉ có nghĩa khi mission
// layer nở nó theo bảng compound: đẩy thẳng xuống lõi sẽ biến `PickUp` thành một chặng chỉ-action
// không có bước dò và không có bước tiến vào, tức robot báo "đã nâng kệ" khi càng còn chưa tới
// gần kệ. Layer tắt thì phải từ chối để host báo FAILED ngay, thay vì chờ một kết quả không đến.
if (runtime_ == nullptr || !runtime_->missionLayer().submitInstantActions(actions))
{
const std::string first = actions.empty() ? std::string("<empty>") : actions.front().actionType;
bool NavigationServer::dockTo(const robot_protocol_msgs::Order& msg, const std::string& marker,
const robot_geometry_msgs::PoseStamped& goal,
double xy_goal_tolerance, double yaw_goal_tolerance)
{
(void)xy_goal_tolerance;
(void)yaw_goal_tolerance;
NavigationRequest request;
request.profile = MotionProfile::kDocking;
request.goal = goal;
request.marker = marker;
request.order = std::make_shared<robot_protocol_msgs::Order>(msg);
return submit(request);
}
last_reject_reason_ = "mission layer cannot accept instant actions";
nav_feedback_->feed_back_str =
"instant action '" + first + "' rejected: " + last_reject_reason_;
robot::log_error("[move_base2] instantActions message rejected (%zu action(s), first '%s') — "
"mission layer not running, empty message, or no source declares schema '%s'.",
actions.size(), first.c_str(), mission_adapters::schema::kInstantAction);
return false;
}
bool NavigationServer::moveStraightTo(const robot_geometry_msgs::PoseStamped& goal,
double xy_goal_tolerance)
{
(void)xy_goal_tolerance;
NavigationRequest request;
request.profile = MotionProfile::kGoStraight;
request.goal = goal;
return submit(request);
}
bool NavigationServer::rotateTo(const robot_geometry_msgs::PoseStamped& goal,
double yaw_goal_tolerance)
{
(void)yaw_goal_tolerance;
NavigationRequest request;
request.profile = MotionProfile::kRotate;
request.goal = goal;
return submit(request);
last_reject_reason_.clear();
return true;
}
// ================================================================================================