feat: per-marker dock_face_offset and pivot margin for dock_anchor mating_edge

The charger goal is the docked base_link pose, and the real charger face lies 0.40 m behind
it (detector offset_x). mating_edge measured the pivot sweep from a face assumed at
mating_extent (0.325 m) behind the goal, and still forced a terminal of at least
rear_extent. So the robot rotated with its centre about 0.725 m from the charger face.

Two optional keys, valid only with dock_anchor: mating_edge (rejected with center or face):
- dock_face_offset [m]: distance from the goal back to the real dock face. Default
  mating_extent.
- dock_pivot_safety_margin [m]: overrides maneuver/pivot_safety_margin for this marker.
A YAML null reads as unset, so move_base2 can clear a previous marker's value.

For mating_edge, the terminal floor becomes
max(mating_extent - face_offset, 0) + padding (floored at path_point_spacing), and the pivot
vertex becomes max(straight_distance, circumscribed - face_offset + margin). The costmap
rotation radius uses the same margin. center and face are unchanged.

KIT charger (face offset 0.40, margin 0.10, straight_length 0.2): vertex 0.2 m, robot centre
0.60 m from the charger face. Tests cover the three robot starts, the defaults, validation
and null handling. The test target now links yaml-cpp itself.
This commit is contained in:
2026-10-29 16:54:16 +07:00
parent 9d31c0e5db
commit 07e2fd3b38
8 changed files with 406 additions and 32 deletions

View File

