feat: thêm mô hình động học differential và maneuver straight-pivot-straight
Hai thay đổi đi cùng một commit vì maneuver mới là hình dạng chính của base differential, đồng thời là fallback của base Ackermann; tách ra sẽ tạo commit trung gian không build được. Mô hình động học (kinematics/kinematic_model): - kAckermann là mặc định và giữ nguyên hành vi cũ, nên YAML chưa khai báo khoá này không đổi gì. - kDifferential bỏ qua lookup axle TF. Base differential không publish frame trục lái, tra cứu sẽ ném exception và làm chết plugin ngay lúc initialize; bán kính quay nhỏ nhất do đó lấy thẳng từ kinematics/minimum_turning_radius. - Bán kính 0 giờ là giá trị hợp lệ, nghĩa là robot xoay tại chỗ được. Chỉ giá trị âm hoặc không hữu hạn mới là lỗi cấu hình. Maneuver straight-pivot-straight: - Đỉnh xoay nằm giữa robot và dock nên không tốn thêm chiều sâu lối đi như cusp, vốn đẩy robot ra xa dock hơn chỗ đang đứng. - Vòng xoay tại chỗ được ghi thẳng vào path thành một khối pose cùng vị trí, khác yaw. Base Ackermann không đổi hướng ở một góc gấp của polyline, nên trạng thái dừng-đánh-lái phải nằm trong plan chứ không để controller tự suy. - maneuver/pivot_fallback_extension mở khoá hình dạng này cho Ackermann, đo bằng phần cusp đẩy robot RA XA dock hơn chỗ nó đang đứng. Ngưỡng tương đối là có chủ đích: bản trước đo chiều sâu lối đi tuyệt đối, cộng cả khoảng robot đang chiếm, nên loại bỏ mọi maneuver xuất phát từ khoảng cách tiếp cận bình thường. Mặc định 0 = tắt hoàn toàn. - maneuver/pivot_safety_margin giữ khoảng hở giữa đường tròn thân xe quét khi xoay tại chỗ và mặt gần của dock. Xoay tại chỗ quay mọi điểm footprint quanh base_link nên kích thước liên quan là circumscribed radius, luôn lớn hơn mating extent dùng cho đoạn thẳng cuối. Kiểm chứng: catkin_make --pkg dock_planner build sạch, ./devel/lib/dock_planner/dock_planner_test PASS.
This commit is contained in:
@@ -202,12 +202,104 @@ void checkDirectEntry(const std::vector<robot_geometry_msgs::Pose>& path,
|
||||
CHECK(std::fabs(longitudinal(path[entry_index], goal)) >= straight_distance - 1e-6);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assert the straight-pivot-straight contract: one straight leg, one
|
||||
* explicit on-the-spot rotation, one straight terminal, one travel
|
||||
* direction throughout.
|
||||
*
|
||||
* @param expected_vertex_distance where the rotation must happen, measured
|
||||
* along the goal axis. It has to clear the swept circle, not just the
|
||||
* mating extent, or a corner of the body hits the dock while it turns.
|
||||
*/
|
||||
void checkPivotPath(const std::vector<robot_geometry_msgs::Pose>& path,
|
||||
const robot_geometry_msgs::Pose& goal,
|
||||
bool terminal_forward,
|
||||
double expected_vertex_distance)
|
||||
{
|
||||
CHECK(path.size() > 3);
|
||||
const double goal_yaw = data_convert::getYaw(goal.orientation);
|
||||
|
||||
// Locate the run of poses that share a position: that is the rotation.
|
||||
std::size_t block_start = path.size();
|
||||
std::size_t block_end = 0;
|
||||
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)
|
||||
{
|
||||
if (block_start == path.size())
|
||||
{
|
||||
block_start = index - 1;
|
||||
}
|
||||
block_end = index;
|
||||
}
|
||||
}
|
||||
CHECK(block_start < path.size());
|
||||
// StanleyControl::planDivision only splits a rotation out of the plan after
|
||||
// three consecutive same-position samples, so four poses is the hard floor.
|
||||
// Fewer and the controller drives through the corner instead of turning.
|
||||
CHECK(block_end >= block_start + 3);
|
||||
|
||||
for (std::size_t index = block_start; index <= block_end; ++index)
|
||||
{
|
||||
CHECK(std::fabs(lateral(path[index], goal)) < 1e-7);
|
||||
CHECK(near(std::fabs(longitudinal(path[index], goal)),
|
||||
expected_vertex_distance, 1e-6));
|
||||
}
|
||||
|
||||
// Yaw steps one way only, never by less than the epsilon planDivision uses
|
||||
// to decide two samples share a heading, and lands on the goal heading.
|
||||
const double first_step = normalizeAngle(
|
||||
data_convert::getYaw(path[block_start + 1].orientation) -
|
||||
data_convert::getYaw(path[block_start].orientation));
|
||||
CHECK(std::fabs(first_step) > 1e-6);
|
||||
for (std::size_t index = block_start + 1; index <= block_end; ++index)
|
||||
{
|
||||
const double step = normalizeAngle(
|
||||
data_convert::getYaw(path[index].orientation) -
|
||||
data_convert::getYaw(path[index - 1].orientation));
|
||||
CHECK(std::fabs(step) > 1e-6);
|
||||
CHECK(step * first_step > 0.0);
|
||||
}
|
||||
CHECK(std::fabs(normalizeAngle(
|
||||
data_convert::getYaw(path[block_end].orientation) - goal_yaw)) < 1e-7);
|
||||
|
||||
// One travel direction end to end: no cusp anywhere, which is the whole
|
||||
// reason this shape is preferred over the single-cusp one.
|
||||
for (std::size_t index = 0; index + 1 < path.size(); ++index)
|
||||
{
|
||||
if (std::hypot(path[index + 1].position.x - path[index].position.x,
|
||||
path[index + 1].position.y - path[index].position.y) <= 1e-9)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
CHECK(edgeIsForward(path[index], path[index + 1]) == terminal_forward);
|
||||
}
|
||||
|
||||
// Terminal leg: on the axis and already at the goal heading.
|
||||
for (std::size_t index = block_end; index < path.size(); ++index)
|
||||
{
|
||||
CHECK(std::fabs(lateral(path[index], goal)) < 1e-7);
|
||||
CHECK(std::fabs(normalizeAngle(
|
||||
data_convert::getYaw(path[index].orientation) - goal_yaw)) < 1e-7);
|
||||
}
|
||||
|
||||
// The defining property: the path never reaches further away from the dock
|
||||
// than the robot already stood, so it costs no extra aisle depth.
|
||||
for (const auto& sample : path)
|
||||
{
|
||||
CHECK(std::fabs(longitudinal(sample, goal)) <=
|
||||
std::fabs(longitudinal(path.front(), goal)) + 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<robot_geometry_msgs::Pose> generatePath(
|
||||
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)
|
||||
const std::vector<robot_geometry_msgs::Point>& dock_footprint,
|
||||
bool allow_stationary_block = false)
|
||||
{
|
||||
std::vector<robot_geometry_msgs::Pose> path;
|
||||
CHECK(calculator.makePlanMoveToDock(start, goal, robot_footprint,
|
||||
@@ -225,7 +317,9 @@ std::vector<robot_geometry_msgs::Pose> generatePath(
|
||||
CHECK(std::isfinite(current.position.y));
|
||||
CHECK(std::isfinite(current.orientation.z));
|
||||
CHECK(std::isfinite(current.orientation.w));
|
||||
if (index > 0)
|
||||
// The pivot shape deliberately repeats a position while the body turns,
|
||||
// so that check only applies to the shapes made of motion alone.
|
||||
if (index > 0 && !allow_stationary_block)
|
||||
{
|
||||
CHECK(std::hypot(current.position.x - path[index - 1].position.x,
|
||||
current.position.y - path[index - 1].position.y) > 1e-9);
|
||||
@@ -269,6 +363,167 @@ void testConfig()
|
||||
config = dock_planner::DockPlannerConfig{};
|
||||
config.path_point_spacing = std::numeric_limits<double>::quiet_NaN();
|
||||
CHECK(!config.validate(error));
|
||||
config = dock_planner::DockPlannerConfig{};
|
||||
config.pivot_fallback_extension = -0.01;
|
||||
CHECK(!config.validate(error));
|
||||
config = dock_planner::DockPlannerConfig{};
|
||||
config.pivot_safety_margin = -0.01;
|
||||
CHECK(!config.validate(error));
|
||||
|
||||
// A differential base has no steered axle, so empty axle frames and a zero
|
||||
// steering angle must NOT stop it loading -- validating them there would
|
||||
// reject a perfectly valid robot.
|
||||
config = dock_planner::DockPlannerConfig{};
|
||||
config.kinematic_model = dock_planner::KinematicModel::kDifferential;
|
||||
config.max_steering_angle = 0.0;
|
||||
config.front_axle_frame.clear();
|
||||
config.rear_axle_frame.clear();
|
||||
CHECK(config.validate(error));
|
||||
CHECK(!config.requiresAxleTf());
|
||||
// 0 is the answer, not a failure: it is what allows turning on the spot.
|
||||
CHECK(near(config.minimumTurningRadius(), 0.0));
|
||||
|
||||
config.minimum_turning_radius = -0.1;
|
||||
CHECK(!config.validate(error));
|
||||
config.minimum_turning_radius = 1.5;
|
||||
CHECK(config.validate(error));
|
||||
CHECK(near(config.minimumTurningRadius(), 1.5));
|
||||
|
||||
// Ackermann still needs its axle TF resolved before it can plan.
|
||||
config = dock_planner::DockPlannerConfig{};
|
||||
CHECK(config.requiresAxleTf());
|
||||
}
|
||||
|
||||
/** Footprint of the APM reference robot: 1.65 m of nose, 0.35 m of tail. */
|
||||
std::vector<robot_geometry_msgs::Point> apmFootprint()
|
||||
{
|
||||
return {point(1.65, -0.40), point(1.65, 0.40),
|
||||
point(-0.35, 0.40), point(-0.35, -0.40)};
|
||||
}
|
||||
|
||||
std::vector<robot_geometry_msgs::Point> apmDockFootprint()
|
||||
{
|
||||
return {point(0.50, -0.40), point(0.50, 0.40),
|
||||
point(-0.50, 0.40), point(-0.50, -0.40)};
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the rotation has to happen for the footprints above. The swept circle
|
||||
* is the binding constraint, not the mating extent: hypot(1.65, 0.40) is
|
||||
* 1.6978 m, so the vertex ends up 1.50 m further out than the 0.85 m the rear
|
||||
* mating extent plus dock face would have suggested.
|
||||
*/
|
||||
double apmPivotVertex(double pivot_safety_margin)
|
||||
{
|
||||
return std::max(0.85, std::hypot(1.65, 0.40) + 0.50 + pivot_safety_margin);
|
||||
}
|
||||
|
||||
void testPivotFallback()
|
||||
{
|
||||
dock_planner::DockPlannerConfig config = apmConfig();
|
||||
config.pivot_fallback_extension = 1.0;
|
||||
dock_planner::DockCalc calculator(config);
|
||||
|
||||
const auto robot_footprint = apmFootprint();
|
||||
const auto dock_footprint = apmDockFootprint();
|
||||
const auto goal = pose(0.0, 0.0, 0.0);
|
||||
const double maximum_curvature = 1.0 / config.minimumTurningRadius();
|
||||
const double vertex = apmPivotVertex(config.pivot_safety_margin);
|
||||
|
||||
// 0.60 m of lateral offset needs a 1.598 m cusp extension at min_radius
|
||||
// 2.4287 m, past the 1.0 m threshold, so the pivot shape takes over.
|
||||
const auto pivot_path = generatePath(calculator, pose(2.8, 0.6, -1.2), goal,
|
||||
robot_footprint, dock_footprint, true);
|
||||
checkPivotPath(pivot_path, goal.pose, false, vertex);
|
||||
|
||||
// Same start, mirrored to the far side of the goal: the docking edge flips,
|
||||
// so the whole path drives FORWARD instead, and the vertex is unchanged
|
||||
// because the swept circle, not the mating extent, decides where it sits.
|
||||
const auto front_pivot = generatePath(calculator, pose(-2.8, 0.6, 0.0), goal,
|
||||
robot_footprint, dock_footprint, true);
|
||||
checkPivotPath(front_pivot, goal.pose, true, vertex);
|
||||
|
||||
// Only 0.05 m of lateral offset: the cusp costs 0.490 m, under the
|
||||
// threshold, so nothing changes and the cusp is still planned.
|
||||
const auto cusp_path = generatePath(calculator, pose(2.8, 0.05, 0.0), goal,
|
||||
robot_footprint, dock_footprint);
|
||||
checkSingleCuspPath(cusp_path, goal.pose, maximum_curvature, false);
|
||||
|
||||
// Vertex behind the robot (start 1.5 m out, vertex 2.348 m): the pivot
|
||||
// shape cannot be built and the planner must fall back to the cusp rather
|
||||
// than refuse a path.
|
||||
const auto behind_path = generatePath(calculator, pose(1.5, 0.3, 0.0), goal,
|
||||
robot_footprint, dock_footprint);
|
||||
checkSingleCuspPath(behind_path, goal.pose, maximum_curvature, false);
|
||||
|
||||
// The safety margin really does move the vertex: pushing it 0.50 m further
|
||||
// out puts it past the 2.8 m start, so the same case falls back to a cusp.
|
||||
config.pivot_safety_margin = 0.65;
|
||||
calculator.setConfig(config);
|
||||
const auto margin_path = generatePath(calculator, pose(2.8, 0.6, -1.2), goal,
|
||||
robot_footprint, dock_footprint);
|
||||
checkSingleCuspPath(margin_path, goal.pose, maximum_curvature, false);
|
||||
|
||||
// A cusp that cannot be placed at all used to be a hard failure. With the
|
||||
// pivot shape available it is a path instead: refusing to dock is strictly
|
||||
// worse than docking with one extra stop.
|
||||
config = apmConfig();
|
||||
config.maximum_forward_extension = 0.30;
|
||||
std::vector<robot_geometry_msgs::Pose> refused;
|
||||
dock_planner::DockCalc no_pivot(config);
|
||||
CHECK(!no_pivot.makePlanMoveToDock(pose(2.8, 0.6, 0.0), goal,
|
||||
robot_footprint, dock_footprint, refused));
|
||||
CHECK(refused.empty());
|
||||
|
||||
config.pivot_fallback_extension = 1.0;
|
||||
dock_planner::DockCalc rescued(config);
|
||||
const auto rescue_path = generatePath(rescued, pose(2.8, 0.6, 0.0), goal,
|
||||
robot_footprint, dock_footprint, true);
|
||||
checkPivotPath(rescue_path, goal.pose, false,
|
||||
apmPivotVertex(config.pivot_safety_margin));
|
||||
}
|
||||
|
||||
void testDifferentialModel()
|
||||
{
|
||||
dock_planner::DockPlannerConfig config;
|
||||
config.kinematic_model = dock_planner::KinematicModel::kDifferential;
|
||||
config.minimum_turning_radius = 0.0;
|
||||
config.path_point_spacing = 0.05;
|
||||
config.direct_entry_min_curve_room = 0.0;
|
||||
// Deliberately left at 0: a differential base pivots because it can, not
|
||||
// because a threshold turned the shape on.
|
||||
config.pivot_fallback_extension = 0.0;
|
||||
dock_planner::DockCalc calculator(config);
|
||||
|
||||
const auto robot_footprint = apmFootprint();
|
||||
const auto dock_footprint = apmDockFootprint();
|
||||
const auto goal = pose(0.0, 0.0, 0.0);
|
||||
const double vertex = apmPivotVertex(config.pivot_safety_margin);
|
||||
|
||||
CHECK(near(config.minimumTurningRadius(), 0.0));
|
||||
|
||||
const auto rear_path = generatePath(calculator, pose(2.8, 0.6, -1.2), goal,
|
||||
robot_footprint, dock_footprint, true);
|
||||
checkPivotPath(rear_path, goal.pose, false, vertex);
|
||||
|
||||
// Barely off the axis: an Ackermann base would have taken the cheap cusp
|
||||
// here, but a base that turns on the spot always prefers the shape that
|
||||
// claims no extra aisle.
|
||||
const auto aligned_path = generatePath(calculator, pose(2.8, 0.05, 0.0), goal,
|
||||
robot_footprint, dock_footprint, true);
|
||||
checkPivotPath(aligned_path, goal.pose, false, vertex);
|
||||
|
||||
const auto front_path = generatePath(calculator, pose(-2.8, 0.6, 0.0), goal,
|
||||
robot_footprint, dock_footprint, true);
|
||||
checkPivotPath(front_path, goal.pose, true, vertex);
|
||||
|
||||
// Turning on the spot forbidden -- a tall load, say. The base is still
|
||||
// differential, but the planner must go back to arc-based shapes.
|
||||
config.minimum_turning_radius = 1.5;
|
||||
dock_planner::DockCalc loaded(config);
|
||||
const auto loaded_path = generatePath(loaded, pose(2.8, 0.6, -1.2), goal,
|
||||
robot_footprint, dock_footprint);
|
||||
checkSingleCuspPath(loaded_path, goal.pose, 1.0 / 1.5, false);
|
||||
}
|
||||
|
||||
void testPathGeneration()
|
||||
@@ -506,6 +761,8 @@ int main()
|
||||
testConfig();
|
||||
testPathGeneration();
|
||||
testDirectEntry();
|
||||
testPivotFallback();
|
||||
testDifferentialModel();
|
||||
testAsymmetricFootprint();
|
||||
testDockAnchor();
|
||||
if (failures != 0)
|
||||
|
||||
Reference in New Issue
Block a user