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:
2026-10-29 16:54:02 +07:00
parent c3c64919d3
commit 75af8ccf12
2 changed files with 84 additions and 13 deletions

View File

@@ -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ì

View File

@@ -774,6 +774,51 @@ TEST(PlannerRunnerDockingMarker, ProfileWithoutFootprintDockIsAcceptedAndChanges
EXPECT_EQ(pluginInitializeCount(), before);
}
TEST(PlannerRunnerDockingMarker, CopiesAndClearsOptionalDockOverridesPerMarker)
{
Fixture fixture;
ASSERT_TRUE(fixture.ok()) << fixture.error();
robot::NodeHandle nh;
// Create isolated profiles in the shared test parameter tree so this test does not alter the
// checked-in fixture or affect the existing dock_a/dock_b footprint tests.
nh.setParam("docking_marker_profiles/dock_override/dock_face_offset", 0.40);
nh.setParam("docking_marker_profiles/dock_override/dock_pivot_safety_margin", 0.10);
nh.setParam("docking_marker_profiles/dock_no_override/global_planner",
YAML::Node("TestPlannerOk"));
const std::size_t before = pluginInitializeCount();
ASSERT_TRUE(fixture.runner_.bindDockingMarker("dock_override", "TestPlannerOk"));
YAML::Node copied_face_offset;
YAML::Node copied_margin;
ASSERT_TRUE(nh.getParam("TestPlannerOk/dock_face_offset", copied_face_offset));
ASSERT_TRUE(nh.getParam("TestPlannerOk/dock_pivot_safety_margin", copied_margin));
EXPECT_DOUBLE_EQ(copied_face_offset.as<double>(), 0.40);
EXPECT_DOUBLE_EQ(copied_margin.as<double>(), 0.10);
ASSERT_TRUE(fixture.runner_.swapPlanner("TestPlannerOk"));
EXPECT_EQ(pluginInitializeCount(), before + 1);
ASSERT_TRUE(fixture.runner_.bindDockingMarker("dock_no_override", "TestPlannerOk"));
YAML::Node cleared_face_offset;
YAML::Node cleared_margin;
ASSERT_TRUE(nh.getParam("TestPlannerOk/dock_face_offset", cleared_face_offset));
ASSERT_TRUE(nh.getParam("TestPlannerOk/dock_pivot_safety_margin", cleared_margin));
EXPECT_TRUE(cleared_face_offset.IsNull());
EXPECT_TRUE(cleared_margin.IsNull());
ASSERT_TRUE(fixture.runner_.swapPlanner("TestPlannerOk"));
EXPECT_EQ(pluginInitializeCount(), before + 2);
ASSERT_TRUE(fixture.runner_.bindDockingMarker("dock_override", "TestPlannerOk"));
YAML::Node restored_face_offset;
YAML::Node restored_margin;
ASSERT_TRUE(nh.getParam("TestPlannerOk/dock_face_offset", restored_face_offset));
ASSERT_TRUE(nh.getParam("TestPlannerOk/dock_pivot_safety_margin", restored_margin));
EXPECT_DOUBLE_EQ(restored_face_offset.as<double>(), 0.40);
EXPECT_DOUBLE_EQ(restored_margin.as<double>(), 0.10);
ASSERT_TRUE(fixture.runner_.swapPlanner("TestPlannerOk"));
EXPECT_EQ(pluginInitializeCount(), before + 3);
}
TEST(PlannerRunnerDockingMarker, EmptyMarkerOrPlannerNameIsANoOp)
{
Fixture fixture;