@@ -6,6 +6,7 @@
#include <vector>
#include <data_convert/data_convert.h>
#include <robot/node_handle.h>
#include "dock_planner/dock_calc.h"
#include "dock_planner/dock_planner_config.h"
@@ -400,6 +401,56 @@ void testConfig()
config = dock_planner::DockPlannerConfig{};
config.pivot_safety_margin = -0.01;
CHECK(!config.validate(error));
for (const auto anchor : {dock_planner::DockAnchor::kCenter,
dock_planner::DockAnchor::kFace})
{
config = dock_planner::DockPlannerConfig{};
config.dock_anchor = anchor;
config.dock_face_offset = 0.4;
CHECK(!config.validate(error));
CHECK(error.find("dock_face_offset is only valid with dock_anchor: mating_edge") !=
std::string::npos);
CHECK(error.find(anchor == dock_planner::DockAnchor::kCenter ? "got center" : "got face") !=
std::string::npos);
}
config = dock_planner::DockPlannerConfig{};
config.dock_anchor = dock_planner::DockAnchor::kMatingEdge;
config.dock_face_offset = 0.0;
CHECK(!config.validate(error));
config.dock_face_offset = -0.01;
CHECK(!config.validate(error));
config.dock_face_offset = std::numeric_limits<double>::quiet_NaN();
CHECK(!config.validate(error));
config.dock_face_offset = 2.01;
CHECK(!config.validate(error));
config.dock_face_offset.reset();
config.dock_pivot_safety_margin = -0.01;
CHECK(!config.validate(error));
config.dock_pivot_safety_margin = std::numeric_limits<double>::quiet_NaN();
CHECK(!config.validate(error));
config.dock_pivot_safety_margin = 1.01;
CHECK(!config.validate(error));
// YAML null is the marker-binding clear value and must load exactly like an absent key.
robot::NodeHandle planner_nh;
planner_nh.setParam("dock_anchor", YAML::Node("mating_edge"));
planner_nh.setParam("dock_face_offset", YAML::Node(YAML::NodeType::Null));
planner_nh.setParam("dock_pivot_safety_margin", YAML::Node(YAML::NodeType::Null));
dock_planner::DockPlannerConfig loaded;
CHECK(dock_planner::DockPlannerConfig::load(planner_nh, loaded, error));
CHECK(!loaded.dock_face_offset.has_value());
CHECK(!loaded.dock_pivot_safety_margin.has_value());
planner_nh.setParam("dock_face_offset", 0.4);
planner_nh.setParam("dock_pivot_safety_margin", 0.1);
CHECK(dock_planner::DockPlannerConfig::load(planner_nh, loaded, error));
CHECK(loaded.dock_face_offset.has_value() && near(*loaded.dock_face_offset, 0.4));
CHECK(loaded.dock_pivot_safety_margin.has_value() &&
near(*loaded.dock_pivot_safety_margin, 0.1));
planner_nh.setParam("dock_anchor", YAML::Node("face"));
CHECK(!dock_planner::DockPlannerConfig::load(planner_nh, loaded, error));
CHECK(error.find("dock_face_offset is only valid with dock_anchor: mating_edge (got face)") !=
std::string::npos);
config = dock_planner::DockPlannerConfig{};
config.pivot_backoff_max_distance = -0.01;
CHECK(!config.validate(error));
@@ -635,6 +686,174 @@ void testMatingEdgeAnchor()
CHECK(mating_path.size() < face_path.size());
}
void testMatingEdgeFaceOffset()
{
const auto robot_footprint = robotFootprint065x069();
const std::vector<robot_geometry_msgs::Point> no_dock_footprint;
const auto goal = pose(0.0, 0.0, 0.0);
const double circumscribed = std::hypot(0.325, 0.345);
auto config = differentialBackoffConfig();
config.minimum_turning_radius = 0.0;
config.direct_entry_min_curve_room = 0.0;
config.straight_length = 0.2;
config.dock_anchor = dock_planner::DockAnchor::kMatingEdge;
config.dock_face_offset = 0.40;
config.dock_pivot_safety_margin = 0.10;
const double kit_minimum_cusp_distance = std::max(
std::max(0.325 - *config.dock_face_offset, 0.0) +
config.reverse_distance_padding,
config.path_point_spacing);
const double kit_straight_distance =
std::max(kit_minimum_cusp_distance, config.straight_length);
CHECK(near(kit_minimum_cusp_distance, 0.05));
CHECK(near(kit_straight_distance, 0.2));
const double kit_vertex = std::max(
kit_straight_distance,
circumscribed - *config.dock_face_offset +
*config.dock_pivot_safety_margin);
CHECK(near(kit_vertex, 0.2));
dock_planner::DockCalc kit_calculator(config);
for (const auto& start : {pose(0.579, 0.292, 0.0),
pose(0.427, 0.155, 0.0),
pose(0.375, -0.149, 0.17)})
{
std::vector<robot_geometry_msgs::Pose> path;
CHECK(kit_calculator.makePlanMoveToDock(start, goal, robot_footprint,
no_dock_footprint, path));
checkPivotPath(path, goal.pose, false, kit_vertex);
bool checked_terminal_length = false;
for (std::size_t index = 1; index < path.size(); ++index)
{
if (std::hypot(path[index].position.x - path[index - 1].position.x,
path[index].position.y - path[index - 1].position.y) <= 1e-9)
{
CHECK(near(std::fabs(longitudinal(path[index], goal.pose)), 0.2));
checked_terminal_length = true;
break;
}
}
CHECK(checked_terminal_length);
// The pivot lies between every start and the goal, so none of these paths backs off.
CHECK(longitudinal(path.front(), goal.pose) > kit_vertex);
}
// With no explicit offset, the mating edge remains the assumed face. A short
// terminal is therefore raised to the rotation-clearance vertex, 0.299 m.
config.dock_face_offset.reset();
config.dock_pivot_safety_margin.reset();
config.straight_length = 0.1;
const double default_offset_vertex = std::max(
config.straight_length,
circumscribed - 0.325 + config.pivot_safety_margin);
CHECK(near(default_offset_vertex, 0.299, 1e-3));
dock_planner::DockCalc default_offset_calculator(config);
std::vector<robot_geometry_msgs::Pose> default_offset_path;
CHECK(default_offset_calculator.makePlanMoveToDock(
pose(0.579, 0.292, 0.0), goal, robot_footprint,
no_dock_footprint, default_offset_path));
checkPivotPath(default_offset_path, goal.pose, false, default_offset_vertex);
}
void testDockPivotSafetyMarginOverride()
{
const auto robot_footprint = robotFootprint065x069();
const std::vector<robot_geometry_msgs::Point> trolley_footprint = {
point(0.375, -0.2735), point(0.375, 0.2735),
point(-0.375, 0.2735), point(-0.375, -0.2735)};
const auto start = pose(1.6, 0.4, 0.0);
const auto goal = pose(0.0, 0.0, 0.0);
const double circumscribed = std::hypot(0.325, 0.345);
auto center_config = differentialBackoffConfig();
center_config.minimum_turning_radius = 0.0;
center_config.direct_entry_min_curve_room = 0.0;
center_config.straight_length = 0.2;
center_config.dock_anchor = dock_planner::DockAnchor::kCenter;
center_config.dock_pivot_safety_margin.reset();
center_config.dock_face_offset.reset();
// With neither optional key set, preserve the prior center-anchor path pose for pose.
dock_planner::DockCalc center_default(center_config);
std::vector<robot_geometry_msgs::Pose> center_default_path;
CHECK(center_default.makePlanMoveToDock(start, goal, robot_footprint,
trolley_footprint, center_default_path));
auto center_no_keys_config = center_config;
center_no_keys_config.dock_face_offset.reset();
center_no_keys_config.dock_pivot_safety_margin.reset();
dock_planner::DockCalc center_no_keys(center_no_keys_config);
std::vector<robot_geometry_msgs::Pose> center_no_keys_path;
CHECK(center_no_keys.makePlanMoveToDock(start, goal, robot_footprint,
trolley_footprint, center_no_keys_path));
CHECK(pathsEqualExactly(center_default_path, center_no_keys_path));
const std::vector<robot_geometry_msgs::Point> no_dock_footprint;
auto face_config = center_config;
face_config.dock_anchor = dock_planner::DockAnchor::kFace;
dock_planner::DockCalc face_default(face_config);
std::vector<robot_geometry_msgs::Pose> face_default_path;
CHECK(face_default.makePlanMoveToDock(start, goal, robot_footprint,
no_dock_footprint, face_default_path));
// DockCalc itself also ignores an invalid non-mating-edge override. Plugin validation below
// still rejects these configs before initialize() succeeds.
for (const auto anchor : {dock_planner::DockAnchor::kCenter,
dock_planner::DockAnchor::kFace})
{
auto rejected_config = center_config;
rejected_config.dock_anchor = anchor;
rejected_config.dock_pivot_safety_margin = 0.10;
std::string error;
CHECK(!rejected_config.validate(error));
CHECK(error.find("dock_pivot_safety_margin is only valid with dock_anchor: mating_edge") !=
std::string::npos);
CHECK(error.find(anchor == dock_planner::DockAnchor::kCenter ? "got center" : "got face") !=
std::string::npos);
// DockCalc validates its config before planning, so an override declared on
// center/face is refused there too: no path, rather than a silently ignored key.
dock_planner::DockCalc refused_override(rejected_config);
std::vector<robot_geometry_msgs::Pose> refused_override_path;
const auto& dock_footprint = anchor == dock_planner::DockAnchor::kCenter
? trolley_footprint
: no_dock_footprint;
CHECK(!refused_override.makePlanMoveToDock(
start, goal, robot_footprint, dock_footprint, refused_override_path));
CHECK(refused_override_path.empty());
}
auto mating_config = center_config;
mating_config.dock_anchor = dock_planner::DockAnchor::kMatingEdge;
mating_config.dock_face_offset = 0.40;
mating_config.straight_length = 0.1;
mating_config.dock_pivot_safety_margin.reset();
std::string mating_config_error;
CHECK(mating_config.validate(mating_config_error));
dock_planner::DockCalc mating_default(mating_config);
std::vector<robot_geometry_msgs::Pose> mating_default_path;
CHECK(mating_default.makePlanMoveToDock(
pose(0.579, 0.292, 0.0), goal, robot_footprint, {}, mating_default_path));
mating_config.dock_pivot_safety_margin = 0.10;
dock_planner::DockCalc overridden(mating_config);
std::vector<robot_geometry_msgs::Pose> overridden_path;
CHECK(overridden.makePlanMoveToDock(
pose(0.579, 0.292, 0.0), goal, robot_footprint, {}, overridden_path));
const double face_offset = 0.40;
const double straight_distance = 0.1;
const double default_vertex = std::max(
straight_distance,
circumscribed - face_offset + center_config.pivot_safety_margin);
const double override_vertex = std::max(
straight_distance, circumscribed - face_offset + 0.10);
CHECK(near(default_vertex, 0.224, 1e-3));
CHECK(near(override_vertex, 0.174, 1e-3));
checkPivotPath(mating_default_path, goal.pose, false, default_vertex);
checkPivotPath(overridden_path, goal.pose, false, override_vertex);
CHECK(!pathsEqualExactly(mating_default_path, overridden_path));
}
void testExistingPlansUnchangedByBackoff()
{
const auto robot_footprint = apmFootprint();
@@ -1228,6 +1447,8 @@ int main()
testConfig();
testBackoffPivotRobotFailures();
testMatingEdgeAnchor();
testMatingEdgeFaceOffset();
testDockPivotSafetyMarginOverride();
testExistingPlansUnchangedByBackoff();
testBackoffPivotGates();
testCostmapCheckCallbacks();