This commit is contained in:
2026-08-15 13:04:56 +07:00
parent bac3ae0ba3
commit 5c0c5d96d7
8 changed files with 905 additions and 73 deletions

View File

@@ -102,16 +102,26 @@ double threePointCurvature(const robot_geometry_msgs::Pose& first,
return 2.0 * twice_area / (ab * bc * ac);
}
std::size_t checkForwardThenReverse(
/**
* @brief Assert the single-cusp contract: one curved lead-in, one direction
* change, then a straight terminal on the goal axis.
*
* @param terminal_forward true when the terminal leg is driven forward (front
* edge docks, e.g. a charging contact), false when it is driven in
* reverse (rear edge docks, e.g. forks into a pallet). The lead-in
* always runs in the opposite direction.
*/
std::size_t checkSingleCuspPath(
const std::vector<robot_geometry_msgs::Pose>& path,
const robot_geometry_msgs::Pose& goal,
double maximum_curvature)
double maximum_curvature,
bool terminal_forward)
{
CHECK(path.size() > 3);
std::size_t cusp_index = path.size();
int direction_changes = 0;
bool previous_forward = edgeIsForward(path[0], path[1]);
CHECK(previous_forward);
CHECK(previous_forward != terminal_forward);
for (std::size_t index = 1; index + 1 < path.size(); ++index)
{
@@ -130,11 +140,11 @@ std::size_t checkForwardThenReverse(
for (std::size_t index = 0; index < cusp_index; ++index)
{
CHECK(edgeIsForward(path[index], path[index + 1]));
CHECK(edgeIsForward(path[index], path[index + 1]) != terminal_forward);
}
for (std::size_t index = cusp_index; index + 1 < path.size(); ++index)
{
CHECK(!edgeIsForward(path[index], path[index + 1]));
CHECK(edgeIsForward(path[index], path[index + 1]) == terminal_forward);
CHECK(std::fabs(lateral(path[index], goal)) < 1e-7);
CHECK(std::fabs(normalizeAngle(
data_convert::getYaw(path[index].orientation) -
@@ -149,6 +159,49 @@ std::size_t checkForwardThenReverse(
return cusp_index;
}
/**
* @brief Assert the no-cusp contract: one travel direction for the whole path,
* curvature within the Ackermann limit, and a straight tail on the goal
* axis at least @p straight_distance long.
*/
void checkDirectEntry(const std::vector<robot_geometry_msgs::Pose>& path,
const robot_geometry_msgs::Pose& goal,
double maximum_curvature,
bool terminal_forward,
double straight_distance)
{
CHECK(path.size() > 3);
for (std::size_t index = 0; index + 1 < path.size(); ++index)
{
CHECK(edgeIsForward(path[index], path[index + 1]) == terminal_forward);
}
for (std::size_t index = 1; index + 1 < path.size(); ++index)
{
CHECK(threePointCurvature(path[index - 1], path[index], path[index + 1]) <=
maximum_curvature + 1e-5);
}
std::size_t entry_index = path.size();
for (std::size_t index = 0; index < path.size(); ++index)
{
if (std::fabs(lateral(path[index], goal)) < 1e-7)
{
entry_index = index;
break;
}
}
CHECK(entry_index + 1 < path.size());
// Once the path reaches the axis it must stay on it, pointing at the goal.
for (std::size_t index = entry_index; index < path.size(); ++index)
{
CHECK(std::fabs(lateral(path[index], goal)) < 1e-7);
CHECK(std::fabs(normalizeAngle(
data_convert::getYaw(path[index].orientation) -
data_convert::getYaw(goal.orientation))) < 1e-7);
}
CHECK(std::fabs(longitudinal(path[entry_index], goal)) >= straight_distance - 1e-6);
}
std::vector<robot_geometry_msgs::Pose> generatePath(
dock_planner::DockCalc& calculator,
const robot_geometry_msgs::PoseStamped& start,
@@ -187,6 +240,9 @@ dock_planner::DockPlannerConfig apmConfig()
config.wheel_base = 1.3268;
config.max_steering_angle = 0.50;
config.path_point_spacing = 0.05;
// The cusp cases below have to keep exercising the cusp: several of their
// starts are far enough that the direct entry would take over.
config.direct_entry_min_curve_room = 0.0;
return config;
}
@@ -235,8 +291,8 @@ void testPathGeneration()
{
const auto path = generatePath(calculator, start, goal,
robot_footprint, dock_footprint);
const std::size_t cusp = checkForwardThenReverse(path, goal.pose,
maximum_curvature);
const std::size_t cusp = checkSingleCuspPath(path, goal.pose,
maximum_curvature, false);
CHECK(longitudinal(path[cusp], goal.pose) > longitudinal(start.pose, goal.pose));
CHECK(std::fabs(normalizeAngle(
data_convert::getYaw(path.front().orientation) -
@@ -247,16 +303,33 @@ void testPathGeneration()
const auto rotated_path = generatePath(
calculator, pose(0.6, 2.8, 0.0), rotated_goal,
robot_footprint, dock_footprint);
checkForwardThenReverse(rotated_path, rotated_goal.pose, maximum_curvature);
checkSingleCuspPath(rotated_path, rotated_goal.pose, maximum_curvature, false);
// The previous projection<=1 failure is now valid: the robot first drives
// away from the dock until the curvature-safe cusp, then reverses straight.
const auto close_path = generatePath(calculator, pose(0.8, 0.2, 0.0), goal,
robot_footprint, dock_footprint);
checkForwardThenReverse(close_path, goal.pose, maximum_curvature);
checkSingleCuspPath(close_path, goal.pose, maximum_curvature, false);
// Standing on the far side of the goal is no longer an error: the docking
// edge is derived from the side the robot is on, so the same geometry runs
// mirrored -- reverse lead-in, then a straight FORWARD terminal. This is the
// charging-contact case (APM mates with the front of the robot).
const auto front_path = generatePath(calculator, pose(-2.8, 0.6, 0.0), goal,
robot_footprint, dock_footprint);
const std::size_t front_cusp =
checkSingleCuspPath(front_path, goal.pose, maximum_curvature, true);
// The cusp must sit on the far side of the goal from the rear-dock cases,
// and the clearance must come from front_extent (1.65 m) plus the dock's
// near face (0.50 m), not from rear_extent (0.35 m).
CHECK(longitudinal(front_path[front_cusp], goal.pose) < 0.0);
CHECK(std::fabs(longitudinal(front_path[front_cusp], goal.pose)) >= 2.15);
CHECK(std::fabs(lateral(front_path[front_cusp], goal.pose)) < 1e-7);
// A start exactly on the goal's lateral axis belongs to neither side, so no
// docking edge can be derived and the plan must be refused.
std::vector<robot_geometry_msgs::Pose> path;
CHECK(!calculator.makePlanMoveToDock(pose(-2.8, 0.6, 0.0), goal,
CHECK(!calculator.makePlanMoveToDock(pose(0.0, 0.6, 0.0), goal,
robot_footprint, dock_footprint, path));
CHECK(path.empty());
@@ -275,6 +348,75 @@ void testPathGeneration()
CHECK(path.empty());
}
void testDirectEntry()
{
dock_planner::DockPlannerConfig config = apmConfig();
config.direct_entry_min_curve_room = 0.5;
dock_planner::DockCalc calculator(config);
const std::vector<robot_geometry_msgs::Point> robot_footprint = {
point(1.65, -0.40), point(1.65, 0.40),
point(-0.35, 0.40), point(-0.35, -0.40)};
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 goal = pose(0.0, 0.0, 0.0);
const double maximum_curvature = 1.0 / config.minimumTurningRadius();
// Rear edge: clearance 0.35 (rear_extent) + 0.50 (dock near face) = 0.85 m,
// so a start 2.8 m out leaves 1.95 m of curve room against the 1.598 m the
// 0.60 m lateral offset needs at min_radius 2.4287 m. The whole path reverses.
const double rear_straight = 0.35 + 0.50;
for (const auto& start : {pose(2.8, 0.6, -1.2), pose(2.8, -0.6, 1.2)})
{
const auto direct_path = generatePath(calculator, start, goal,
robot_footprint, dock_footprint);
checkDirectEntry(direct_path, goal.pose, maximum_curvature, false,
rear_straight);
}
// Already on the dock axis: the arc degenerates and the robot drives one
// straight line all the way in, instead of the pointless drive-away-and-back
// the cusp maneuver would produce.
const auto aligned_path = generatePath(calculator, pose(2.8, 0.0, 0.5), goal,
robot_footprint, dock_footprint);
checkDirectEntry(aligned_path, goal.pose, maximum_curvature, false,
rear_straight);
for (const auto& sample : aligned_path)
{
CHECK(std::fabs(lateral(sample, goal.pose)) < 1e-7);
}
// Front edge: clearance 1.65 (front_extent) + 0.50 = 2.15 m, so the start has
// to be much farther out for the arc to fit. The whole path drives forward.
const double front_straight = 1.65 + 0.50;
const auto front_direct = generatePath(calculator, pose(-4.0, 0.6, 0.0), goal,
robot_footprint, dock_footprint);
checkDirectEntry(front_direct, goal.pose, maximum_curvature, true,
front_straight);
// Enough room to pass the threshold (1.15 m > 0.50 m) but not enough for the
// radius (needs 1.598 m), so the planner must fall back to the cusp rather
// than emit an arc tighter than the steering limit.
const auto fallback_path = generatePath(calculator, pose(2.0, 0.6, 0.0), goal,
robot_footprint, dock_footprint);
checkSingleCuspPath(fallback_path, goal.pose, maximum_curvature, false);
// Too close for a straight terminal of its own length: still a cusp.
const auto close_path = generatePath(calculator, pose(1.0, 0.2, 0.0), goal,
robot_footprint, dock_footprint);
checkSingleCuspPath(close_path, goal.pose, maximum_curvature, false);
// A longer requested straight terminal eats the curve room, so the same start
// that took the direct entry above falls back to the cusp.
config.straight_length = 2.5;
calculator.setConfig(config);
const auto long_terminal = generatePath(calculator, pose(2.8, 0.6, -1.2), goal,
robot_footprint, dock_footprint);
checkSingleCuspPath(long_terminal, goal.pose, maximum_curvature, false);
}
bool pathsEqual(const std::vector<robot_geometry_msgs::Pose>& first,
const std::vector<robot_geometry_msgs::Pose>& second)
{
@@ -363,6 +505,7 @@ int main()
{
testConfig();
testPathGeneration();
testDirectEntry();
testAsymmetricFootprint();
testDockAnchor();
if (failures != 0)