Split configuration out of the planner into DockPlannerConfig with explicit
load/validate, so a missing or malformed key fails at initialize() with a
message instead of silently defaulting to zero.
- initialize() now scopes its NodeHandle to the plugin name. The previous
"~/<name>" form never resolved ("~" is not a key in the merged tree) and
fell back to ROOT, so every parameter was read from the wrong place and
cost_threshold silently dropped from 200 to 0.
- Replace robot_nav_2d_utils::footprintFromParams(), whose declaration and
definition disagreed on the argument type. The symbol was never defined,
and because the plugin is dlopen'd lazily the failure only surfaced at the
call site on the robot, long after a clean build.
- Read footprint_dock, the dock object's polygon, with range and NaN checks.
move_base2 copies it in per marker before the instance is built.
- dock_anchor selects whether the marker goal sits at the dock centre or on
its approach face; the face case ignores footprint_dock entirely.
- makePlan() rejects start/goal outside the costmap global frame instead of
planning across mismatched frames.
- Add dock_planner_test covering config validation, footprint parsing and
path generation.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
301 lines
12 KiB
C++
301 lines
12 KiB
C++
#include <cmath>
|
|
#include <iostream>
|
|
#include <limits>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <data_convert/data_convert.h>
|
|
|
|
#include "dock_planner/dock_calc.h"
|
|
#include "dock_planner/dock_planner_config.h"
|
|
|
|
namespace
|
|
{
|
|
|
|
int failures = 0;
|
|
|
|
void check(bool condition, const char* expression, int line)
|
|
{
|
|
if (!condition)
|
|
{
|
|
std::cerr << "FAIL line " << line << ": " << expression << '\n';
|
|
++failures;
|
|
}
|
|
}
|
|
|
|
#define CHECK(expression) check((expression), #expression, __LINE__)
|
|
|
|
robot_geometry_msgs::Point point(double x, double y)
|
|
{
|
|
robot_geometry_msgs::Point result;
|
|
result.x = x;
|
|
result.y = y;
|
|
result.z = 0.0;
|
|
return result;
|
|
}
|
|
|
|
robot_geometry_msgs::PoseStamped pose(double x, double y, double yaw)
|
|
{
|
|
robot_geometry_msgs::PoseStamped result;
|
|
result.pose.position.x = x;
|
|
result.pose.position.y = y;
|
|
result.pose.orientation = data_convert::createQuaternionMsgFromYaw(yaw);
|
|
return result;
|
|
}
|
|
|
|
bool near(double first, double second, double tolerance = 1e-9)
|
|
{
|
|
return std::fabs(first - second) <= tolerance;
|
|
}
|
|
|
|
double normalizeAngle(double angle)
|
|
{
|
|
return std::remainder(angle, 2.0 * 3.14159265358979323846);
|
|
}
|
|
|
|
void checkGeneratedPath(dock_planner::DockCalc& calculator,
|
|
const robot_geometry_msgs::PoseStamped& start,
|
|
const robot_geometry_msgs::PoseStamped& goal,
|
|
const std::vector<robot_geometry_msgs::Point>& robot_footprint,
|
|
const std::vector<robot_geometry_msgs::Point>& dock_footprint)
|
|
{
|
|
std::vector<robot_geometry_msgs::Pose> path;
|
|
CHECK(calculator.makePlanMoveToDock(start, goal, robot_footprint,
|
|
dock_footprint, path));
|
|
CHECK(path.size() > 2);
|
|
CHECK(near(path.front().position.x, start.pose.position.x));
|
|
CHECK(near(path.front().position.y, start.pose.position.y));
|
|
CHECK(near(path.back().position.x, goal.pose.position.x));
|
|
CHECK(near(path.back().position.y, goal.pose.position.y));
|
|
|
|
for (std::size_t index = 0; index < path.size(); ++index)
|
|
{
|
|
const auto& current = path[index];
|
|
CHECK(std::isfinite(current.position.x));
|
|
CHECK(std::isfinite(current.position.y));
|
|
CHECK(std::isfinite(current.orientation.z));
|
|
CHECK(std::isfinite(current.orientation.w));
|
|
if (index > 0)
|
|
{
|
|
CHECK(std::hypot(current.position.x - path[index - 1].position.x,
|
|
current.position.y - path[index - 1].position.y) > 1e-9);
|
|
}
|
|
}
|
|
}
|
|
|
|
void testConfig()
|
|
{
|
|
dock_planner::DockPlannerConfig config;
|
|
std::string error;
|
|
CHECK(config.validate(error));
|
|
CHECK(error.empty());
|
|
CHECK(near(config.angleThreshold(0.0), config.angle_threshold_near));
|
|
CHECK(near(config.angleThreshold(10.0), config.angle_threshold_far));
|
|
CHECK(near(config.angleThreshold(0.55),
|
|
(config.angle_threshold_near + config.angle_threshold_far) / 2.0));
|
|
|
|
config.path_point_spacing = 0.0;
|
|
CHECK(!config.validate(error));
|
|
CHECK(!error.empty());
|
|
|
|
config = dock_planner::DockPlannerConfig{};
|
|
config.angle_threshold_far = config.angle_threshold_near;
|
|
CHECK(!config.validate(error));
|
|
|
|
config = dock_planner::DockPlannerConfig{};
|
|
config.lateral_distance_far = std::numeric_limits<double>::quiet_NaN();
|
|
CHECK(!config.validate(error));
|
|
}
|
|
|
|
void testPathGeneration()
|
|
{
|
|
dock_planner::DockPlannerConfig config;
|
|
config.path_point_spacing = 0.05;
|
|
dock_planner::DockCalc calculator(config);
|
|
|
|
const std::vector<robot_geometry_msgs::Point> robot_footprint = {
|
|
point(0.50, -0.35), point(0.50, 0.35),
|
|
point(-0.50, 0.35), point(-0.50, -0.35)};
|
|
const std::vector<robot_geometry_msgs::Point> dock_footprint = {
|
|
point(0.50, -0.40), point(0.50, 0.40),
|
|
point(-0.50, 0.40), point(-0.50, -0.40)};
|
|
|
|
const auto start = pose(2.8, 0.6, 0.0);
|
|
const auto goal = pose(0.0, 0.0, 0.0);
|
|
checkGeneratedPath(calculator, start, goal, robot_footprint, dock_footprint);
|
|
checkGeneratedPath(calculator, pose(2.8, 0.0, 0.0), goal,
|
|
robot_footprint, dock_footprint);
|
|
checkGeneratedPath(calculator, pose(2.8, -0.6, 0.0), goal,
|
|
robot_footprint, dock_footprint);
|
|
checkGeneratedPath(calculator, pose(-2.8, 0.6, 0.0), goal,
|
|
robot_footprint, dock_footprint);
|
|
checkGeneratedPath(calculator, pose(0.6, 2.8, 1.5707963267948966),
|
|
pose(0.0, 0.0, 1.5707963267948966),
|
|
robot_footprint, dock_footprint);
|
|
|
|
const auto prealigned_start = pose(2.8, 0.6, -1.2);
|
|
std::vector<robot_geometry_msgs::Pose> orientation_path;
|
|
CHECK(calculator.makePlanMoveToDock(prealigned_start, goal, robot_footprint,
|
|
dock_footprint, orientation_path));
|
|
CHECK(orientation_path.size() > 2);
|
|
const double first_path_yaw = data_convert::getYaw(
|
|
orientation_path.front().orientation);
|
|
const double expected_reverse_path_yaw = std::atan2(
|
|
orientation_path.front().position.y - orientation_path[1].position.y,
|
|
orientation_path.front().position.x - orientation_path[1].position.x);
|
|
CHECK(near(normalizeAngle(first_path_yaw - expected_reverse_path_yaw), 0.0));
|
|
CHECK(std::fabs(normalizeAngle(
|
|
first_path_yaw - data_convert::getYaw(prealigned_start.pose.orientation))) > 0.1);
|
|
|
|
// Regression for the integrated run where libamr_comunication_utils was
|
|
// loaded before DockPlanner and its global CurveCommon symbol was selected.
|
|
const std::vector<robot_geometry_msgs::Point> runtime_footprint = {
|
|
point(0.583, -0.48), point(0.583, 0.48),
|
|
point(-0.583, 0.48), point(-0.583, -0.48)};
|
|
checkGeneratedPath(calculator,
|
|
pose(9.914814184, 9.939527902, 0.015737065),
|
|
pose(8.411853097, 10.115902417, 0.015734468),
|
|
runtime_footprint, runtime_footprint);
|
|
|
|
std::vector<robot_geometry_msgs::Pose> path;
|
|
auto invalid_start = start;
|
|
invalid_start.pose.position.x = std::numeric_limits<double>::infinity();
|
|
CHECK(!calculator.makePlanMoveToDock(invalid_start, goal, robot_footprint,
|
|
dock_footprint, path));
|
|
CHECK(path.empty());
|
|
|
|
CHECK(!calculator.makePlanMoveToDock(start, goal, {}, dock_footprint, path));
|
|
CHECK(path.empty());
|
|
|
|
CHECK(!calculator.makePlanMoveToDock(pose(0.8, 0.2, 0.0), goal,
|
|
robot_footprint, dock_footprint, path));
|
|
CHECK(path.empty());
|
|
|
|
// Slightly beyond the nominal 1.0 m alignment distance: projection_ratio
|
|
// passes the strict > 1 check, but the reference NURBS is still too short.
|
|
CHECK(!calculator.makePlanMoveToDock(pose(1.0 + 5e-10, 0.0, 0.0), goal,
|
|
robot_footprint, dock_footprint, path));
|
|
CHECK(path.empty());
|
|
|
|
config.path_point_spacing = 0.0;
|
|
calculator.setConfig(config);
|
|
CHECK(!calculator.makePlanMoveToDock(start, goal, robot_footprint,
|
|
dock_footprint, path));
|
|
CHECK(path.empty());
|
|
}
|
|
|
|
bool pathsEqual(const std::vector<robot_geometry_msgs::Pose>& first,
|
|
const std::vector<robot_geometry_msgs::Pose>& second)
|
|
{
|
|
if (first.size() != second.size())
|
|
{
|
|
return false;
|
|
}
|
|
for (std::size_t index = 0; index < first.size(); ++index)
|
|
{
|
|
if (!near(first[index].position.x, second[index].position.x) ||
|
|
!near(first[index].position.y, second[index].position.y) ||
|
|
!near(first[index].orientation.z, second[index].orientation.z) ||
|
|
!near(first[index].orientation.w, second[index].orientation.w))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// A stacker-style robot: base_link at the drive cluster, forks extending
|
|
// 1.2 m behind it (-x), body 0.8 m ahead (+x). The approach distance must use
|
|
// the extent of the leading edge, not half the bounding box.
|
|
void testAsymmetricFootprint()
|
|
{
|
|
dock_planner::DockPlannerConfig config;
|
|
dock_planner::DockCalc calculator(config);
|
|
|
|
const std::vector<robot_geometry_msgs::Point> stacker_footprint = {
|
|
point(0.8, -0.5), point(0.8, 0.5), point(-1.2, 0.5), point(-1.2, -0.5)};
|
|
const std::vector<robot_geometry_msgs::Point> rear_matched_footprint = {
|
|
point(1.2, -0.5), point(1.2, 0.5), point(-1.2, 0.5), point(-1.2, -0.5)};
|
|
const std::vector<robot_geometry_msgs::Point> front_matched_footprint = {
|
|
point(0.8, -0.5), point(0.8, 0.5), point(-0.8, 0.5), point(-0.8, -0.5)};
|
|
const std::vector<robot_geometry_msgs::Point> dock_footprint = {
|
|
point(0.5, -0.4), point(0.5, 0.4), point(-0.5, 0.4), point(-0.5, -0.4)};
|
|
|
|
// Goal yaw points toward the start: backward approach, the rear edge
|
|
// (forks, 1.2 m) leads. The path must match a symmetric robot with the
|
|
// same rear extent, regardless of the front extent.
|
|
const auto backing_start = pose(4.0, 0.5, 0.0);
|
|
const auto goal = pose(0.0, 0.0, 0.0);
|
|
std::vector<robot_geometry_msgs::Pose> asymmetric_path;
|
|
std::vector<robot_geometry_msgs::Pose> reference_path;
|
|
CHECK(calculator.makePlanMoveToDock(backing_start, goal, stacker_footprint,
|
|
dock_footprint, asymmetric_path));
|
|
CHECK(calculator.makePlanMoveToDock(backing_start, goal, rear_matched_footprint,
|
|
dock_footprint, reference_path));
|
|
CHECK(pathsEqual(asymmetric_path, reference_path));
|
|
CHECK(calculator.makePlanMoveToDock(backing_start, goal, front_matched_footprint,
|
|
dock_footprint, reference_path));
|
|
CHECK(!pathsEqual(asymmetric_path, reference_path));
|
|
|
|
// Goal yaw points away from the start: the axis flips, the approach is
|
|
// forward and the front edge (0.8 m) leads.
|
|
const auto forward_goal = pose(0.0, 0.0, 3.14159265358979323846);
|
|
CHECK(calculator.makePlanMoveToDock(backing_start, forward_goal, stacker_footprint,
|
|
dock_footprint, asymmetric_path));
|
|
CHECK(calculator.makePlanMoveToDock(backing_start, forward_goal, front_matched_footprint,
|
|
dock_footprint, reference_path));
|
|
CHECK(pathsEqual(asymmetric_path, reference_path));
|
|
}
|
|
|
|
void testDockAnchor()
|
|
{
|
|
dock_planner::DockPlannerConfig config;
|
|
const std::vector<robot_geometry_msgs::Point> robot_footprint = {
|
|
point(0.50, -0.35), point(0.50, 0.35),
|
|
point(-0.50, 0.35), point(-0.50, -0.35)};
|
|
const std::vector<robot_geometry_msgs::Point> dock_footprint = {
|
|
point(0.9, -0.8), point(0.9, 0.8), point(-0.9, 0.8), point(-0.9, -0.8)};
|
|
|
|
const auto start = pose(4.0, 0.6, 0.0);
|
|
const auto goal = pose(0.0, 0.0, 0.0);
|
|
|
|
// face: the goal already sits on the approach face, so the dock footprint
|
|
// must not contribute — identical to center with no dock footprint at all.
|
|
config.dock_anchor = dock_planner::DockAnchor::kFace;
|
|
dock_planner::DockCalc face_calculator(config);
|
|
std::vector<robot_geometry_msgs::Pose> face_path;
|
|
CHECK(face_calculator.makePlanMoveToDock(start, goal, robot_footprint,
|
|
dock_footprint, face_path));
|
|
|
|
config.dock_anchor = dock_planner::DockAnchor::kCenter;
|
|
dock_planner::DockCalc center_calculator(config);
|
|
std::vector<robot_geometry_msgs::Pose> no_dock_path;
|
|
CHECK(center_calculator.makePlanMoveToDock(start, goal, robot_footprint,
|
|
{}, no_dock_path));
|
|
CHECK(pathsEqual(face_path, no_dock_path));
|
|
|
|
// center with a real dock footprint must differ from face: the near-face
|
|
// extent (0.9 m) pushes the alignment pose further out.
|
|
std::vector<robot_geometry_msgs::Pose> center_path;
|
|
CHECK(center_calculator.makePlanMoveToDock(start, goal, robot_footprint,
|
|
dock_footprint, center_path));
|
|
CHECK(!pathsEqual(face_path, center_path));
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main()
|
|
{
|
|
testConfig();
|
|
testPathGeneration();
|
|
testAsymmetricFootprint();
|
|
testDockAnchor();
|
|
if (failures != 0)
|
|
{
|
|
std::cerr << failures << " DockPlanner test assertion(s) failed.\n";
|
|
return 1;
|
|
}
|
|
std::cout << "DockPlanner tests passed.\n";
|
|
return 0;
|
|
}
|