feat: per-marker dock_straight_length override for the terminal straight leg

terminal/straight_length is one global value, so every docking marker gets
the same straight run into the dock. A marker profile can now set
dock_straight_length (move_base2 copies it into the DockPlanner namespace
and writes YAML null when the next marker lacks it). The terminal leg is
max(cusp floor, dock_straight_length or terminal/straight_length).

- Valid for every dock_anchor (center, face, mating_edge), unlike
  dock_face_offset and dock_pivot_safety_margin; finite and in [0, 2.0] m.
- The init summary and the plan log print the effective length and whether
  it came from the marker or the default.
- Test: missing and null keep the default, 0.30 lengthens the terminal leg,
  all three anchors load, out-of-range and NaN values are rejected.
This commit is contained in:
2026-11-12 15:44:02 +07:00
parent 07e2fd3b38
commit c94c5b2b0c
7 changed files with 118 additions and 6 deletions

View File

@@ -854,6 +854,87 @@ void testDockPivotSafetyMarginOverride()
CHECK(!pathsEqualExactly(mating_default_path, overridden_path));
}
void testDockStraightLengthOverride()
{
robot::NodeHandle root_nh;
YAML::Node parameters(YAML::NodeType::Map);
parameters["kinematics"]["model"] = "differential";
parameters["dock_anchor"] = "mating_edge";
parameters["dock_face_offset"] = 0.40;
parameters["dock_pivot_safety_margin"] = 0.10;
parameters["terminal"]["straight_length"] = 0.20;
root_nh.setParam("straight_length_override_test", parameters);
robot::NodeHandle planner_nh(root_nh, "straight_length_override_test");
dock_planner::DockPlannerConfig config;
std::string error;
const auto start = pose(0.579, 0.292, 0.0);
const auto goal = pose(0.0, 0.0, 0.0);
const auto footprint = robotFootprint065x069();
auto check_terminal = [&](const dock_planner::DockPlannerConfig& candidate,
double expected)
{
dock_planner::DockCalc calculator(candidate);
std::vector<robot_geometry_msgs::Pose> path;
CHECK(calculator.makePlanMoveToDock(start, goal, footprint, {}, path));
bool found_pivot = 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)), expected));
found_pivot = true;
break;
}
}
CHECK(found_pivot);
};
// Missing and null both preserve the configured terminal default in the path.
CHECK(dock_planner::DockPlannerConfig::load(planner_nh, config, error));
CHECK(!config.dock_straight_length.has_value());
CHECK(near(config.straight_length, 0.20));
check_terminal(config, 0.20);
planner_nh.setParam("dock_straight_length", YAML::Node(YAML::NodeType::Null));
CHECK(dock_planner::DockPlannerConfig::load(planner_nh, config, error));
CHECK(!config.dock_straight_length.has_value());
CHECK(near(config.straight_length, 0.20));
check_terminal(config, 0.20);
planner_nh.setParam("dock_straight_length", 0.30);
CHECK(dock_planner::DockPlannerConfig::load(planner_nh, config, error));
CHECK(config.dock_straight_length.has_value());
check_terminal(config, 0.30);
// Unlike the face and margin overrides, this key is valid for all anchors.
planner_nh.setParam("dock_face_offset", YAML::Node(YAML::NodeType::Null));
planner_nh.setParam("dock_pivot_safety_margin", YAML::Node(YAML::NodeType::Null));
for (const char* anchor : {"center", "face", "mating_edge"})
{
planner_nh.setParam("dock_anchor", YAML::Node(anchor));
CHECK(dock_planner::DockPlannerConfig::load(planner_nh, config, error));
CHECK(config.dock_straight_length.has_value());
}
for (const double value : {-0.01, 2.01})
{
planner_nh.setParam("dock_straight_length", value);
CHECK(!dock_planner::DockPlannerConfig::load(planner_nh, config, error));
CHECK(error == "parameter 'dock_straight_length' must be finite and in [0, 2.0] m");
}
// NaN goes through the YAML param tree as text that may not parse back as a double, so the
// reader can reject it before validate() does; either way the key must be named in the error.
planner_nh.setParam("dock_straight_length", std::numeric_limits<double>::quiet_NaN());
CHECK(!dock_planner::DockPlannerConfig::load(planner_nh, config, error));
CHECK(error.find("dock_straight_length") != std::string::npos);
std::cout << "dock_straight_length NaN rejected with: " << error << "\n";
for (const double value : {0.0, 2.0})
{
planner_nh.setParam("dock_straight_length", value);
CHECK(dock_planner::DockPlannerConfig::load(planner_nh, config, error));
}
}
void testExistingPlansUnchangedByBackoff()
{
const auto robot_footprint = apmFootprint();
@@ -1449,6 +1530,7 @@ int main()
testMatingEdgeAnchor();
testMatingEdgeFaceOffset();
testDockPivotSafetyMarginOverride();
testDockStraightLengthOverride();
testExistingPlansUnchangedByBackoff();
testBackoffPivotGates();
testCostmapCheckCallbacks();