refactor: xoá PathMonitor và PathCheckPort, EnvMonitor là bộ giám sát duy nhất; gộp refreshSnapshot
Xoá hạ tầng giám sát cũ đã tắt từ 5/9 (path_monitor/enabled: false), −2947 dòng: - ControlLoop: PathMonitorConfig, updatePathMonitor / updateProgressMonitor / applyCollisionGuard / planIsBlocked / resetPathMonitor / rebuildPlanArcLength, toàn bộ member bốn phép đo, luật "plan mới bẩn thì giữ plan cũ" trong collectPlannerResult. Bốn cổng StateMachineInput giữ nguyên (off_path không còn nguồn, đặt false). - ports/path_check_port.h, CostmapPathCheck trong NavigationRuntime. - plan_inspector: bỏ checkPlan / checkMotion / PlanBlockResult / MotionCheckParams / MotionBlockResult; giữ planarTransform, nearestIndex, trackedNearestIndex, crossTrackError. - Config: readPathMonitor, MoveBase2Config::path_monitor, validate; xoá config/runtime/path_monitor_params.yaml; comment YAML/state_machine đổi sang tên verdict EnvMonitor. - Test: FakePathCheckPort, 30 test WalkingSkeletonPathMonitor/CollisionGuard, 13 test PlanInspectorCheck/Motion, 2 test validate thân guard. P0(b): ControlLoop::step() gọi EnvironmentPort::refresh() một lần đầu cycle (không phụ thuộc env_monitor/enabled); ControllerRunner::setSnapshotRefreshedByLoop(true) làm ba refreshSnapshot() trong runner thành no-op — monitor và controller đọc cùng một lưới, một bản copy mỗi cycle. Test: env_monitor 43, grid_analysis 33, plan_inspector 11, walking_skeleton 57, config_validation 32, scenario 12, state_machine 100, navigation_server 56, controller_runner 28, velocity_arbiter 29, planner_runner 31 — pass. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017xXjFjr2DQ6rhmhHSW4fk4
This commit is contained in:
@@ -65,107 +65,6 @@ 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;
|
||||
}
|
||||
|
||||
bool CostmapPathCheck::checkMotion(const robot_geometry_msgs::PoseStamped& robot_pose, double v,
|
||||
double omega, const MotionCheckParams& params,
|
||||
MotionBlockResult& out) const
|
||||
{
|
||||
if (costmap_ == nullptr || !tf_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
robot_costmap_2d::Costmap2D* grid = costmap_->getCostmap();
|
||||
if (grid == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Pose robot ở frame của cổng pose (thường `map`), lưới ở `odom`: quy đổi cả vị trí lẫn hướng
|
||||
// rồi tích phân cung ngay trong frame lưới — mỗi mẫu không phải tra TF lần nữa.
|
||||
PlanarTransform pose_to_grid;
|
||||
if (!planarTransform(*tf_, robot_pose.header.frame_id, costmap_->getGlobalFrameID(),
|
||||
pose_to_grid))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
double gx = 0.0;
|
||||
double gy = 0.0;
|
||||
pose_to_grid.apply(robot_pose.pose.position.x, robot_pose.pose.position.y, gx, gy);
|
||||
const auto& q = robot_pose.pose.orientation;
|
||||
const double yaw_pose = std::atan2(2.0 * (q.w * q.z + q.x * q.y),
|
||||
1.0 - 2.0 * (q.y * q.y + q.z * q.z));
|
||||
const double yaw_grid = yaw_pose + std::atan2(pose_to_grid.sin_yaw, pose_to_grid.cos_yaw);
|
||||
|
||||
boost::unique_lock<robot_costmap_2d::Costmap2D::mutex_t> lock(*(grid->getMutex()));
|
||||
out = move_base2::checkMotion(gx, gy, yaw_grid, v, omega, params, *grid, &baseline_scratch_);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CostmapPathCheck::robotBodyExtents(double& front, double& rear, double& side) const
|
||||
{
|
||||
if (costmap_ == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Footprint KHÔNG đệm: guard có collision_footprint_padding riêng, cộng đệm costmap vào nữa là
|
||||
// đếm biên hai lần. Đây cũng là hình mà SBPL/PRIEST dùng, nên ba bên cùng một thân.
|
||||
const std::vector<robot_geometry_msgs::Point>& fp = costmap_->getUnpaddedRobotFootprint();
|
||||
if (fp.size() < 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
double max_x = std::numeric_limits<double>::lowest();
|
||||
double min_x = std::numeric_limits<double>::max();
|
||||
double max_abs_y = 0.0;
|
||||
for (const robot_geometry_msgs::Point& p : fp)
|
||||
{
|
||||
if (!std::isfinite(p.x) || !std::isfinite(p.y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
max_x = std::max(max_x, p.x);
|
||||
min_x = std::min(min_x, p.x);
|
||||
max_abs_y = std::max(max_abs_y, std::fabs(p.y));
|
||||
}
|
||||
if (!(max_x > 0.0) || !(min_x < 0.0) || !(max_abs_y > 0.0))
|
||||
{
|
||||
return false; // suy biến hoặc base_link nằm ngoài thân — không tin được
|
||||
}
|
||||
front = max_x;
|
||||
rear = -min_x;
|
||||
side = max_abs_y;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// CostmapEnvironment
|
||||
// ================================================================================================
|
||||
@@ -480,12 +379,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_);
|
||||
|
||||
// EnvMonitor đọc cùng costmap local (thay PathMonitor); TF để quy plan (map) và pose về frame lưới.
|
||||
// EnvMonitor đọc costmap local — cùng lưới mà detour lập đường vòng trên đó; TF để quy plan (map) và
|
||||
// pose về frame lưới.
|
||||
environment_.setCostmap(local_costmap_.get());
|
||||
controller_.setSnapshotRefreshedByLoop(true); // ControlLoop làm mới snapshot một lần đầu cycle (P0b)
|
||||
environment_.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
|
||||
@@ -736,7 +633,6 @@ ControlLoopDeps NavigationRuntime::deps()
|
||||
deps.mission = &mission_;
|
||||
deps.action = &action_;
|
||||
deps.costmap_status = &costmap_status_;
|
||||
deps.path_check = &path_check_;
|
||||
deps.environment = &environment_;
|
||||
return deps;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user