update
This commit is contained in:
@@ -10,8 +10,11 @@
|
||||
|
||||
#include <exception>
|
||||
|
||||
#include <boost/thread/locks.hpp>
|
||||
|
||||
#include <robot/node_handle.h>
|
||||
#include <robot/robot.h>
|
||||
#include <robot_costmap_2d/costmap_2d.h>
|
||||
#include <robot_nav_2d_utils/conversions.h>
|
||||
#include <tf3/buffer_core.h>
|
||||
|
||||
@@ -54,6 +57,36 @@ bool CostmapPosePort::lookupPose(const std::string& frame,
|
||||
}
|
||||
}
|
||||
|
||||
bool CostmapPathCheck::checkPlan(const std::vector<robot_geometry_msgs::PoseStamped>& plan,
|
||||
std::size_t from_index, double horizon,
|
||||
PlanBlockResult& out) const
|
||||
{
|
||||
if (costmap_ == nullptr || !tf_ || plan.empty() || from_index >= plan.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
robot_costmap_2d::Costmap2D* grid = costmap_->getCostmap();
|
||||
if (grid == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
PlanarTransform plan_to_grid;
|
||||
if (!planarTransform(*tf_, plan[from_index].header.frame_id, costmap_->getGlobalFrameID(),
|
||||
plan_to_grid))
|
||||
{
|
||||
// Không quy đổi được frame thì mọi kết luận đều vô nghĩa. Trả false = "không biết".
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cùng giao thức khoá với map-update thread và planner: lượt quét chỉ đọc vài chục ô nên giữ
|
||||
// mutex trọn lượt là rẻ, còn đọc lưới trong lúc nó đang được ghi thì kết luận không đáng tin.
|
||||
boost::unique_lock<robot_costmap_2d::Costmap2D::mutex_t> lock(*(grid->getMutex()));
|
||||
out = move_base2::checkPlan(plan, from_index, horizon, *grid, plan_to_grid);
|
||||
return true;
|
||||
}
|
||||
|
||||
NavigationRuntime::NavigationRuntime() = default;
|
||||
|
||||
NavigationRuntime::~NavigationRuntime()
|
||||
@@ -131,6 +164,10 @@ bool NavigationRuntime::buildCostmaps(const std::shared_ptr<tf3::BufferCore>& tf
|
||||
// Costmap ĐIỀU KHIỂN (local) là nguồn của guard "không đi mù" — xem doc của CostmapStatusAdapter.
|
||||
costmap_status_.setCostmap(local_costmap_.get());
|
||||
|
||||
// PathMonitor quét tuyến trên chính costmap local — cùng lưới mà detour lập đường vòng trên đó.
|
||||
path_check_.setCostmap(local_costmap_.get());
|
||||
path_check_.setTf(tf_);
|
||||
|
||||
// Gắn ngay: host có thể hỏi dữ liệu hiển thị bất cứ lúc nào sau initialize(), kể cả trước khi
|
||||
// costmap có nội dung. Exporter tự trả về "chưa có gì" thay vì lưới rỗng.
|
||||
global_exporter_.attach(global_costmap_.get(), config_.global_frame);
|
||||
@@ -189,6 +226,9 @@ bool NavigationRuntime::buildRunners(std::string& error)
|
||||
recovery_deps.pose = &local_pose_;
|
||||
recovery_deps.local_costmap = local_costmap_.get();
|
||||
recovery_deps.global_costmap = global_costmap_.get();
|
||||
// Behavior họ path (DetourPathRecovery) lập đường vòng trên local costmap (frame odom) trong khi
|
||||
// plan ở frame map — cần TF để quy đổi hai chiều.
|
||||
recovery_deps.tf = tf_.get();
|
||||
recovery_.setDeps(recovery_deps);
|
||||
recovery_.setNamespace(config_.recovery_namespace);
|
||||
|
||||
@@ -370,6 +410,7 @@ ControlLoopDeps NavigationRuntime::deps()
|
||||
deps.mission = &mission_;
|
||||
deps.action = &action_;
|
||||
deps.costmap_status = &costmap_status_;
|
||||
deps.path_check = &path_check_;
|
||||
return deps;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user