diff --git a/README.md b/README.md index 563d53b..eb7a481 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,13 @@ File mặc định đi kèm gói: `config/dock_global_params.yaml`. Cây đang c từng marker rồi rót vào namespace `DockPlanner` trước khi dựng plugin. `dock_anchor: center` cộng nửa thân dock phía tiếp cận vào khoảng hở; `dock_anchor: face` bỏ qua `footprint_dock` hoàn toàn. +`dock_anchor: mating_edge` cũng bỏ qua `footprint_dock`. Nó dành cho goal đã được tầng +trên offset sẵn thành vị trí `base_link` lúc dock xong (ví dụ trạm sạc dò bằng lidar với +`offset_x`): mặt dock nằm sát mép robot đi vào tại goal, sau goal đúng `rear_extent` +(lùi vào) hoặc `front_extent` (tiến vào). Chỉ điểm xoay của kiểu thẳng + xoay + thẳng +(và kiểu lùi ra rồi xoay) đổi: `max(straight_length, bán kính ngoại tiếp − extent mép + +pivot_safety_margin)`, thay vì đo từ goal như `face`. Robot KIT 0.65 × 0.69, trạm sạc: +điểm xoay 0.4 m thay vì 0.624 m. Đường vào thẳng và đường cusp không đổi. Điều kiện validate: diff --git a/include/dock_planner/dock_planner_config.h b/include/dock_planner/dock_planner_config.h index ad102d7..2e53e4d 100644 --- a/include/dock_planner/dock_planner_config.h +++ b/include/dock_planner/dock_planner_config.h @@ -18,11 +18,17 @@ inline constexpr double kPi = 3.14159265358979323846; * footprint_dock is added to the approach distance. * kFace: goal is already on the approach face; footprint_dock does not * contribute to the approach distance and is ignored entirely. + * kMatingEdge: goal is the docked base_link pose, already offset upstream + * (e.g. by the detector), and the dock face touches the robot's mating edge + * there. Same as kFace, except that the on-the-spot pivot clearance is measured + * from that real face, mating_extent behind the goal, instead of from the goal. + * footprint_dock is ignored. */ enum class DockAnchor { kCenter, kFace, + kMatingEdge, }; /** diff --git a/src/dock_calc.cpp b/src/dock_calc.cpp index a5c7650..7264ac8 100644 --- a/src/dock_calc.cpp +++ b/src/dock_calc.cpp @@ -819,9 +819,16 @@ bool DockCalc::makePlanMoveToDock( // circumscribed radius here, which is always more than the mating extent // the straight terminal is sized from. Sizing the vertex from the terminal // instead would drive a corner of the robot into the dock. + // + // With dock_anchor=mating_edge the goal is the docked base_link pose and the + // dock face sits at the robot's mating edge, mating_extent behind the goal. + // The sweep clearance is measured from that real face. face and center keep + // the face at the goal / at dock_extent, unchanged. + const double pivot_face_offset = + config_.dock_anchor == DockAnchor::kMatingEdge ? -mating_extent : dock_extent; const double pivot_vertex_distance = std::max( straight_distance, - robot.circumscribed_radius + dock_extent + config_.pivot_safety_margin); + robot.circumscribed_radius + pivot_face_offset + config_.pivot_safety_margin); // The pivot shape needs a base that can change heading without moving. A // differential base can exactly when its declared turning radius is 0; a diff --git a/src/dock_planner.cpp b/src/dock_planner.cpp index 877ad44..ddf347e 100644 --- a/src/dock_planner.cpp +++ b/src/dock_planner.cpp @@ -322,14 +322,18 @@ bool DockPlanner::initialize(std::string name, } std::vector loaded_footprint; - if (loaded_config.dock_anchor == DockAnchor::kFace) + if (loaded_config.dock_anchor == DockAnchor::kFace || + loaded_config.dock_anchor == DockAnchor::kMatingEdge) { - // Goal sits on the approach face: dock size never enters the approach - // formula, so a declared footprint_dock is deliberately ignored. + // Goal sits on the approach face (face) or the face touches the robot at + // the goal (mating_edge): dock size never enters the approach formula, + // so a declared footprint_dock is deliberately ignored. if (planner_nh.hasParam("footprint_dock")) { - robot::log_info("[dock_planner] '%s' uses dock_anchor=face; footprint_dock is ignored.\n", - name.c_str()); + robot::log_info("[dock_planner] '%s' uses dock_anchor=%s; footprint_dock is ignored.\n", + name.c_str(), + loaded_config.dock_anchor == DockAnchor::kFace ? "face" + : "mating_edge"); } } else diff --git a/src/dock_planner_config.cpp b/src/dock_planner_config.cpp index e4784a7..87511c9 100644 --- a/src/dock_planner_config.cpp +++ b/src/dock_planner_config.cpp @@ -85,7 +85,13 @@ bool readDockAnchor(const robot::NodeHandle& nh, DockAnchor& anchor, std::string anchor = DockAnchor::kFace; return true; } - error = "parameter 'dock_anchor' must be 'center' or 'face' (got '" + parsed + "')"; + if (parsed == "mating_edge") + { + anchor = DockAnchor::kMatingEdge; + return true; + } + error = "parameter 'dock_anchor' must be 'center', 'face' or 'mating_edge' (got '" + + parsed + "')"; return false; } diff --git a/test/dock_planner_test.cpp b/test/dock_planner_test.cpp index 6c1e742..13075b7 100644 --- a/test/dock_planner_test.cpp +++ b/test/dock_planner_test.cpp @@ -584,6 +584,57 @@ void testBackoffPivotRobotFailures() } } +void testMatingEdgeAnchor() +{ + // KIT charger: the detector already offsets the goal to the docked + // base_link pose, so the charger face is at the robot's rear edge there. + const auto robot_footprint = robotFootprint065x069(); + const std::vector no_dock_footprint; + const auto goal = pose(0.0, 0.0, 0.0); + const double circumscribed = std::hypot(0.325, 0.345); + const double face_vertex = circumscribed + 0.15; + // max(straight_length 0.4, 0.474 - 0.325 + 0.15 = 0.299) + const double mating_vertex = std::max(0.4, circumscribed - 0.325 + 0.15); + CHECK(near(mating_vertex, 0.4)); + + auto face_config = differentialBackoffConfig(); + face_config.dock_anchor = dock_planner::DockAnchor::kFace; + face_config.pivot_backoff_max_distance = 1.0; + auto mating_config = face_config; + mating_config.dock_anchor = dock_planner::DockAnchor::kMatingEdge; + dock_planner::DockCalc face_calc(face_config); + dock_planner::DockCalc mating_calc(mating_config); + + // The two 29/10 starts that needed a back-off with face now pivot in place + // at 0.4 m, with no back-off leg. + for (const auto& start : {pose(0.579, 0.292, 0.0), pose(0.427, 0.155, 0.0)}) + { + std::vector path; + CHECK(mating_calc.makePlanMoveToDock(start, goal, robot_footprint, + no_dock_footprint, path)); + checkPivotPath(path, goal.pose, false, mating_vertex); + } + + // 29/10 15:36 start: still closer than the vertex, so it backs off, but + // only to vertex + spacing (0.45 m) instead of 0.674 m. + const auto close_start = pose(0.375, -0.149, 0.17); + std::vector face_path; + std::vector mating_path; + CHECK(face_calc.makePlanMoveToDock(close_start, goal, robot_footprint, + no_dock_footprint, face_path)); + CHECK(mating_calc.makePlanMoveToDock(close_start, goal, robot_footprint, + no_dock_footprint, mating_path)); + checkBackoffPivotPath(face_path, close_start, goal, face_vertex); + checkBackoffPivotPath(mating_path, close_start, goal, mating_vertex); + double furthest = 0.0; + for (const auto& path_pose : mating_path) + { + furthest = std::max(furthest, longitudinal(path_pose, goal.pose)); + } + CHECK(furthest < mating_vertex + 0.05 + 1e-6); + CHECK(mating_path.size() < face_path.size()); +} + void testExistingPlansUnchangedByBackoff() { const auto robot_footprint = apmFootprint(); @@ -1176,6 +1227,7 @@ int main() { testConfig(); testBackoffPivotRobotFailures(); + testMatingEdgeAnchor(); testExistingPlansUnchangedByBackoff(); testBackoffPivotGates(); testCostmapCheckCallbacks();