optimal & fix file cmake

This commit is contained in:
2026-08-03 22:41:32 +07:00
parent d8babff20b
commit 701d25f952
70 changed files with 5572 additions and 1146 deletions

View File

@@ -52,13 +52,20 @@ PlannerRunner::~PlannerRunner()
}
}
void PlannerRunner::attachStats(RuntimeStats* stats)
{
stats_ = stats;
section_make_plan_ = (stats_ != nullptr) ? stats_->section("planner.makePlan")
: RuntimeStats::kInvalidSection;
}
bool PlannerRunner::configure(const robot::NodeHandle& nh,
robot_costmap_2d::Costmap2DROBOT* costmap,
const std::string& initial_planner, std::string& error)
{
if (configured_)
{
error = "PlannerRunner::configure() gọi lần thứ hai";
error = "PlannerRunner::configure() called twice";
return false;
}
@@ -66,7 +73,7 @@ bool PlannerRunner::configure(const robot::NodeHandle& nh,
{
// Không có costmap thì `BaseGlobalPlanner::initialize` nhận nullptr và mọi plugin tự quyết định
// làm gì với nó — thường là sập. Chặn ở đây, nơi còn nói được lý do.
error = "PlannerRunner cần costmap global khác null";
error = "PlannerRunner needs a non-null global costmap";
return false;
}
@@ -76,7 +83,7 @@ bool PlannerRunner::configure(const robot::NodeHandle& nh,
if (!initial_planner.empty() && !swapPlanner(initial_planner))
{
error = "không nạp được global planner khởi đầu '" + initial_planner + "'";
error = "could not load the initial global planner '" + initial_planner + "'";
configured_ = false;
return false;
}
@@ -102,8 +109,8 @@ robot_nav_core::BaseGlobalPlanner* PlannerRunner::acquire(const std::string& nam
if (library_path.empty())
{
robot::log_error("[move_base2] PlannerRunner: không tìm được thư viện cho '%s' — kiểm khoá "
"'%s/library_path' trong YAML và sự tồn tại của file .so trong devel/lib.\n",
robot::log_error("[move_base2] PlannerRunner: no library found for '%s' — check the key "
"'%s/library_path' in the YAML and that the .so file exists in devel/lib.\n",
name.c_str(), name.c_str());
return nullptr;
}
@@ -117,13 +124,14 @@ robot_nav_core::BaseGlobalPlanner* PlannerRunner::acquire(const std::string& nam
}
catch (const boost::system::system_error& ex)
{
robot::log_error("[move_base2] PlannerRunner: không nạp được symbol '%s' từ '%s': %s\n",
robot::log_error("[move_base2] PlannerRunner: could not load symbol '%s' from '%s': %s\n",
name.c_str(), library_path.c_str(), ex.what());
return nullptr;
}
catch (const std::exception& ex)
{
robot::log_error("[move_base2] PlannerRunner: lỗi khi nạp '%s': %s\n", name.c_str(), ex.what());
robot::log_error("[move_base2] PlannerRunner: error while loading '%s': %s\n",
name.c_str(), ex.what());
return nullptr;
}
@@ -133,14 +141,15 @@ robot_nav_core::BaseGlobalPlanner* PlannerRunner::acquire(const std::string& nam
}
catch (const std::exception& ex)
{
robot::log_error("[move_base2] PlannerRunner: factory của '%s' ném exception: %s\n",
robot::log_error("[move_base2] PlannerRunner: factory of '%s' threw an exception: %s\n",
name.c_str(), ex.what());
return nullptr;
}
if (!loaded.instance)
{
robot::log_error("[move_base2] PlannerRunner: factory của '%s' trả nullptr.\n", name.c_str());
robot::log_error("[move_base2] PlannerRunner: factory of '%s' returned nullptr.\n",
name.c_str());
return nullptr;
}
@@ -151,7 +160,7 @@ robot_nav_core::BaseGlobalPlanner* PlannerRunner::acquire(const std::string& nam
}
catch (const std::exception& ex)
{
robot::log_error("[move_base2] PlannerRunner: initialize() của '%s' ném exception: %s\n",
robot::log_error("[move_base2] PlannerRunner: initialize() of '%s' threw an exception: %s\n",
name.c_str(), ex.what());
return nullptr;
}
@@ -160,7 +169,8 @@ robot_nav_core::BaseGlobalPlanner* PlannerRunner::acquire(const std::string& nam
{
// Bản cũ chỉ log rồi đi tiếp với một planner chưa khởi tạo. Ở đây coi là thất bại: một planner
// báo "tôi chưa sẵn sàng" mà vẫn được gọi makePlan là đường dẫn tới hành vi không xác định.
robot::log_error("[move_base2] PlannerRunner: '%s' báo initialize() thất bại.\n", name.c_str());
robot::log_error("[move_base2] PlannerRunner: '%s' reported an initialize() failure.\n",
name.c_str());
return nullptr;
}
@@ -174,13 +184,13 @@ bool PlannerRunner::swapPlanner(const std::string& planner_name)
{
if (!configured_)
{
robot::log_error("[move_base2] PlannerRunner: swapPlanner() trước configure().\n");
robot::log_error("[move_base2] PlannerRunner: swapPlanner() before configure().\n");
return false;
}
if (planner_name.empty())
{
robot::log_error("[move_base2] PlannerRunner: tên planner rỗng.\n");
robot::log_error("[move_base2] PlannerRunner: empty planner name.\n");
return false;
}
@@ -213,7 +223,7 @@ bool PlannerRunner::swapPlanner(const std::string& planner_name)
}
active_name_ = planner_name;
robot::log_info("[move_base2] PlannerRunner: global planner đang dùng là '%s'.\n",
robot::log_info("[move_base2] PlannerRunner: active global planner is '%s'.\n",
planner_name.c_str());
return true;
}
@@ -234,14 +244,14 @@ bool PlannerRunner::startPlan(const robot_geometry_msgs::PoseStamped& start,
{
if (!configured_)
{
robot::log_error_throttle(5.0, "[move_base2] PlannerRunner: startPlan() trước configure().\n");
robot::log_error_throttle(5.0, "[move_base2] PlannerRunner: startPlan() before configure().\n");
return false;
}
if (!isFinitePose(start) || !isFinitePose(goal))
{
robot::log_error_throttle(5.0, "[move_base2] PlannerRunner: start hoặc goal chứa NaN/Inf, "
"không khởi động lượt lập plan.\n");
robot::log_error_throttle(5.0, "[move_base2] PlannerRunner: start or goal contains NaN/Inf, "
"not starting a planning attempt.\n");
return false;
}
@@ -249,7 +259,8 @@ bool PlannerRunner::startPlan(const robot_geometry_msgs::PoseStamped& start,
if (active_ == nullptr)
{
robot::log_error_throttle(5.0, "[move_base2] PlannerRunner: startPlan() khi chưa có planner.\n");
robot::log_error_throttle(5.0, "[move_base2] PlannerRunner: startPlan() with no planner "
"loaded.\n");
return false;
}
@@ -317,6 +328,12 @@ void PlannerRunner::cancelPlan()
void PlannerRunner::threadBody()
{
if (stats_ != nullptr)
{
// Phải đăng ký TỪ chính thread này: nhãn được gắn theo tid của thread đang chạy.
stats_->registerCurrentThread("move_base2/planner");
}
std::unique_lock<std::mutex> lock(mutex_);
while (true)
@@ -346,6 +363,7 @@ void PlannerRunner::threadBody()
try
{
ScopedSection timer(stats_, section_make_plan_);
// Hai overload của interface gốc gộp lại: "có Order hay không" là một nhánh, không phải hai
// contract. Plugin nào không hiểu Order thì overload mặc định của nó tự lo.
ok = (order != nullptr) ? planner->makePlan(*order, start, goal, planning_)
@@ -355,14 +373,14 @@ void PlannerRunner::threadBody()
{
// Plugin bên thứ ba ném ra thì đây là biên duy nhất chặn được — exception thoát khỏi thân
// thread là std::terminate, tức mất cả tiến trình navigation vì một lượt lập plan hỏng.
robot::log_error_throttle(5.0, "[move_base2] PlannerRunner: plugin ném exception khi lập "
"plan: %s\n", ex.what());
robot::log_error_throttle(5.0, "[move_base2] PlannerRunner: plugin threw an exception while "
"making a plan: %s\n", ex.what());
ok = false;
}
catch (...)
{
robot::log_error_throttle(5.0, "[move_base2] PlannerRunner: plugin ném exception lạ khi lập "
"plan.\n");
robot::log_error_throttle(5.0, "[move_base2] PlannerRunner: plugin threw an unknown "
"exception while making a plan.\n");
ok = false;
}