feat(planner_runner): bind dock_face_offset and dock_pivot_safety_margin per marker
Two new DockPlanner keys, valid only with dock_anchor: mating_edge, are copied from docking_marker_profiles/<marker> into the planner namespace like footprint_dock and dock_anchor. Unlike those two, the new keys are optional. A marker that does not declare one would keep the value bound by the previous marker, so the charger's smaller pivot margin could leak into a later trolley docking. When the marker lacks a key that the planner namespace still holds, the binder writes a YAML null, which DockPlanner reads as unset, and counts it as a change so that the instance is rebuilt. footprint_dock and dock_anchor keep their old behaviour.
This commit is contained in:
@@ -43,14 +43,22 @@ bool isFinitePose(const robot_geometry_msgs::PoseStamped& pose)
|
||||
/// hai công thức khác nhau, trùng tên là mời gọi đặt nhầm giá trị.
|
||||
///
|
||||
/// `dock_anchor` khai goal pose của marker nằm ở tâm footprint dock (`center`) hay ngay trên mặt
|
||||
/// tiếp cận (`face`). `face` thì DockPlanner bỏ qua `footprint_dock` hoàn toàn.
|
||||
/// tiếp cận (`face`). `mating_edge` dùng goal đã offset tới pose base_link lúc dock xong;
|
||||
/// `face` và `mating_edge` khiến DockPlanner bỏ qua `footprint_dock` hoàn toàn.
|
||||
/// `dock_face_offset` và `dock_pivot_safety_margin` là override DockPlanner chỉ có tác dụng với
|
||||
/// `dock_anchor: mating_edge`; khai với `center` hoặc `face` khiến DockPlanner từ chối khởi tạo.
|
||||
/// Nếu marker sau không khai, giá trị cũ được đặt YAML null để plugin trở về mặc định.
|
||||
///
|
||||
/// KHÔNG có `terminal_direction` ở đây, và cố ý như vậy: chiều chạy của đoạn thẳng cuối được SUY RA
|
||||
/// từ phía robot đứng so với goal (`dock_calc.cpp`), vì tầng trên đã offset goal sao cho base_link
|
||||
/// dừng đúng tại đó khi manơ hoàn tất. Một khoá cho phép marker ép chiều khác sẽ mâu thuẫn với
|
||||
/// chính vị trí goal, nên khoá đó đã được gỡ thay vì hiện thực.
|
||||
constexpr const char* kMarkerPlannerParams[] = {
|
||||
"footprint_dock", "dock_anchor"
|
||||
"footprint_dock", "dock_anchor", "dock_face_offset", "dock_pivot_safety_margin"
|
||||
};
|
||||
|
||||
constexpr const char* kOptionalMarkerPlannerParams[] = {
|
||||
"dock_face_offset", "dock_pivot_safety_margin"
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -312,36 +320,54 @@ bool PlannerRunner::bindDockingMarker(const std::string& marker, const std::stri
|
||||
}
|
||||
|
||||
const std::string profile_ns = "docking_marker_profiles/" + marker;
|
||||
if (!nh_.hasParam(profile_ns))
|
||||
{
|
||||
// Marker hợp lệ nhưng không có profile riêng: cặp planner mặc định, không có gì để chép. Không
|
||||
// phải lỗi — `maker_sources` mới là allow-list, bảng profile chỉ là override.
|
||||
return true;
|
||||
}
|
||||
const bool has_profile = nh_.hasParam(profile_ns);
|
||||
|
||||
// Namespace phải được kiểm TRƯỚC khi dựng NodeHandle: `robot::NodeHandle` không báo lỗi khi
|
||||
// namespace không resolve được mà lặng lẽ rơi về namespace cha. Bỏ qua bước này thì marker gõ sai
|
||||
// sẽ đọc `footprint` ở ROOT — tức footprint ROBOT — rồi dùng nó làm kích thước trạm dock.
|
||||
robot::NodeHandle marker_nh(nh_, profile_ns);
|
||||
robot::NodeHandle planner_nh(nh_, planner_name);
|
||||
if (marker_nh.getNamespace() == nh_.getNamespace() ||
|
||||
planner_nh.getNamespace() == nh_.getNamespace())
|
||||
const bool marker_namespace_invalid =
|
||||
has_profile && marker_nh.getNamespace() == nh_.getNamespace();
|
||||
const bool planner_namespace_invalid =
|
||||
planner_nh.getNamespace() == nh_.getNamespace();
|
||||
if (marker_namespace_invalid || (has_profile && planner_namespace_invalid))
|
||||
{
|
||||
robot::log_error("[move_base2] PlannerRunner: namespace '%s' or '%s' does not resolve in the "
|
||||
"param tree; refusing to bind marker '%s'.\n",
|
||||
profile_ns.c_str(), planner_name.c_str(), marker.c_str());
|
||||
return false;
|
||||
}
|
||||
if (!has_profile && planner_namespace_invalid)
|
||||
{
|
||||
// Marker hợp lệ nhưng không có profile riêng: giữ nguyên hành vi cũ nếu planner namespace
|
||||
// chưa tồn tại; không có nơi an toàn để xoá override per-marker.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool copied = false;
|
||||
for (const char* key : kMarkerPlannerParams)
|
||||
if (has_profile)
|
||||
{
|
||||
copied = copyParamNode(marker_nh, planner_nh, key) || copied;
|
||||
for (const char* key : kMarkerPlannerParams)
|
||||
{
|
||||
copied = copyParamNode(marker_nh, planner_nh, key) || copied;
|
||||
}
|
||||
}
|
||||
|
||||
for (const char* key : kOptionalMarkerPlannerParams)
|
||||
{
|
||||
if ((!has_profile || !marker_nh.hasParam(key)) && planner_nh.hasParam(key))
|
||||
{
|
||||
// Không để override rò sang marker trước: DockPlannerConfig đọc YAML null như chưa khai.
|
||||
// footprint_dock và dock_anchor giữ nguyên cách xử lý cũ.
|
||||
planner_nh.setParam(key, YAML::Node(YAML::NodeType::Null));
|
||||
copied = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!copied)
|
||||
{
|
||||
return true; // Profile có tồn tại nhưng không khai khoá nào của planner — giữ nguyên cấu hình.
|
||||
return true; // Không có khoá planner mới hoặc override tuỳ chọn nào cần xoá.
|
||||
}
|
||||
|
||||
// Dựng lại instance CHỈ khi marker nối vào planner này thực sự đổi. Dock lại đúng marker cũ thì
|
||||
|
||||
Reference in New Issue
Block a user